feat(editor): update
This commit is contained in:
@@ -94,7 +94,11 @@ func (s *creator) Dashboard(ctx context.Context, userID int64) (*creator_dto.Das
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func (s *creator) ListContents(ctx context.Context, userID int64, filter *creator_dto.CreatorContentListFilter) ([]creator_dto.ContentItem, error) {
|
||||
func (s *creator) ListContents(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
filter *creator_dto.CreatorContentListFilter,
|
||||
) ([]creator_dto.ContentItem, error) {
|
||||
tid, err := s.getTenantID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -186,7 +190,12 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
})
|
||||
}
|
||||
|
||||
func (s *creator) UpdateContent(ctx context.Context, userID int64, id string, form *creator_dto.ContentUpdateForm) error {
|
||||
func (s *creator) UpdateContent(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
id string,
|
||||
form *creator_dto.ContentUpdateForm,
|
||||
) error {
|
||||
tid, err := s.getTenantID(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -215,7 +224,9 @@ func (s *creator) UpdateContent(ctx context.Context, userID int64, id string, fo
|
||||
count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).Count()
|
||||
newPrice := int64(form.Price * 100)
|
||||
if count > 0 {
|
||||
_, err = tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice))
|
||||
_, err = tx.ContentPrice.WithContext(ctx).
|
||||
Where(tx.ContentPrice.ContentID.Eq(cid)).
|
||||
UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice))
|
||||
} else {
|
||||
err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{
|
||||
TenantID: tid,
|
||||
@@ -263,14 +274,83 @@ func (s *creator) DeleteContent(ctx context.Context, userID int64, id string) er
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid), models.ContentQuery.TenantID.Eq(tid)).Delete()
|
||||
_, err = models.ContentQuery.WithContext(ctx).
|
||||
Where(models.ContentQuery.ID.Eq(cid), models.ContentQuery.TenantID.Eq(tid)).
|
||||
Delete()
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *creator) ListOrders(ctx context.Context, userID int64, filter *creator_dto.CreatorOrderListFilter) ([]creator_dto.Order, error) {
|
||||
func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*creator_dto.ContentEditDTO, error) {
|
||||
tid, err := s.getTenantID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cid := cast.ToInt64(id)
|
||||
|
||||
// Fetch Content with preloads
|
||||
var c models.Content
|
||||
err = models.ContentQuery.WithContext(ctx).
|
||||
Where(models.ContentQuery.ID.Eq(cid), models.ContentQuery.TenantID.Eq(tid)).
|
||||
UnderlyingDB().
|
||||
Preload("ContentAssets", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("sort ASC")
|
||||
}).
|
||||
Preload("ContentAssets.Asset").
|
||||
First(&c).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
}
|
||||
return nil, errorx.ErrDatabaseError.WithCause(err)
|
||||
}
|
||||
|
||||
// Fetch Price
|
||||
var price float64
|
||||
cp, err := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.Eq(cid)).First()
|
||||
if err == nil {
|
||||
price = float64(cp.PriceAmount) / 100.0
|
||||
}
|
||||
|
||||
dto := &creator_dto.ContentEditDTO{
|
||||
ID: cast.ToString(c.ID),
|
||||
Title: c.Title,
|
||||
Genre: c.Genre,
|
||||
Description: c.Description,
|
||||
Status: string(c.Status),
|
||||
Price: price,
|
||||
EnableTrial: c.PreviewSeconds > 0,
|
||||
PreviewSeconds: int(c.PreviewSeconds),
|
||||
Assets: make([]creator_dto.AssetDTO, 0),
|
||||
}
|
||||
|
||||
for _, ca := range c.ContentAssets {
|
||||
if ca.Asset != nil {
|
||||
sizeBytes := ca.Asset.Meta.Data().Size
|
||||
sizeMB := float64(sizeBytes) / 1024.0 / 1024.0
|
||||
sizeStr := cast.ToString(float64(int(sizeMB*100))/100.0) + " MB"
|
||||
|
||||
dto.Assets = append(dto.Assets, creator_dto.AssetDTO{
|
||||
ID: cast.ToString(ca.AssetID),
|
||||
Role: string(ca.Role),
|
||||
Type: string(ca.Asset.Type),
|
||||
URL: Common.GetAssetURL(ca.Asset.ObjectKey),
|
||||
Name: ca.Asset.ObjectKey, // Simple fallback
|
||||
Size: sizeStr,
|
||||
Sort: int(ca.Sort),
|
||||
})
|
||||
}
|
||||
}
|
||||
return dto, nil
|
||||
}
|
||||
|
||||
func (s *creator) ListOrders(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
filter *creator_dto.CreatorOrderListFilter,
|
||||
) ([]creator_dto.Order, error) {
|
||||
tid, err := s.getTenantID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -310,7 +390,9 @@ func (s *creator) ProcessRefund(ctx context.Context, userID int64, id string, fo
|
||||
uid := userID // Creator ID
|
||||
|
||||
// Fetch Order
|
||||
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid), models.OrderQuery.TenantID.Eq(tid)).First()
|
||||
o, err := models.OrderQuery.WithContext(ctx).
|
||||
Where(models.OrderQuery.ID.Eq(oid), models.OrderQuery.TenantID.Eq(tid)).
|
||||
First()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user