From 61870ec7a210240e066b71118bb9ca8bb1d3173c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Thu, 10 Apr 2025 15:47:07 +0800 Subject: [PATCH] add product_item --- internal/logic/product_item_service/get_logic.go | 2 +- .../product_item_service/list_by_product_id_logic.go | 2 +- internal/svc/service_context.go | 9 +++++---- pkg/domain/repository/product_item.go | 1 + pkg/repository/product_item_basic.go | 3 +++ pkg/usecase/product_item.go | 1 + 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/internal/logic/product_item_service/get_logic.go b/internal/logic/product_item_service/get_logic.go index 4b64b46..7571a80 100644 --- a/internal/logic/product_item_service/get_logic.go +++ b/internal/logic/product_item_service/get_logic.go @@ -72,7 +72,7 @@ func (l *GetLogic) Get(in *product.GetProductItemRequest) (*product.ProductItem, // 運費 c := make([]*product.CustomField, 0, len(item.CustomFields)) for _, fItem := range item.CustomFields { - f = append(f, &product.CustomField{ + c = append(c, &product.CustomField{ Key: fItem.Key, Value: fItem.Value, }) diff --git a/internal/logic/product_item_service/list_by_product_id_logic.go b/internal/logic/product_item_service/list_by_product_id_logic.go index c892704..101d9d0 100644 --- a/internal/logic/product_item_service/list_by_product_id_logic.go +++ b/internal/logic/product_item_service/list_by_product_id_logic.go @@ -96,7 +96,7 @@ func (l *ListByProductIdLogic) ListByProductId(in *PB.ListProductItemRequest) (* // 運費 c := make([]*PB.CustomField, 0, len(item.CustomFields)) for _, fItem := range item.CustomFields { - f = append(f, &PB.CustomField{ + c = append(c, &PB.CustomField{ Key: fItem.Key, Value: fItem.Value, }) diff --git a/internal/svc/service_context.go b/internal/svc/service_context.go index e85ee1d..228ba57 100644 --- a/internal/svc/service_context.go +++ b/internal/svc/service_context.go @@ -20,10 +20,11 @@ type ServiceContext struct { func NewServiceContext(c config.Config) *ServiceContext { return &ServiceContext{ - CategoryUseCase: MustCategory(c), - TagsUseCase: MustTags(c), - KYCUseCase: MustKYC(c), - Config: c, + CategoryUseCase: MustCategory(c), + TagsUseCase: MustTags(c), + KYCUseCase: MustKYC(c), + ProductItemUseCase: MustProductItem(c), + Config: c, } } diff --git a/pkg/domain/repository/product_item.go b/pkg/domain/repository/product_item.go index 032f113..9edbfda 100644 --- a/pkg/domain/repository/product_item.go +++ b/pkg/domain/repository/product_item.go @@ -45,6 +45,7 @@ type ProductItemQueryParams struct { ReferenceID *string // 對應參照的ID IsFree *bool // 是否為免費品項(贈品) Status *product.ItemStatus // 商品狀態 + IsUnlimited *bool } type ProductUpdateItem struct { Name *string // 名稱 diff --git a/pkg/repository/product_item_basic.go b/pkg/repository/product_item_basic.go index c3f89a6..9030095 100644 --- a/pkg/repository/product_item_basic.go +++ b/pkg/repository/product_item_basic.go @@ -235,6 +235,9 @@ func (repo *ProductItemRepository) ListProductItem(ctx context.Context, param re if param.Status != nil { filter["status"] = *param.Status } + if param.IsUnlimited != nil { + filter["is_un_limit"] = *param.IsUnlimited + } // 設置排序選項 opts := options.Find().SetSkip((param.PageIndex - 1) * param.PageSize).SetLimit(param.PageSize) diff --git a/pkg/usecase/product_item.go b/pkg/usecase/product_item.go index b29b133..98cf21f 100644 --- a/pkg/usecase/product_item.go +++ b/pkg/usecase/product_item.go @@ -336,6 +336,7 @@ func (use *ProductItemUseCase) List(ctx context.Context, filter usecase.QueryPro ReferenceID: filter.ReferenceID, IsFree: filter.IsFree, Status: filter.Status, + IsUnlimited: filter.IsUnLimit, // 注意:若需要依 IsUnLimit 過濾,需擴充 repository.ProductItemQueryParams 結構 } entities, total, err := use.ProductItemUseCaseParam.ProductItems.ListProductItem(ctx, repoQuery)