From 5101c97f7cab241b904844d6e9af832da81660fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=9E=E3=83=AA=E3=82=A6=E3=82=B9?= Date: Sat, 17 Oct 2020 01:32:53 +0100 Subject: [PATCH] Implemented UpdateProject & GetProject --- z/database.go | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/z/database.go b/z/database.go index 3a7fc87..89c4d0f 100644 --- a/z/database.go +++ b/z/database.go @@ -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 +}