summaryrefslogtreecommitdiff
path: root/models.go
diff options
context:
space:
mode:
authorJan Dittberner <jan@dittberner.info>2017-04-18 02:34:21 +0200
committerJan Dittberner <jan@dittberner.info>2017-04-22 00:12:32 +0200
commit471daf12ea98aa2a7fcb11deff9697403c5dd6a5 (patch)
tree995daa7635955bef5b973f38ecf88cf3b2a2d82f /models.go
parent57e3d5324559255e57655f71b333edc6c54fabdf (diff)
downloadcacert-boardvoting-471daf12ea98aa2a7fcb11deff9697403c5dd6a5.tar.gz
cacert-boardvoting-471daf12ea98aa2a7fcb11deff9697403c5dd6a5.tar.xz
cacert-boardvoting-471daf12ea98aa2a7fcb11deff9697403c5dd6a5.zip
Partialy add new motion creation
Diffstat (limited to 'models.go')
-rw-r--r--models.go37
1 files changed, 35 insertions, 2 deletions
diff --git a/models.go b/models.go
index 46d669e..410ed3e 100644
--- a/models.go
+++ b/models.go
@@ -51,12 +51,26 @@ WHERE decisions.status=0 AND decisions.id NOT IN (
SELECT decision FROM votes WHERE votes.voter=$2)
ORDER BY proposed DESC
LIMIT 10 OFFSET 10 * $1`
+ sqlCreateDecision = `
+INSERT INTO decisions (
+ proposed, proponent, title, content, votetype, status, due, modified,tag
+) VALUES (
+ datetime('now','utc'), :proponent, :title, :content, :votetype, 0,
+ :due,
+ datetime('now','utc'),
+ 'm' || strftime('%Y%m%d','now') || '.' || (
+ SELECT COUNT(*)+1 AS num
+ FROM decisions
+ WHERE proposed BETWEEN date('now') AND date('now','1 day')
+ )
+)
+`
)
var db *sqlx.DB
-type VoteType int
-type VoteStatus int
+type VoteType uint8
+type VoteStatus int8
type Decision struct {
Id int
@@ -332,6 +346,25 @@ func (d *Decision) OlderExists() (result bool, err error) {
return
}
+func (d *Decision) Save() (err error) {
+ insertDecisionStmt, err := db.PrepareNamed(sqlCreateDecision)
+ if err != nil {
+ logger.Println("Error preparing statement:", err)
+ return
+ }
+ defer insertDecisionStmt.Close()
+
+ result, err := insertDecisionStmt.Exec(d)
+ if err != nil {
+ logger.Println("Error creating motion:", err)
+ return
+ }
+ logger.Println(result)
+ // TODO: implement fetch last id from result
+ // TODO: load decision from DB
+ return
+}
+
func FindVoterByAddress(emailAddress string) (voter *Voter, err error) {
findVoterStmt, err := db.Preparex(sqlGetVoter)
if err != nil {