mirror of
https://forgejo.merr.is/annika/isl-api.git
synced 2025-12-13 05:30:12 -05:00
Added Logic To Set a UUID For New Items
This commit is contained in:
parent
f483833260
commit
26e6b52b04
3 changed files with 10 additions and 9 deletions
|
|
@ -9,6 +9,8 @@ import (
|
|||
"forgejo.merr.is/annika/isl-api/entities"
|
||||
"forgejo.merr.is/annika/isl-api/services"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/jackc/pgtype"
|
||||
)
|
||||
|
||||
type PowerItemController struct {
|
||||
|
|
@ -29,6 +31,13 @@ func (p *PowerItemController) Add(w http.ResponseWriter, r *http.Request) {
|
|||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
if newItem.ID.Status == pgtype.Null || newItem.ID.Status == pgtype.Undefined {
|
||||
newID, err := uuid.DefaultGenerator.NewV4()
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
newItem.ID.Set(newID)
|
||||
}
|
||||
|
||||
result, err := p.powerItemService.Add(newItem)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue