From 00ddb91a22c6e5ced41ef41188421a2ab0c64c79 Mon Sep 17 00:00:00 2001 From: Andre Henriques Date: Tue, 16 Apr 2024 19:03:30 +0100 Subject: [PATCH] add ability to agree with results closes #96 --- logic/tasks/agreement.go | 29 +++++++++++++++++ logic/tasks/index.go | 8 ++--- logic/tasks/utils/utils.go | 13 ++++++++ .../src/routes/models/edit/TasksTable.svelte | 32 +++++++++++++++++-- 4 files changed, 76 insertions(+), 6 deletions(-) create mode 100644 logic/tasks/agreement.go diff --git a/logic/tasks/agreement.go b/logic/tasks/agreement.go new file mode 100644 index 0000000..bae6f65 --- /dev/null +++ b/logic/tasks/agreement.go @@ -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}) + }) +} diff --git a/logic/tasks/index.go b/logic/tasks/index.go index 22ccdc3..3c8d59e 100644 --- a/logic/tasks/index.go +++ b/logic/tasks/index.go @@ -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) } - diff --git a/logic/tasks/utils/utils.go b/logic/tasks/utils/utils.go index bdeae3b..57caa2d 100644 --- a/logic/tasks/utils/utils.go +++ b/logic/tasks/utils/utils.go @@ -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 diff --git a/webpage/src/routes/models/edit/TasksTable.svelte b/webpage/src/routes/models/edit/TasksTable.svelte index eadd0fd..666e8b6 100644 --- a/webpage/src/routes/models/edit/TasksTable.svelte +++ b/webpage/src/routes/models/edit/TasksTable.svelte @@ -32,10 +32,11 @@

Tasks

+ @@ -116,6 +134,16 @@ {:else} TODO {task.user_confirmed} {/if} + {#if task.user_confirmed == -1} + + {/if} + {#if task.user_confirmed == 1} + + {/if} {:else} - {/if}