mirror of
https://forgejo.merr.is/annika/isl-api.git
synced 2025-12-10 11:53:14 -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 {
|
||||
|
|
|
|||
4
go.mod
4
go.mod
|
|
@ -3,23 +3,21 @@ module forgejo.merr.is/annika/isl-api
|
|||
go 1.21.6
|
||||
|
||||
require (
|
||||
forgejo.merr.is/annika/jwtauth/v5 v5.1.0
|
||||
github.com/go-chi/chi/v5 v5.0.11
|
||||
github.com/go-chi/cors v1.2.1
|
||||
github.com/go-chi/httplog/v2 v2.0.9
|
||||
github.com/gofrs/uuid v4.0.0+incompatible
|
||||
github.com/jackc/pgconn v1.14.1
|
||||
github.com/jackc/pgtype v1.14.1
|
||||
github.com/jackc/pgx/v4 v4.18.1
|
||||
github.com/lestrrat-go/jwx/v2 v2.0.19
|
||||
github.com/lmittmann/tint v1.0.4
|
||||
github.com/moosetheory/jwtauth/v5 v5.1.1
|
||||
github.com/spf13/viper v1.18.2
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
github.com/go-chi/jwtauth/v5 v5.3.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
|
|
|
|||
6
go.sum
6
go.sum
|
|
@ -1,5 +1,3 @@
|
|||
forgejo.merr.is/annika/jwtauth/v5 v5.1.0 h1:I5OZx/WhDUsA8Frux6bwi+geWLMwmLf5BA2KyqA2Cko=
|
||||
forgejo.merr.is/annika/jwtauth/v5 v5.1.0/go.mod h1:E+c0kfRzONRviIMYlx5de1b8SSu4lm/SkvD/297MQjY=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
github.com/cockroachdb/apd v1.1.0 h1:3LFP3629v+1aKXU5Q37mxmRxX/pIu1nijXydLShEq5I=
|
||||
|
|
@ -23,8 +21,6 @@ github.com/go-chi/cors v1.2.1 h1:xEC8UT3Rlp2QuWNEr4Fs/c2EAGVKBwy/1vHx3bppil4=
|
|||
github.com/go-chi/cors v1.2.1/go.mod h1:sSbTewc+6wYHBBCW7ytsFSn836hqM7JxpglAy2Vzc58=
|
||||
github.com/go-chi/httplog/v2 v2.0.9 h1:RK1TBETd4SSwu075tcfm0KKxR/k98RUfzmOWxLaocGg=
|
||||
github.com/go-chi/httplog/v2 v2.0.9/go.mod h1:/XXdxicJsp4BA5fapgIC3VuTD+z0Z/VzukoB3VDc1YE=
|
||||
github.com/go-chi/jwtauth/v5 v5.3.0 h1:X7RKGks1lrVeIe2omGyz47pNaNjG2YmwlRN5UKhN8qg=
|
||||
github.com/go-chi/jwtauth/v5 v5.3.0/go.mod h1:2PoGm/KbnzRN9ILY6HFZAI6fTnb1gEZAKogAyqkd6fY=
|
||||
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
|
||||
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
|
|
@ -127,8 +123,6 @@ github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
|
|||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
|
||||
github.com/moosetheory/jwtauth/v5 v5.1.1 h1:uj4PJWiKpLkKhr9WfsVjgUAT5izGojJhs7y0HKXmdSI=
|
||||
github.com/moosetheory/jwtauth/v5 v5.1.1/go.mod h1:S1z/wAXZwfzqfeQa8umtAt1rwSKekNVfyqTt7+IAVSY=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 h1:FnwAJ4oYMvbT/34k9zzHuZNrhlz48GB3/s6at6/MHO4=
|
||||
github.com/pelletier/go-toml/v2 v2.1.0/go.mod h1:tJU2Z3ZkXwnxa4DPO899bsyIoywizdUvyaeZurnPPDc=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue