fyp/logic/tasks/agreement.go

30 lines
874 B
Go
Raw Permalink Normal View History

package tasks
import (
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
func handleRequests(x *Handle) {
type AgreementRequest struct {
Id string `json:"id" validate:"required"`
Agreement int `json:"agreement" validate:"required"`
}
PostAuthJson(x, "/task/agreement", User_Normal, func(c *Context, dat *AgreementRequest) *Error {
var task Task
err := GetDBOnce(c, &task, "tasks where id=$1", dat.Id)
if err == ModelNotFoundError {
return c.JsonBadRequest("Model not found")
} else if err != nil {
return c.E500M("Failed to get task data", err)
}
err = task.SetAgreement(c, TaskAgreement(dat.Agreement))
if err != nil {
return c.E500M("Failed to update task data", err)
}
return c.SendJSON(JustId{Id: dat.Id})
})
}