Add Updated At to Tasks And Libraries

This commit is contained in:
speatzle 2024-05-28 21:32:57 +02:00
parent ec645f6162
commit c04aa74364
14 changed files with 74 additions and 38 deletions

View file

@ -7,6 +7,7 @@ import (
"fmt"
"log/slog"
"net/http"
"time"
"git.lastassault.de/speatzle/morffix/constants"
"git.lastassault.de/speatzle/morffix/types"
@ -32,21 +33,23 @@ type TaskStats struct {
}
type TaskDisplay struct {
ID int `db:"id"`
Library int `db:"library"`
Worker *string `db:"worker"`
Type int `db:"type"`
Status string `db:"status"`
File string `db:"file"`
ID int `db:"id"`
Library int `db:"library"`
Worker *string `db:"worker"`
Type int `db:"type"`
Status string `db:"status"`
File string `db:"file"`
UpdatedAt string `db:"updated_at"`
}
type TaskDB struct {
ID int `db:"id"`
Library int `db:"library"`
Worker *string `db:"worker"`
Type int `db:"type"`
Status constants.TaskStatus `db:"status"`
File string `db:"file"`
ID int `db:"id"`
Library int `db:"library"`
Worker *string `db:"worker"`
Type int `db:"type"`
Status constants.TaskStatus `db:"status"`
File string `db:"file"`
UpdatedAt time.Time `db:"updated_at"`
}
func handleTasks(w http.ResponseWriter, r *http.Request) {
@ -93,7 +96,7 @@ func handleTasks(w http.ResponseWriter, r *http.Request) {
}
data.Libraries = libraries
rows, err = db.Query(r.Context(), "SELECT t.id AS id, l.id AS library, t.worker_id AS worker, t.type AS type, t.status AS status, f.path AS file FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN libraries l ON l.id = f.library_id ORDER BY CASE t.type WHEN 3 THEN -1 ELSE t.type END, t.id")
rows, err = db.Query(r.Context(), "SELECT t.id AS id, l.id AS library, t.worker_id AS worker, t.type AS type, t.status AS status, f.path AS file, t.updated_at AS updated_at FROM tasks t INNER JOIN files f ON f.id = t.file_id INNER JOIN libraries l ON l.id = f.library_id ORDER BY CASE t.type WHEN 3 THEN -1 ELSE t.type END, t.id")
if err != nil {
slog.ErrorContext(r.Context(), "Query Tasks", "err", err)
http.Error(w, "Error Query Tasks: "+err.Error(), http.StatusInternalServerError)
@ -107,12 +110,13 @@ func handleTasks(w http.ResponseWriter, r *http.Request) {
}
for i := range tasks {
data.Tasks = append(data.Tasks, TaskDisplay{
ID: tasks[i].ID,
Library: tasks[i].Library,
Worker: tasks[i].Worker,
Type: tasks[i].Type,
File: tasks[i].File,
Status: tasks[i].Status.String(),
ID: tasks[i].ID,
Library: tasks[i].Library,
Worker: tasks[i].Worker,
Type: tasks[i].Type,
File: tasks[i].File,
Status: tasks[i].Status.String(),
UpdatedAt: tasks[i].UpdatedAt.Format(time.DateTime),
})
}