Compare commits
2 Commits
dc5a823508
...
f6b42709d7
| Author | SHA1 | Date | |
|---|---|---|---|
| f6b42709d7 | |||
| 3d124bafb0 |
@ -7,6 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CreateProductRequest struct {
|
type CreateProductRequest struct {
|
||||||
|
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
||||||
CategoryID uuid.UUID `json:"category_id" validate:"required"`
|
CategoryID uuid.UUID `json:"category_id" validate:"required"`
|
||||||
SKU *string `json:"sku,omitempty"`
|
SKU *string `json:"sku,omitempty"`
|
||||||
Name string `json:"name" validate:"required,min=1,max=255"`
|
Name string `json:"name" validate:"required,min=1,max=255"`
|
||||||
@ -25,6 +26,7 @@ type CreateProductRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UpdateProductRequest struct {
|
type UpdateProductRequest struct {
|
||||||
|
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
||||||
CategoryID *uuid.UUID `json:"category_id,omitempty"`
|
CategoryID *uuid.UUID `json:"category_id,omitempty"`
|
||||||
SKU *string `json:"sku,omitempty"`
|
SKU *string `json:"sku,omitempty"`
|
||||||
Name *string `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
|
Name *string `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
|
||||||
@ -58,6 +60,7 @@ type UpdateProductVariantRequest struct {
|
|||||||
type ProductResponse struct {
|
type ProductResponse struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
OrganizationID uuid.UUID `json:"organization_id"`
|
OrganizationID uuid.UUID `json:"organization_id"`
|
||||||
|
OutletID *uuid.UUID `json:"outlet_id"`
|
||||||
CategoryID uuid.UUID `json:"category_id"`
|
CategoryID uuid.UUID `json:"category_id"`
|
||||||
CategoryName string `json:"category_name"`
|
CategoryName string `json:"category_name"`
|
||||||
SKU *string `json:"sku"`
|
SKU *string `json:"sku"`
|
||||||
@ -89,6 +92,7 @@ type ProductVariantResponse struct {
|
|||||||
|
|
||||||
type ListProductsRequest struct {
|
type ListProductsRequest struct {
|
||||||
OrganizationID *uuid.UUID `json:"organization_id,omitempty"`
|
OrganizationID *uuid.UUID `json:"organization_id,omitempty"`
|
||||||
|
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
||||||
CategoryID *uuid.UUID `json:"category_id,omitempty"`
|
CategoryID *uuid.UUID `json:"category_id,omitempty"`
|
||||||
BusinessType string `json:"business_type,omitempty"`
|
BusinessType string `json:"business_type,omitempty"`
|
||||||
IsActive *bool `json:"is_active,omitempty"`
|
IsActive *bool `json:"is_active,omitempty"`
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
type Product struct {
|
type Product struct {
|
||||||
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
ID uuid.UUID `gorm:"type:uuid;primary_key;default:gen_random_uuid()" json:"id"`
|
||||||
OrganizationID uuid.UUID `gorm:"type:uuid;not null;index" json:"organization_id" validate:"required"`
|
OrganizationID uuid.UUID `gorm:"type:uuid;not null;index" json:"organization_id" validate:"required"`
|
||||||
|
OutletID *uuid.UUID `gorm:"type:uuid;index" json:"outlet_id"`
|
||||||
CategoryID uuid.UUID `gorm:"type:uuid;not null;index" json:"category_id" validate:"required"`
|
CategoryID uuid.UUID `gorm:"type:uuid;not null;index" json:"category_id" validate:"required"`
|
||||||
SKU *string `gorm:"size:100;index" json:"sku"`
|
SKU *string `gorm:"size:100;index" json:"sku"`
|
||||||
Name string `gorm:"not null;size:255" json:"name" validate:"required,min=1,max=255"`
|
Name string `gorm:"not null;size:255" json:"name" validate:"required,min=1,max=255"`
|
||||||
@ -27,6 +28,7 @@ type Product struct {
|
|||||||
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
|
||||||
|
|
||||||
Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization,omitempty"`
|
Organization Organization `gorm:"foreignKey:OrganizationID" json:"organization,omitempty"`
|
||||||
|
Outlet *Outlet `gorm:"foreignKey:OutletID" json:"outlet,omitempty"`
|
||||||
Category Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
Category Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
|
||||||
Unit *Unit `gorm:"foreignKey:UnitID" json:"unit,omitempty"`
|
Unit *Unit `gorm:"foreignKey:UnitID" json:"unit,omitempty"`
|
||||||
ProductVariants []ProductVariant `gorm:"foreignKey:ProductID" json:"variants,omitempty"`
|
ProductVariants []ProductVariant `gorm:"foreignKey:ProductID" json:"variants,omitempty"`
|
||||||
|
|||||||
@ -172,6 +172,12 @@ func (h *ProductHandler) ListProducts(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if outletIDStr := c.Query("outlet_id"); outletIDStr != "" {
|
||||||
|
if outletID, err := uuid.Parse(outletIDStr); err == nil {
|
||||||
|
req.OutletID = &outletID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if categoryIDStr := c.Query("category_id"); categoryIDStr != "" {
|
if categoryIDStr := c.Query("category_id"); categoryIDStr != "" {
|
||||||
if categoryID, err := uuid.Parse(categoryIDStr); err == nil {
|
if categoryID, err := uuid.Parse(categoryIDStr); err == nil {
|
||||||
req.CategoryID = &categoryID
|
req.CategoryID = &categoryID
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import (
|
|||||||
type Product struct {
|
type Product struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
OrganizationID uuid.UUID
|
OrganizationID uuid.UUID
|
||||||
|
OutletID *uuid.UUID
|
||||||
CategoryID uuid.UUID
|
CategoryID uuid.UUID
|
||||||
SKU *string
|
SKU *string
|
||||||
Name string
|
Name string
|
||||||
@ -40,6 +41,7 @@ type ProductVariant struct {
|
|||||||
|
|
||||||
type CreateProductRequest struct {
|
type CreateProductRequest struct {
|
||||||
OrganizationID uuid.UUID `validate:"required"`
|
OrganizationID uuid.UUID `validate:"required"`
|
||||||
|
OutletID *uuid.UUID `validate:"omitempty"`
|
||||||
CategoryID uuid.UUID `validate:"required"`
|
CategoryID uuid.UUID `validate:"required"`
|
||||||
SKU *string `validate:"omitempty,max=100"`
|
SKU *string `validate:"omitempty,max=100"`
|
||||||
Name string `validate:"required,min=1,max=255"`
|
Name string `validate:"required,min=1,max=255"`
|
||||||
@ -60,6 +62,7 @@ type CreateProductRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UpdateProductRequest struct {
|
type UpdateProductRequest struct {
|
||||||
|
OutletID *uuid.UUID `validate:"omitempty"`
|
||||||
CategoryID *uuid.UUID `validate:"omitempty"`
|
CategoryID *uuid.UUID `validate:"omitempty"`
|
||||||
SKU *string `validate:"omitempty,max=100"`
|
SKU *string `validate:"omitempty,max=100"`
|
||||||
Name *string `validate:"omitempty,min=1,max=255"`
|
Name *string `validate:"omitempty,min=1,max=255"`
|
||||||
@ -94,6 +97,7 @@ type UpdateProductVariantRequest struct {
|
|||||||
type ProductResponse struct {
|
type ProductResponse struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
OrganizationID uuid.UUID
|
OrganizationID uuid.UUID
|
||||||
|
OutletID *uuid.UUID
|
||||||
CategoryID uuid.UUID
|
CategoryID uuid.UUID
|
||||||
CategoryName string
|
CategoryName string
|
||||||
SKU *string
|
SKU *string
|
||||||
|
|||||||
@ -85,6 +85,9 @@ func (s *ProductServiceImpl) ListProducts(ctx context.Context, req *contract.Lis
|
|||||||
if req.OrganizationID != nil {
|
if req.OrganizationID != nil {
|
||||||
filters["organization_id"] = *req.OrganizationID
|
filters["organization_id"] = *req.OrganizationID
|
||||||
}
|
}
|
||||||
|
if req.OutletID != nil {
|
||||||
|
filters["outlet_id"] = *req.OutletID
|
||||||
|
}
|
||||||
if req.CategoryID != nil {
|
if req.CategoryID != nil {
|
||||||
filters["category_id"] = *req.CategoryID
|
filters["category_id"] = *req.CategoryID
|
||||||
}
|
}
|
||||||
|
|||||||
@ -39,6 +39,7 @@ func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Cr
|
|||||||
|
|
||||||
return &models.CreateProductRequest{
|
return &models.CreateProductRequest{
|
||||||
OrganizationID: apctx.OrganizationID,
|
OrganizationID: apctx.OrganizationID,
|
||||||
|
OutletID: req.OutletID,
|
||||||
CategoryID: req.CategoryID,
|
CategoryID: req.CategoryID,
|
||||||
SKU: req.SKU,
|
SKU: req.SKU,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
@ -60,6 +61,7 @@ func UpdateProductRequestToModel(req *contract.UpdateProductRequest) *models.Upd
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &models.UpdateProductRequest{
|
return &models.UpdateProductRequest{
|
||||||
|
OutletID: req.OutletID,
|
||||||
CategoryID: req.CategoryID,
|
CategoryID: req.CategoryID,
|
||||||
SKU: req.SKU,
|
SKU: req.SKU,
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
@ -100,6 +102,7 @@ func ProductModelResponseToResponse(prod *models.ProductResponse) *contract.Prod
|
|||||||
return &contract.ProductResponse{
|
return &contract.ProductResponse{
|
||||||
ID: prod.ID,
|
ID: prod.ID,
|
||||||
OrganizationID: prod.OrganizationID,
|
OrganizationID: prod.OrganizationID,
|
||||||
|
OutletID: prod.OutletID,
|
||||||
CategoryID: prod.CategoryID,
|
CategoryID: prod.CategoryID,
|
||||||
CategoryName: prod.CategoryName,
|
CategoryName: prod.CategoryName,
|
||||||
SKU: prod.SKU,
|
SKU: prod.SKU,
|
||||||
|
|||||||
8
migrations/000069_add_outlet_id_to_products.down.sql
Normal file
8
migrations/000069_add_outlet_id_to_products.down.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
-- Remove foreign key constraint
|
||||||
|
ALTER TABLE products DROP CONSTRAINT IF EXISTS fk_products_outlet;
|
||||||
|
|
||||||
|
-- Remove index
|
||||||
|
DROP INDEX IF EXISTS idx_products_outlet_id;
|
||||||
|
|
||||||
|
-- Remove outlet_id column
|
||||||
|
ALTER TABLE products DROP COLUMN IF EXISTS outlet_id;
|
||||||
8
migrations/000069_add_outlet_id_to_products.up.sql
Normal file
8
migrations/000069_add_outlet_id_to_products.up.sql
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
-- Add nullable outlet_id column to products table
|
||||||
|
ALTER TABLE products ADD COLUMN outlet_id UUID;
|
||||||
|
|
||||||
|
-- Create index on outlet_id for faster queries
|
||||||
|
CREATE INDEX idx_products_outlet_id ON products (outlet_id);
|
||||||
|
|
||||||
|
-- Add foreign key constraint
|
||||||
|
ALTER TABLE products ADD CONSTRAINT fk_products_outlet FOREIGN KEY (outlet_id) REFERENCES outlets(id) ON DELETE SET NULL;
|
||||||
Loading…
x
Reference in New Issue
Block a user