feat: add basic deletion finding

This commit is contained in:
2026-04-26 18:43:23 +02:00
parent 7c069c0437
commit f589ae4faf
6 changed files with 79 additions and 60 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ func RegisterApiRoutes(api *gin.RouterGroup /* env runtime.Environment,*/, db *g
// Display the information on what is going on at the moment
api.GET("/command", func(c *gin.Context) {
state, err := database.GetState(db)
state, err := database.LatestState(db)
if err != nil {
slog.Error("unable to determine state", "error", err)
c.JSON(http.StatusInternalServerError, response.BasicResponse{
@@ -48,7 +48,7 @@ func RegisterApiRoutes(api *gin.RouterGroup /* env runtime.Environment,*/, db *g
// define a route to check what is registered
api.GET("/available", func(c *gin.Context) {
files, err := database.GetFiles(db)
files, err := database.ListFiles(db)
if err != nil {
slog.Error("failed to retrieve available files", "error", err)
c.JSON(http.StatusInternalServerError, response.BasicResponse{
+17 -3
View File
@@ -17,8 +17,8 @@ func RegisterFileRoutes(file *gin.RouterGroup, env bootstrap.Environment, db *go
// prefix: file
// for example: /file/<file-name>
file.GET("/:filename", func(c *gin.Context) {
f := c.Param("filename")
p := filepath.Join(env.ContentDirectory, f)
fileParam := c.Param("filename")
p := filepath.Join(env.ContentDirectory, fileParam)
c.File(p)
})
@@ -50,7 +50,7 @@ func RegisterFileRoutes(file *gin.RouterGroup, env bootstrap.Environment, db *go
return
}
if err := database.RegisterFile(db, fileData); err != nil {
if err := database.CreateFile(db, fileData); err != nil {
if errors.Is(err, gorm.ErrDuplicatedKey) {
slog.Debug("discarding file since its checksum is a duplicate", "error", err)
c.JSON(http.StatusConflict, response.BasicResponse{
@@ -80,4 +80,18 @@ func RegisterFileRoutes(file *gin.RouterGroup, env bootstrap.Environment, db *go
Data: fileData,
})
})
file.DELETE("/:filename", func(c *gin.Context) {
fileParam := c.Param("filename")
f, err := database.FindFileByName(db, fileParam)
slog.Info("received a detelte request for a file", "file", f, "filename", fileParam)
if err != nil {
slog.Error("failed to filter the file database for the name")
c.JSON(http.StatusNotFound, response.BasicResponse{
Msg: response.IntErrMes,
})
}
})
}