display commit at recipe
This commit is contained in:
parent
820557a268
commit
f2ec0ed5fa
6 changed files with 640 additions and 555 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package data
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
"go.uber.org/zap"
|
||||
|
|
@ -60,9 +62,46 @@ func Insert(c *CommitLog) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// func GetCommitLogOfFilename(filename string) ([]CommitLog, error) {
|
||||
//}
|
||||
// cut .json, split then get pos 2, check `change_file` startwith "filename" then return all quries
|
||||
func GetCommitLogOfFilename(countryId string, filename string) ([]CommitLog, error) {
|
||||
|
||||
filename = strings.TrimSuffix(filename, ".json")
|
||||
|
||||
// try split and get pos 1 and 2
|
||||
filenameParts := strings.Split(filename, "_")
|
||||
if len(filenameParts) == 2 {
|
||||
filename = filenameParts[1]
|
||||
} else if len(filenameParts) > 2 {
|
||||
filename = filenameParts[1] + "_" + filenameParts[2]
|
||||
}
|
||||
|
||||
Log.Debug("CommitDB", zap.Any("lookup", filename))
|
||||
|
||||
commitDB, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||
if err != nil {
|
||||
Log.Fatal("Error when connecting to database", zap.Error(err))
|
||||
}
|
||||
|
||||
var commits []CommitLog
|
||||
// get contains
|
||||
// err = commitDB.Get(&commits, "SELECT * FROM commit_log WHERE change_file LIKE ?", "%"+filename+"%")
|
||||
|
||||
err = commitDB.Select(&commits, "SELECT * FROM commit_log WHERE change_file LIKE ?", "%"+filename+"%")
|
||||
|
||||
var commitsByCountryID []CommitLog
|
||||
|
||||
for _, v := range commits {
|
||||
if strings.Contains(v.Change_file, countryId) {
|
||||
commitsByCountryID = append(commitsByCountryID, v)
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
Log.Error("Error when get commit log", zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return commitsByCountryID, nil
|
||||
}
|
||||
|
||||
func GetCommitLogs() ([]CommitLog, error) {
|
||||
commit_db, err := sqlx.Connect("sqlite3", "./data/database.db")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue