2024-04-16 19:03:30 +01:00
|
|
|
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)
|
2024-04-19 15:39:51 +01:00
|
|
|
if err == NotFoundError {
|
2024-04-16 19:03:30 +01:00
|
|
|
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})
|
|
|
|
})
|
|
|
|
}
|