chore: did more clean up

This commit is contained in:
2024-04-14 15:19:32 +01:00
parent 8b13afba48
commit e7eeccd09e
20 changed files with 283 additions and 352 deletions

View File

@@ -9,7 +9,6 @@ import (
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)
@@ -48,7 +47,7 @@ func handleUpload(handler *Handle) {
ModelId string `json:"id" validate:"required"`
}
_err := c.ParseJson(&requestData, json_data)
_err := c.ParseJson(&requestData, json_data)
if _err != nil {
return _err
}
@@ -88,9 +87,9 @@ func handleUpload(handler *Handle) {
}
id, err := InsertReturnId(c, &newTask, "tasks", "id")
if err != nil {
if err != nil {
return c.E500M("Error 500", err)
}
}
save_path := path.Join("savedData", model.Id, "tasks")
os.MkdirAll(save_path, os.ModePerm)
@@ -99,26 +98,28 @@ func handleUpload(handler *Handle) {
img_file, err := os.Create(img_path)
if err != nil {
if _err := UpdateTaskStatus(c,id, -1, "Failed to create the file"); _err != nil {
c.Logger.Error("Failed to update tasks")
}
if _err := UpdateTaskStatus(c, id, -1, "Failed to create the file"); _err != nil {
c.Logger.Error("Failed to update tasks")
}
return c.E500M("Failed to create the file", err)
}
defer img_file.Close()
img_file.Write(file)
if !TestImgForModel(c, model, img_path) {
if _err := UpdateTaskStatus(c, id, -1, "The provided image is not a valid image for this model"); _err != nil {
c.Logger.Error("Failed to update tasks")
}
if _err := UpdateTaskStatus(c, id, -1, "The provided image is not a valid image for this model"); _err != nil {
c.Logger.Error("Failed to update tasks")
}
return c.JsonBadRequest(struct {
Message string `json:"message"`
Id string `json:"task_id"`
} { "Provided image does not match the model", id})
Message string `json:"message"`
Id string `json:"task_id"`
}{"Provided image does not match the model", id})
}
UpdateStatus(c, "tasks", id, 1)
UpdateStatus(c, "tasks", id, 1)
return c.SendJSON(struct {Id string `json:"id"`}{id})
return c.SendJSON(struct {
Id string `json:"id"`
}{id})
})
}

View File

@@ -3,7 +3,6 @@ package tasks
import (
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
dbtypes "git.andr3h3nriqu3s.com/andr3/fyp/logic/db_types"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/models/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/tasks/utils"
. "git.andr3h3nriqu3s.com/andr3/fyp/logic/utils"
)