From 2de4f3a6065d55f77323a34a8d0e038674160c8b Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 8 Jan 2025 22:55:45 +0800 Subject: [PATCH] :card_box: Add more fields into product --- pkg/internal/models/product.go | 4 +++- pkg/internal/server/api/products_api.go | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/internal/models/product.go b/pkg/internal/models/product.go index 17f51c0..6a6284e 100644 --- a/pkg/internal/models/product.go +++ b/pkg/internal/models/product.go @@ -8,9 +8,11 @@ import ( type Product struct { cruda.BaseModel + Icon string `json:"icon"` // random id of atttachment Name string `json:"name"` Alias string `json:"alias" gorm:"uniqueIndex"` Description string `json:"description"` + Previews datatypes.JSONSlice[string] `json:"previews"` // random id of attachments Tags datatypes.JSONSlice[string] `json:"tags"` Meta ProductMeta `json:"meta" gorm:"foreignKey:ProductID"` @@ -22,7 +24,7 @@ type ProductMeta struct { cruda.BaseModel Introduction string `json:"introduction"` - Attachments datatypes.JSONSlice[string] `json:"attachments"` + Attachments datatypes.JSONSlice[string] `json:"attachments"` // random id of attachments ProductID uint `json:"product_id"` } diff --git a/pkg/internal/server/api/products_api.go b/pkg/internal/server/api/products_api.go index 6aa5c0a..ddebed8 100644 --- a/pkg/internal/server/api/products_api.go +++ b/pkg/internal/server/api/products_api.go @@ -121,11 +121,13 @@ func updateProduct(c *fiber.Ctx) error { user := c.Locals("nex_user").(*sec.UserInfo) var data struct { + Icon string `json:"icon"` Name string `json:"name" validate:"required,max=256"` Description string `json:"description" validate:"max=4096"` Introduction string `json:"introduction"` Alias string `json:"alias" validate:"required"` Tags []string `json:"tags"` + Previews []string `json:"previews"` Attachments []string `json:"attachments"` } @@ -138,9 +140,11 @@ func updateProduct(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } + product.Icon = data.Icon product.Name = data.Name product.Description = data.Description product.Tags = data.Tags + product.Previews = data.Previews product.Meta.Introduction = data.Introduction product.Meta.Attachments = data.Attachments