summaryrefslogtreecommitdiff
path: root/models.go
diff options
context:
space:
mode:
authorJan Dittberner <jandd@cacert.org>2017-04-19 21:35:08 +0200
committerJan Dittberner <jan@dittberner.info>2017-04-22 00:12:38 +0200
commit0ce9ad6dcc01375cb3f2d57f7bbdf701e605bea1 (patch)
tree8de15dd825d80e025764614f6324343771b8231a /models.go
parentbc194e8943bdec58ef462e393ef2a8a59d928718 (diff)
downloadcacert-boardvoting-0ce9ad6dcc01375cb3f2d57f7bbdf701e605bea1.tar.gz
cacert-boardvoting-0ce9ad6dcc01375cb3f2d57f7bbdf701e605bea1.tar.xz
cacert-boardvoting-0ce9ad6dcc01375cb3f2d57f7bbdf701e605bea1.zip
Implement withdraw motion
Diffstat (limited to 'models.go')
-rw-r--r--models.go42
1 files changed, 38 insertions, 4 deletions
diff --git a/models.go b/models.go
index 8194dc9..d6eee15 100644
--- a/models.go
+++ b/models.go
@@ -20,6 +20,7 @@ const (
sqlCountOlderThanUnvotedDecision
sqlCreateDecision
sqlUpdateDecision
+ sqlUpdateDecisionStatus
)
var sqlStatements = map[sqlKey]string{
@@ -98,6 +99,10 @@ UPDATE decisions
SET proponent=:proponent, title=:title, content=:content,
votetype=:votetype, due=:due, modified=:modified
WHERE id=:id`,
+ sqlUpdateDecisionStatus: `
+UPDATE decisions
+SET status=:status, modified=:modified WHERE id=:id
+`,
}
var db *sqlx.DB
@@ -417,6 +422,22 @@ func (d *Decision) Create() (err error) {
return
}
+func (d *Decision) LoadWithId() (err error) {
+ getDecisionStmt, err := db.Preparex(sqlStatements[sqlLoadDecisionById])
+ if err != nil {
+ logger.Println("Error preparing statement:", err)
+ return
+ }
+ defer getDecisionStmt.Close()
+
+ err = getDecisionStmt.Get(d, d.Id)
+ if err != nil {
+ logger.Println("Error loading updated motion:", err)
+ }
+
+ return
+}
+
func (d *Decision) Update() (err error) {
updateDecisionStmt, err := db.PrepareNamed(sqlStatements[sqlUpdateDecision])
if err != nil {
@@ -438,18 +459,31 @@ func (d *Decision) Update() (err error) {
logger.Printf("WARNING wrong number of affected rows: %d (1 expected)\n", affectedRows)
}
- getDecisionStmt, err := db.Preparex(sqlStatements[sqlLoadDecisionById])
+ err = d.LoadWithId()
+ return
+}
+
+func (d *Decision) UpdateStatus() (err error) {
+ updateStatusStmt, err := db.PrepareNamed(sqlStatements[sqlUpdateDecisionStatus])
if err != nil {
logger.Println("Error preparing statement:", err)
return
}
- defer getDecisionStmt.Close()
+ defer updateStatusStmt.Close()
- err = getDecisionStmt.Get(d, d.Id)
+ result, err := updateStatusStmt.Exec(d)
if err != nil {
- logger.Println("Error loading updated motion:", err)
+ logger.Println("Error setting motion status:", err)
+ return
+ }
+ affectedRows, err := result.RowsAffected()
+ if err != nil {
+ logger.Print("Problem determining the affected rows")
+ } else if affectedRows != 1 {
+ logger.Printf("WARNING wrong number of affected rows: %d (1 expected)\n", affectedRows)
}
+ err = d.LoadWithId()
return
}