fix tpyo (#8)
All checks were successful
🧪 ✨ Unit Tests Workflow / 🧪 📜 JavaScript Tests (push) Successful in 7m28s
🧪 ✨ Unit Tests Workflow / 🧪 🐹 GolangCI-Lint (push) Successful in 7m40s
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 10m24s

Reviewed-on: Siteworxpro/reloading-manager#8
Co-authored-by: Ron Rise <ron@siteworxpro.com>
Co-committed-by: Ron Rise <ron@siteworxpro.com>
This commit was merged in pull request #8.
This commit is contained in:
2025-06-10 15:56:03 +00:00
committed by Siteworx Pro Gitea
parent e484aa7e31
commit dd383b6fb3
15 changed files with 211 additions and 90 deletions

View File

@@ -3,6 +3,7 @@ package primers
import (
"context"
"encoding/json"
"fmt"
"git.siteworxpro.com/reloading-manager/backend/database"
"git.siteworxpro.com/reloading-manager/backend/handlers"
"git.siteworxpro.com/reloading-manager/backend/models/primers"
@@ -19,7 +20,9 @@ type PrimerResponse struct {
func Delete(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid, err := handlers.ParseUuid(id)
@@ -37,13 +40,15 @@ func Delete(c echo.Context) error {
func Post(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID.")
}
p, err := db.Primer.GetPrimerById(context.Background(), *uid)
@@ -56,9 +61,9 @@ func Post(c echo.Context) error {
}
if c.FormValue("manufacturer_id") != "" {
mid := handlers.ParseUuidOrBadRequest(c, c.FormValue("manufacturer_id"))
if mid == nil {
return nil
mid, err := handlers.ParseUuidOrBadRequest(c, c.FormValue("manufacturer_id"))
if err != nil || mid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Manufacturer ID.")
}
p.ManufacturerID = *mid
@@ -112,13 +117,14 @@ func Post(c echo.Context) error {
if metaString == "" {
metaString = "{}"
}
var meta json.RawMessage = []byte(metaString)
meta := []byte(metaString)
newUuid := uuid.New().String()
uid, _ := handlers.ParseUuid(newUuid)
mid := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if mid == nil {
return nil
mid, err := handlers.ParseUuidOrBadRequest(c, manufacturerId)
if err != nil || mid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid Manufacturer ID.")
}
err = db.Primer.InsertPrimer(context.Background(), primers.InsertPrimerParams{
@@ -145,12 +151,14 @@ func Post(c echo.Context) error {
func Photo(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID.")
}
byId, err := db.Primer.GetPrimerById(context.Background(), *uid)
@@ -172,18 +180,20 @@ func Photo(c echo.Context) error {
func Get(c echo.Context) error {
db := c.(*database.CustomContext).Db
defer db.Db.Close(context.Background())
defer func() {
_ = db.Db.Close(context.Background())
}()
if c.Param("id") != "" {
id := c.Param("id")
uid := handlers.ParseUuidOrBadRequest(c, id)
if uid == nil {
return nil
uid, err := handlers.ParseUuidOrBadRequest(c, id)
if err != nil || uid == nil {
return echo.NewHTTPError(http.StatusBadRequest, "Invalid UUID.")
}
row, err := db.Primer.GetPrimerById(context.Background(), *uid)
if err != nil {
return err
return fmt.Errorf("primer not found: %v", err)
}
return c.JSON(http.StatusOK, handlers.Response[PrimerResponse]{