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

@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"net/http"
"time"
"git.lastassault.de/speatzle/morffix/constants"
"github.com/jackc/pgx/v5"
@ -16,21 +17,23 @@ type LibraryData struct {
}
type File struct {
ID int `db:"id"`
Path string `db:"path"`
Size int64 `db:"size"`
Status constants.FileStatus `db:"status"`
Health constants.FileHealth `db:"health"`
MD5 []byte `db:"md5"`
ID int `db:"id"`
Path string `db:"path"`
Size int64 `db:"size"`
Status constants.FileStatus `db:"status"`
Health constants.FileHealth `db:"health"`
MD5 []byte `db:"md5"`
UpdatedAt time.Time `db:"updated_at"`
}
type FileDisplay struct {
ID int
Path string
Size int64
Status string
Health string
MD5 string
ID int
Path string
Size int64
Status string
Health string
MD5 string
UpdatedAt string `db:"updated_at"`
}
func handleLibrary(w http.ResponseWriter, r *http.Request) {
@ -62,7 +65,7 @@ func handleLibrary(w http.ResponseWriter, r *http.Request) {
// TODO
}
rows, err := db.Query(r.Context(), "SELECT id, path, size, status, health, md5 FROM files where library_id = $1", id)
rows, err := db.Query(r.Context(), "SELECT id, path, size, status, health, md5, updated_at FROM files where library_id = $1", id)
if err != nil {
slog.ErrorContext(r.Context(), "Query Files", "err", err)
http.Error(w, "Error Query Files: "+err.Error(), http.StatusInternalServerError)
@ -77,12 +80,13 @@ func handleLibrary(w http.ResponseWriter, r *http.Request) {
for i := range files {
data.Files = append(data.Files, FileDisplay{
ID: files[i].ID,
Path: files[i].Path,
Size: files[i].Size,
Status: files[i].Status.String(),
Health: files[i].Health.String(),
MD5: fmt.Sprintf("%x", files[i].MD5),
ID: files[i].ID,
Path: files[i].Path,
Size: files[i].Size,
Status: files[i].Status.String(),
Health: files[i].Health.String(),
MD5: fmt.Sprintf("%x", files[i].MD5),
UpdatedAt: files[i].UpdatedAt.Format(time.DateTime),
})
}