summaryrefslogtreecommitdiff
path: root/boardvoting.go
diff options
context:
space:
mode:
Diffstat (limited to 'boardvoting.go')
-rw-r--r--boardvoting.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/boardvoting.go b/boardvoting.go
index 187a867..30de17e 100644
--- a/boardvoting.go
+++ b/boardvoting.go
@@ -271,16 +271,20 @@ func (a *withDrawMotionAction) Handle(w http.ResponseWriter, r *http.Request) {
case http.MethodPost:
decision.Status = voteStatusWithdrawn
decision.Modified = time.Now().UTC()
- if err := WithdrawMotion(&decision.Decision, voter); err != nil {
+ if err := decision.UpdateStatus(); err != nil {
+ logger.Println("Error withdrawing motion:", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
+
+ notifyMail <- &NotificationWithDrawMotion{decision: decision.Decision, voter: *voter}
+
if err := a.AddFlash(w, r, fmt.Sprintf("Motion %s has been withdrawn!", decision.Tag)); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
+
http.Redirect(w, r, "/motions/", http.StatusTemporaryRedirect)
- return
default:
templateContext.Decision = decision
renderTemplate(w, templates, templateContext)
@@ -319,10 +323,15 @@ func (h *newMotionHandler) Handle(w http.ResponseWriter, r *http.Request) {
renderTemplate(w, templates, templateContext)
} else {
data.Proposed = time.Now().UTC()
- if err := CreateMotion(data, voter); err != nil {
+ data.ProponentId = voter.Id
+ if err := data.Create(); err != nil {
+ logger.Println("Error saving motion:", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
+
+ notifyMail <- &NotificationCreateMotion{decision: *data, voter: *voter}
+
if err := h.AddFlash(w, r, "The motion has been proposed!"); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
@@ -380,10 +389,14 @@ func (a editMotionAction) Handle(w http.ResponseWriter, r *http.Request) {
renderTemplate(w, templates, templateContext)
} else {
data.Modified = time.Now().UTC()
- if err := UpdateMotion(data, voter); err != nil {
+ if err := data.Update(); err != nil {
+ logger.Println("Error updating motion:", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
+
+ notifyMail <- &NotificationUpdateMotion{decision: *data, voter: *voter}
+
if err := a.AddFlash(w, r, "The motion has been modified!"); err != nil {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
@@ -502,6 +515,9 @@ func main() {
defer db.Close()
+ go MailNotifier()
+ defer CloseMailNotifier()
+
http.Handle("/motions/", http.StripPrefix("/motions/", motionsHandler{}))
http.Handle("/newmotion/", motionsHandler{})
http.Handle("/static/", http.FileServer(http.Dir(".")))