Compare commits
No commits in common. "dc5a823508f7136efbbea76a76a6f972b5eb6fd7" and "fa037b4d2aabe0966a7a9daded3abb5cc451ebe0" have entirely different histories.
dc5a823508
...
fa037b4d2a
@ -8,7 +8,6 @@ import (
|
|||||||
|
|
||||||
type CreateCategoryRequest struct {
|
type CreateCategoryRequest struct {
|
||||||
Name string `json:"name" validate:"required,min=1,max=255"`
|
Name string `json:"name" validate:"required,min=1,max=255"`
|
||||||
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
|
||||||
Description *string `json:"description,omitempty"`
|
Description *string `json:"description,omitempty"`
|
||||||
BusinessType *string `json:"business_type,omitempty"`
|
BusinessType *string `json:"business_type,omitempty"`
|
||||||
Order *int `json:"order,omitempty"`
|
Order *int `json:"order,omitempty"`
|
||||||
@ -17,7 +16,6 @@ type CreateCategoryRequest struct {
|
|||||||
|
|
||||||
type UpdateCategoryRequest struct {
|
type UpdateCategoryRequest struct {
|
||||||
Name *string `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
|
Name *string `json:"name,omitempty" validate:"omitempty,min=1,max=255"`
|
||||||
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
|
||||||
Description *string `json:"description,omitempty"`
|
Description *string `json:"description,omitempty"`
|
||||||
BusinessType *string `json:"business_type,omitempty"`
|
BusinessType *string `json:"business_type,omitempty"`
|
||||||
Order *int `json:"order,omitempty"`
|
Order *int `json:"order,omitempty"`
|
||||||
@ -26,7 +24,6 @@ type UpdateCategoryRequest struct {
|
|||||||
|
|
||||||
type ListCategoriesRequest struct {
|
type ListCategoriesRequest struct {
|
||||||
OrganizationID *uuid.UUID `json:"organization_id,omitempty"`
|
OrganizationID *uuid.UUID `json:"organization_id,omitempty"`
|
||||||
OutletID *uuid.UUID `json:"outlet_id,omitempty"`
|
|
||||||
BusinessType string `json:"business_type,omitempty"`
|
BusinessType string `json:"business_type,omitempty"`
|
||||||
Search string `json:"search,omitempty"`
|
Search string `json:"search,omitempty"`
|
||||||
Page int `json:"page" validate:"required,min=1"`
|
Page int `json:"page" validate:"required,min=1"`
|
||||||
@ -37,7 +34,6 @@ type ListCategoriesRequest struct {
|
|||||||
type CategoryResponse struct {
|
type CategoryResponse 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,omitempty"`
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description *string `json:"description"`
|
Description *string `json:"description"`
|
||||||
BusinessType string `json:"business_type"`
|
BusinessType string `json:"business_type"`
|
||||||
|
|||||||
@ -33,7 +33,6 @@ func (m *Metadata) Scan(value interface{}) error {
|
|||||||
type Category struct {
|
type Category 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,omitempty"`
|
|
||||||
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"`
|
||||||
Description *string `gorm:"type:text" json:"description"`
|
Description *string `gorm:"type:text" json:"description"`
|
||||||
Order int `gorm:"default:0" json:"order"`
|
Order int `gorm:"default:0" json:"order"`
|
||||||
@ -43,7 +42,6 @@ type Category 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"`
|
|
||||||
Products []Product `gorm:"foreignKey:CategoryID" json:"products,omitempty"`
|
Products []Product `gorm:"foreignKey:CategoryID" json:"products,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -170,12 +170,6 @@ func (h *CategoryHandler) ListCategories(c *gin.Context) {
|
|||||||
req.BusinessType = businessType
|
req.BusinessType = businessType
|
||||||
}
|
}
|
||||||
|
|
||||||
if outletIDStr := c.Query("outlet_id"); outletIDStr != "" {
|
|
||||||
if outletID, err := uuid.Parse(outletIDStr); err == nil {
|
|
||||||
req.OutletID = &outletID
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if organizationIDStr := c.Query("organization_id"); organizationIDStr != "" {
|
if organizationIDStr := c.Query("organization_id"); organizationIDStr != "" {
|
||||||
if organizationID, err := uuid.Parse(organizationIDStr); err == nil {
|
if organizationID, err := uuid.Parse(organizationIDStr); err == nil {
|
||||||
req.OrganizationID = &organizationID
|
req.OrganizationID = &organizationID
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import (
|
|||||||
type Category struct {
|
type Category struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
OrganizationID uuid.UUID
|
OrganizationID uuid.UUID
|
||||||
OutletID *uuid.UUID
|
|
||||||
Name string
|
Name string
|
||||||
Description *string
|
Description *string
|
||||||
ImageURL *string
|
ImageURL *string
|
||||||
@ -21,7 +20,6 @@ type Category struct {
|
|||||||
|
|
||||||
type CreateCategoryRequest struct {
|
type CreateCategoryRequest struct {
|
||||||
OrganizationID uuid.UUID `validate:"required"`
|
OrganizationID uuid.UUID `validate:"required"`
|
||||||
OutletID *uuid.UUID
|
|
||||||
Name string `validate:"required,min=1,max=255"`
|
Name string `validate:"required,min=1,max=255"`
|
||||||
Description *string `validate:"omitempty,max=1000"`
|
Description *string `validate:"omitempty,max=1000"`
|
||||||
ImageURL *string `validate:"omitempty,url"`
|
ImageURL *string `validate:"omitempty,url"`
|
||||||
@ -29,7 +27,6 @@ type CreateCategoryRequest struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type UpdateCategoryRequest struct {
|
type UpdateCategoryRequest struct {
|
||||||
OutletID *uuid.UUID `validate:"omitempty,required"`
|
|
||||||
Name *string `validate:"omitempty,min=1,max=255"`
|
Name *string `validate:"omitempty,min=1,max=255"`
|
||||||
Description *string `validate:"omitempty,max=1000"`
|
Description *string `validate:"omitempty,max=1000"`
|
||||||
ImageURL *string `validate:"omitempty,url"`
|
ImageURL *string `validate:"omitempty,url"`
|
||||||
@ -40,7 +37,6 @@ type UpdateCategoryRequest struct {
|
|||||||
type CategoryResponse struct {
|
type CategoryResponse struct {
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
OrganizationID uuid.UUID
|
OrganizationID uuid.UUID
|
||||||
OutletID *uuid.UUID
|
|
||||||
Name string
|
Name string
|
||||||
Description *string
|
Description *string
|
||||||
ImageURL *string
|
ImageURL *string
|
||||||
|
|||||||
@ -55,7 +55,6 @@ func (p *CategoryProcessorImpl) CreateCategory(ctx context.Context, req *models.
|
|||||||
|
|
||||||
// Map request to entity
|
// Map request to entity
|
||||||
categoryEntity := mappers.CreateCategoryRequestToEntity(req)
|
categoryEntity := mappers.CreateCategoryRequestToEntity(req)
|
||||||
categoryEntity.OutletID = req.OutletID
|
|
||||||
|
|
||||||
// Create category
|
// Create category
|
||||||
if err := p.categoryRepo.Create(ctx, categoryEntity); err != nil {
|
if err := p.categoryRepo.Create(ctx, categoryEntity); err != nil {
|
||||||
@ -87,9 +86,6 @@ func (p *CategoryProcessorImpl) UpdateCategory(ctx context.Context, id uuid.UUID
|
|||||||
|
|
||||||
// Apply updates to entity
|
// Apply updates to entity
|
||||||
mappers.UpdateCategoryEntityFromRequest(existingCategory, req)
|
mappers.UpdateCategoryEntityFromRequest(existingCategory, req)
|
||||||
if req.OutletID != nil {
|
|
||||||
existingCategory.OutletID = req.OutletID
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update category
|
// Update category
|
||||||
if err := p.categoryRepo.Update(ctx, existingCategory); err != nil {
|
if err := p.categoryRepo.Update(ctx, existingCategory); err != nil {
|
||||||
|
|||||||
@ -25,7 +25,7 @@ func (r *CategoryRepositoryImpl) Create(ctx context.Context, category *entities.
|
|||||||
|
|
||||||
func (r *CategoryRepositoryImpl) GetByID(ctx context.Context, id uuid.UUID) (*entities.Category, error) {
|
func (r *CategoryRepositoryImpl) GetByID(ctx context.Context, id uuid.UUID) (*entities.Category, error) {
|
||||||
var category entities.Category
|
var category entities.Category
|
||||||
err := r.db.WithContext(ctx).Preload("Outlet").First(&category, "id = ?", id).Error
|
err := r.db.WithContext(ctx).First(&category, "id = ?", id).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -34,7 +34,7 @@ func (r *CategoryRepositoryImpl) GetByID(ctx context.Context, id uuid.UUID) (*en
|
|||||||
|
|
||||||
func (r *CategoryRepositoryImpl) GetWithProducts(ctx context.Context, id uuid.UUID) (*entities.Category, error) {
|
func (r *CategoryRepositoryImpl) GetWithProducts(ctx context.Context, id uuid.UUID) (*entities.Category, error) {
|
||||||
var category entities.Category
|
var category entities.Category
|
||||||
err := r.db.WithContext(ctx).Preload("Products").Preload("Outlet").First(&category, "id = ?", id).Error
|
err := r.db.WithContext(ctx).Preload("Products").First(&category, "id = ?", id).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ func (r *CategoryRepositoryImpl) List(ctx context.Context, filters map[string]in
|
|||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err := query.Preload("Outlet").Order("\"order\" ASC").Limit(limit).Offset(offset).Find(&categories).Error
|
err := query.Order("\"order\" ASC").Limit(limit).Offset(offset).Find(&categories).Error
|
||||||
return categories, total, err
|
return categories, total, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -88,9 +88,6 @@ func (s *CategoryServiceImpl) ListCategories(ctx context.Context, req *contract.
|
|||||||
if req.BusinessType != "" {
|
if req.BusinessType != "" {
|
||||||
filters["business_type"] = req.BusinessType
|
filters["business_type"] = req.BusinessType
|
||||||
}
|
}
|
||||||
if req.OutletID != nil {
|
|
||||||
filters["outlet_id"] = *req.OutletID
|
|
||||||
}
|
|
||||||
if req.Search != "" {
|
if req.Search != "" {
|
||||||
filters["search"] = req.Search
|
filters["search"] = req.Search
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,6 @@ import (
|
|||||||
func CreateCategoryRequestToModel(apctx *appcontext.ContextInfo, req *contract.CreateCategoryRequest) *models.CreateCategoryRequest {
|
func CreateCategoryRequestToModel(apctx *appcontext.ContextInfo, req *contract.CreateCategoryRequest) *models.CreateCategoryRequest {
|
||||||
return &models.CreateCategoryRequest{
|
return &models.CreateCategoryRequest{
|
||||||
OrganizationID: apctx.OrganizationID,
|
OrganizationID: apctx.OrganizationID,
|
||||||
OutletID: req.OutletID,
|
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
ImageURL: nil,
|
ImageURL: nil,
|
||||||
@ -19,7 +18,6 @@ func CreateCategoryRequestToModel(apctx *appcontext.ContextInfo, req *contract.C
|
|||||||
|
|
||||||
func UpdateCategoryRequestToModel(req *contract.UpdateCategoryRequest) *models.UpdateCategoryRequest {
|
func UpdateCategoryRequestToModel(req *contract.UpdateCategoryRequest) *models.UpdateCategoryRequest {
|
||||||
return &models.UpdateCategoryRequest{
|
return &models.UpdateCategoryRequest{
|
||||||
OutletID: req.OutletID,
|
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
ImageURL: nil,
|
ImageURL: nil,
|
||||||
@ -36,7 +34,6 @@ func CategoryModelResponseToResponse(cat *models.CategoryResponse) *contract.Cat
|
|||||||
return &contract.CategoryResponse{
|
return &contract.CategoryResponse{
|
||||||
ID: cat.ID,
|
ID: cat.ID,
|
||||||
OrganizationID: cat.OrganizationID,
|
OrganizationID: cat.OrganizationID,
|
||||||
OutletID: cat.OutletID,
|
|
||||||
Name: cat.Name,
|
Name: cat.Name,
|
||||||
Description: cat.Description,
|
Description: cat.Description,
|
||||||
BusinessType: "restaurant", // Default business type
|
BusinessType: "restaurant", // Default business type
|
||||||
|
|||||||
@ -59,7 +59,7 @@ func (v *CategoryValidatorImpl) ValidateUpdateCategoryRequest(req *contract.Upda
|
|||||||
}
|
}
|
||||||
|
|
||||||
// At least one field should be provided for update
|
// At least one field should be provided for update
|
||||||
if req.Name == nil && req.Description == nil && req.BusinessType == nil && req.Metadata == nil && req.OutletID == nil {
|
if req.Name == nil && req.Description == nil && req.BusinessType == nil && req.Metadata == nil {
|
||||||
return errors.New("at least one field must be provided for update"), constants.MissingFieldErrorCode
|
return errors.New("at least one field must be provided for update"), constants.MissingFieldErrorCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +0,0 @@
|
|||||||
DROP INDEX IF EXISTS idx_categories_outlet_id;
|
|
||||||
ALTER TABLE categories DROP CONSTRAINT IF EXISTS fk_categories_outlet;
|
|
||||||
ALTER TABLE categories DROP COLUMN IF EXISTS outlet_id;
|
|
||||||
@ -1,3 +0,0 @@
|
|||||||
ALTER TABLE categories ADD COLUMN outlet_id UUID;
|
|
||||||
ALTER TABLE categories ADD CONSTRAINT fk_categories_outlet FOREIGN KEY (outlet_id) REFERENCES outlets(id) ON DELETE SET NULL;
|
|
||||||
CREATE INDEX idx_categories_outlet_id ON categories(outlet_id);
|
|
||||||
Loading…
x
Reference in New Issue
Block a user