Skip to content

Commit

Permalink
PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakeschuurmans committed Jul 29, 2024
1 parent 561338d commit 33bbc03
Show file tree
Hide file tree
Showing 22 changed files with 387 additions and 429 deletions.
6 changes: 6 additions & 0 deletions db/migrations/00008_skus.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ CREATE TABLE public.server_sku (
CREATE TABLE public.server_sku_disk (
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
sku_id UUID NOT NULL REFERENCES public.server_sku(id) ON DELETE CASCADE,
vendor STRING NOT NULL,
model STRING NOT NULL,
bytes BIGINT NOT NULL,
protocol STRING NOT NULL, -- SATA vs NVMe vs PCIE
count INTEGER NOT NULL,
Expand All @@ -31,6 +33,8 @@ CREATE TABLE public.server_sku_disk (
CREATE TABLE public.server_sku_memory (
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
sku_id UUID NOT NULL REFERENCES public.server_sku(id) ON DELETE CASCADE,
vendor STRING NOT NULL,
model STRING NOT NULL,
bytes BIGINT NOT NULL,
count INTEGER NOT NULL,
created_at TIMESTAMPTZ NULL,
Expand All @@ -40,6 +44,8 @@ CREATE TABLE public.server_sku_memory (
CREATE TABLE public.server_sku_nic (
id UUID NOT NULL PRIMARY KEY DEFAULT gen_random_uuid(),
sku_id UUID NOT NULL REFERENCES public.server_sku(id) ON DELETE CASCADE,
vendor STRING NOT NULL,
model STRING NOT NULL,
port_bandwidth BIGINT NOT NULL,
port_count INTEGER NOT NULL,
count INTEGER NOT NULL,
Expand Down
18 changes: 16 additions & 2 deletions internal/models/server_sku_disk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/models/server_sku_disk_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions internal/models/server_sku_memory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/models/server_sku_memory_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions internal/models/server_sku_nic.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/models/server_sku_nic_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pkg/api/v1/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ var (
errRouteBase = "error fullfilling %s request"
ErrRouteServerSku = fmt.Errorf(errRouteBase, "server sku")
ErrRouteBiosConfigSet = fmt.Errorf(errRouteBase, "bios config set")

// SQL Boiler Erors
ErrNullRelation = errors.New("sqlboiler relation was unexpectedly null")
)

// ClientError is returned when invalid arguments are provided to the client
Expand Down
20 changes: 11 additions & 9 deletions pkg/api/v1/router_bios_config_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func (r *Router) serverBiosConfigSetCreate(c *gin.Context) {
func (r *Router) serverBiosConfigSetGet(c *gin.Context) {
// Get Config Set
id := c.Param("uuid")
if id == "" || id == uuid.Nil.String() {
badRequestResponse(c, "no UUID query param", ErrRouteBiosConfigSet)
return
_, err := uuid.Parse(id)
if err != nil {
badRequestResponse(c, "invalid UUID query param", ErrRouteBiosConfigSet)
}

mods := []qm.QueryMod{
Expand All @@ -61,8 +61,9 @@ func (r *Router) serverBiosConfigSetGet(c *gin.Context) {

func (r *Router) serverBiosConfigSetDelete(c *gin.Context) {
id := c.Param("uuid")
if id == "" || id == uuid.Nil.String() {
badRequestResponse(c, "no UUID query param", ErrRouteBiosConfigSet)
_, err := uuid.Parse(id)
if err != nil {
badRequestResponse(c, "invalid UUID query param", ErrRouteBiosConfigSet)
}

set := &models.BiosConfigSet{}
Expand Down Expand Up @@ -119,12 +120,13 @@ func (r *Router) serverBiosConfigSetUpdate(c *gin.Context) {

// Get ID
id := c.Param("uuid")
if id == "" || id == uuid.Nil.String() {
badRequestResponse(c, "no UUID query param", ErrRouteBiosConfigSet)
_, err := uuid.Parse(id)
if err != nil {
badRequestResponse(c, "invalid UUID query param", ErrRouteBiosConfigSet)
}

// Unmarshal JSON payload
err := c.ShouldBindJSON(&payload)
err = c.ShouldBindJSON(&payload)
if err != nil {
badRequestResponse(c, "invalid payload: BiosConfigSetUpdate{}; failed to unmarshal config set", err)
return
Expand Down Expand Up @@ -241,7 +243,7 @@ func updateBiosConfigSetDeleteHelper(ctx context.Context, tx *sql.Tx, components
func updateBiosConfigSetInsertUpdateHelper(ctx context.Context, tx *sql.Tx, components []*models.BiosConfigComponent, componentsToUpdate []bool, settingsToUpdate [][]bool) error {
for c, component := range components {
if component.R == nil || component.R.FKBiosConfigSet == nil {
return ErrNullRelation
return nil
}

err := component.R.FKBiosConfigSet.AddFKBiosConfigSetBiosConfigComponents(ctx, tx, !componentsToUpdate[c], component)
Expand Down
21 changes: 13 additions & 8 deletions pkg/api/v1/router_server_sku.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ func (r *Router) serverSkuCreate(c *gin.Context) {
func (r *Router) serverSkuGet(c *gin.Context) {
// Get ID
id := c.Param("uuid")
if id == "" || id == uuid.Nil.String() {
badRequestResponse(c, "no UUID query param", ErrRouteServerSku)
_, err := uuid.Parse(id)
if err != nil {
badRequestResponse(c, "invalid UUID query param", ErrRouteServerSku)
return
}

Expand Down Expand Up @@ -65,12 +66,14 @@ func (r *Router) serverSkuUpdate(c *gin.Context) {

// Get ID
id := c.Param("uuid")
if id == "" || id == uuid.Nil.String() {
badRequestResponse(c, "no UUID query param", ErrRouteServerSku)
_, err := uuid.Parse(id)
if err != nil {
badRequestResponse(c, "invalid UUID query param", ErrRouteServerSku)
return
}

// Unmarshal JSON payload
err := c.ShouldBindJSON(&payload)
err = c.ShouldBindJSON(&payload)
if err != nil {
badRequestResponse(c, "invalid payload; failed to unmarshal sku", err)
return
Expand Down Expand Up @@ -103,8 +106,10 @@ func (r *Router) serverSkuUpdate(c *gin.Context) {
func (r *Router) serverSkuDelete(c *gin.Context) {
// Get ID
id := c.Param("uuid")
if id == "" || id == uuid.Nil.String() {
badRequestResponse(c, "no UUID query param", ErrRouteServerSku)
_, err := uuid.Parse(id)
if err != nil {
badRequestResponse(c, "invalid UUID query param", ErrRouteServerSku)
return
}

set := &models.ServerSku{}
Expand All @@ -129,7 +134,7 @@ func (r *Router) serverSkuList(c *gin.Context) {

mods := params.queryMods()

count, err := models.BiosConfigSets().Count(c.Request.Context(), r.DB)
count, err := models.ServerSkus().Count(c.Request.Context(), r.DB)
if err != nil {
dbErrorResponse(c, err)
return
Expand Down
Loading

0 comments on commit 33bbc03

Please sign in to comment.