Implemented UpdateProject & GetProject

This commit is contained in:
マリウス 2020-10-17 01:32:53 +01:00
parent a89d78f66c
commit 5101c97f7c
No known key found for this signature in database
GPG key ID: C228EF0A530AF06F

View file

@ -222,3 +222,41 @@ func (database *Database) UpdateImportsSHA1List(user string, sha1List map[string
return dberr
}
func (database *Database) UpdateProject(user string, projectName string, project Project) (error) {
projectJson, jsonerr := json.Marshal(project)
if jsonerr != nil {
return jsonerr
}
projectId := GetProjectIdFromName(projectName)
dberr := database.DB.Update(func(tx *buntdb.Tx) error {
_, _, sperr := tx.Set(user + ":project:" + projectId, string(projectJson), nil)
if sperr != nil {
return sperr
}
return nil
})
return dberr
}
func (database *Database) GetProject(user string, projectName string) (Project, error) {
var project Project
projectId := GetProjectIdFromName(projectName)
dberr := database.DB.View(func(tx *buntdb.Tx) error {
value, err := tx.Get(user + ":project:" + projectId, false)
if err != nil {
return nil
}
json.Unmarshal([]byte(value), &project)
return nil
})
return project, dberr
}