add ability to agree with results closes #96
This commit is contained in:
29
logic/tasks/agreement.go
Normal file
29
logic/tasks/agreement.go
Normal file
@@ -0,0 +1,29 @@
|
||||
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})
|
||||
})
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import (
|
||||
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
|
||||
)
|
||||
|
||||
func HandleTasks (handle *Handle) {
|
||||
handleUpload(handle)
|
||||
handleList(handle)
|
||||
func HandleTasks(handle *Handle) {
|
||||
handleUpload(handle)
|
||||
handleList(handle)
|
||||
handleRequests(handle)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,23 @@ const (
|
||||
TASK_TYPE_RETRAINING
|
||||
)
|
||||
|
||||
type TaskAgreement int
|
||||
|
||||
const (
|
||||
TASK_AGREE_DISAGRE TaskAgreement = -1 + iota
|
||||
TASK_AGREE_NONE
|
||||
TASK_AGREE_AGREE
|
||||
)
|
||||
|
||||
func (t Task) UpdateStatus(base BasePack, status TaskStatus, message string) (err error) {
|
||||
return UpdateTaskStatus(base, t.Id, status, message)
|
||||
}
|
||||
|
||||
func (t Task) SetAgreement(base BasePack, agreement TaskAgreement) (err error) {
|
||||
_, err = base.GetDb().Exec("update tasks set user_confirmed=$1 where id=$2", agreement, t.Id)
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the UpdateStatus function and logs on the case of failure!
|
||||
* This varient does not return any error message
|
||||
|
||||
Reference in New Issue
Block a user