52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
|
package repository
|
|||
|
|
|||
|
import (
|
|||
|
"context"
|
|||
|
|
|||
|
"code.30cm.net/digimon/app-cloudep-product-service/pkg/domain/entity"
|
|||
|
"go.mongodb.org/mongo-driver/mongo"
|
|||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
|||
|
)
|
|||
|
|
|||
|
// ProductRepository 存取 Product 的地方
|
|||
|
type ProductRepository interface {
|
|||
|
Insert(ctx context.Context, data *entity.Product) error
|
|||
|
FindOneByID(ctx context.Context, id string) (*entity.Product, error)
|
|||
|
FindOneBySlug(ctx context.Context, slug string) (*entity.Product, error)
|
|||
|
Update(ctx context.Context, productID string, data *ProductUpdateParams) (*mongo.UpdateResult, error)
|
|||
|
Delete(ctx context.Context, id string) error
|
|||
|
ListProduct(ctx context.Context, params *ProductQueryParams) ([]*entity.Product, int64, error)
|
|||
|
Transaction(ctx context.Context,
|
|||
|
fn func(sessCtx mongo.SessionContext) (any, error),
|
|||
|
opts ...*options.TransactionOptions) error
|
|||
|
}
|
|||
|
|
|||
|
// ProductQueryParams 用於查詢專案的參數
|
|||
|
type ProductQueryParams struct {
|
|||
|
UID *string // 專案擁有者 UID
|
|||
|
IsPublished *bool // 是否已上架
|
|||
|
Category *string // 類別
|
|||
|
StartTime *int64 // 起始時間(Unix 時間戳)
|
|||
|
EndTime *int64 // 結束時間(Unix 時間戳)
|
|||
|
Slug *string // URL 後綴
|
|||
|
|
|||
|
PageIndex int64 // 頁碼
|
|||
|
PageSize int64 // 每頁數量
|
|||
|
}
|
|||
|
|
|||
|
// ProductUpdateParams 用於更新專案的參數
|
|||
|
type ProductUpdateParams struct {
|
|||
|
Title *string
|
|||
|
ShortTitle *string
|
|||
|
Details *string
|
|||
|
ShortDescription string
|
|||
|
Media []entity.Media
|
|||
|
Category *string
|
|||
|
Slug *string
|
|||
|
IsPublished *bool
|
|||
|
Amount *uint64
|
|||
|
StartTime *int64
|
|||
|
EndTime *int64
|
|||
|
CustomFields []entity.CustomFields
|
|||
|
}
|