feat: align ids to int64

This commit is contained in:
2026-01-08 09:57:04 +08:00
parent a1de16bc01
commit d98f41f1ac
39 changed files with 298 additions and 339 deletions

View File

@@ -29,7 +29,7 @@ func (c *contents) List(ctx fiber.Ctx, filter *dto.SuperContentListFilter) (*req
// Update content status // Update content status
// //
// @Router /super/v1/tenants/:tenantID/contents/:contentID/status [patch] // @Router /super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status [patch]
// @Summary Update content status // @Summary Update content status
// @Description Update content status // @Description Update content status
// @Tags Content // @Tags Content

View File

@@ -13,7 +13,7 @@ type LoginResponse struct {
} }
type User struct { type User struct {
ID string `json:"id"` ID int64 `json:"id"`
Phone string `json:"phone"` Phone string `json:"phone"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`

View File

@@ -29,7 +29,7 @@ func (c *orders) List(ctx fiber.Ctx, filter *dto.SuperOrderListFilter) (*request
// Get order // Get order
// //
// @Router /super/v1/orders/:id [get] // @Router /super/v1/orders/:id<int> [get]
// @Summary Get order // @Summary Get order
// @Description Get order // @Description Get order
// @Tags Order // @Tags Order
@@ -44,7 +44,7 @@ func (c *orders) Get(ctx fiber.Ctx, id int64) (*dto.SuperOrderDetail, error) {
// Refund order // Refund order
// //
// @Router /super/v1/orders/:id/refund [post] // @Router /super/v1/orders/:id<int>/refund [post]
// @Summary Refund order // @Summary Refund order
// @Description Refund order // @Description Refund order
// @Tags Order // @Tags Order

View File

@@ -45,7 +45,7 @@ func (c *tenants) Create(ctx fiber.Ctx, form *dto.TenantCreateForm) error {
// Get tenant // Get tenant
// //
// @Router /super/v1/tenants/:id [get] // @Router /super/v1/tenants/:id<int> [get]
// @Summary Get tenant // @Summary Get tenant
// @Description Get tenant // @Description Get tenant
// @Tags Tenant // @Tags Tenant
@@ -60,7 +60,7 @@ func (c *tenants) Get(ctx fiber.Ctx, id int64) (*dto.TenantItem, error) {
// Update tenant status // Update tenant status
// //
// @Router /super/v1/tenants/:id/status [patch] // @Router /super/v1/tenants/:id<int>/status [patch]
// @Summary Update tenant status // @Summary Update tenant status
// @Description Update tenant status // @Description Update tenant status
// @Tags Tenant // @Tags Tenant
@@ -77,7 +77,7 @@ func (c *tenants) UpdateStatus(ctx fiber.Ctx, id int64, form *dto.TenantStatusUp
// Update tenant expire // Update tenant expire
// //
// @Router /super/v1/tenants/:id [patch] // @Router /super/v1/tenants/:id<int> [patch]
// @Summary Update tenant expire // @Summary Update tenant expire
// @Description Update tenant expire // @Description Update tenant expire
// @Tags Tenant // @Tags Tenant

View File

@@ -30,7 +30,7 @@ func (c *users) List(ctx fiber.Ctx, filter *dto.UserListFilter) (*requests.Pager
// Get user // Get user
// //
// @Router /super/v1/users/:id [get] // @Router /super/v1/users/:id<int> [get]
// @Summary Get user // @Summary Get user
// @Description Get user // @Description Get user
// @Tags User // @Tags User
@@ -45,7 +45,7 @@ func (c *users) Get(ctx fiber.Ctx, id int64) (*dto.UserItem, error) {
// Update user status // Update user status
// //
// @Router /super/v1/users/:id/status [patch] // @Router /super/v1/users/:id<int>/status [patch]
// @Summary Update user status // @Summary Update user status
// @Description Update user status // @Description Update user status
// @Tags User // @Tags User
@@ -62,7 +62,7 @@ func (c *users) UpdateStatus(ctx fiber.Ctx, id int64, form *dto.UserStatusUpdate
// Update user roles // Update user roles
// //
// @Router /super/v1/users/:id/roles [patch] // @Router /super/v1/users/:id<int>/roles [patch]
// @Summary Update user roles // @Summary Update user roles
// @Description Update user roles // @Description Update user roles
// @Tags User // @Tags User

View File

@@ -125,17 +125,17 @@ func (c *Common) AbortUpload(ctx fiber.Ctx, user *models.User, uploadId string)
return services.Common.AbortUpload(ctx.Context(), user.ID, uploadId) return services.Common.AbortUpload(ctx.Context(), user.ID, uploadId)
} }
// @Router /v1/media-assets/:id [delete] // @Router /v1/media-assets/:id<int> [delete]
// @Summary Delete media asset // @Summary Delete media asset
// @Description Delete media asset // @Description Delete media asset
// @Tags Common // @Tags Common
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Asset ID" // @Param id path int64 true "Asset ID"
// @Success 200 {string} string "OK" // @Success 200 {string} string "OK"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (c *Common) DeleteMediaAsset(ctx fiber.Ctx, user *models.User, id string) error { func (c *Common) DeleteMediaAsset(ctx fiber.Ctx, user *models.User, id int64) error {
return services.Common.DeleteMediaAsset(ctx.Context(), user.ID, id) return services.Common.DeleteMediaAsset(ctx.Context(), user.ID, id)
} }

View File

@@ -37,120 +37,120 @@ func (c *Content) List(
// Get content detail // Get content detail
// //
// @Router /v1/contents/:id [get] // @Router /v1/contents/:id<int> [get]
// @Summary Get content detail // @Summary Get content detail
// @Description Get content detail by ID // @Description Get content detail by ID
// @Tags Content // @Tags Content
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {object} dto.ContentDetail // @Success 200 {object} dto.ContentDetail
// @Bind id path // @Bind id path
func (c *Content) Get(ctx fiber.Ctx, id string) (*dto.ContentDetail, error) { func (c *Content) Get(ctx fiber.Ctx, id int64) (*dto.ContentDetail, error) {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.Get(ctx, uid, id) return services.Content.Get(ctx, uid, id)
} }
// Get comments for a content // Get comments for a content
// //
// @Router /v1/contents/:id/comments [get] // @Router /v1/contents/:id<int>/comments [get]
// @Summary Get comments // @Summary Get comments
// @Description Get comments for a content // @Description Get comments for a content
// @Tags Content // @Tags Content
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Param page query int false "Page number" // @Param page query int false "Page number"
// @Success 200 {object} requests.Pager{items=[]dto.Comment} // @Success 200 {object} requests.Pager{items=[]dto.Comment}
// @Bind id path // @Bind id path
// @Bind page query // @Bind page query
func (c *Content) ListComments(ctx fiber.Ctx, id string, page int) (*requests.Pager, error) { func (c *Content) ListComments(ctx fiber.Ctx, id int64, page int) (*requests.Pager, error) {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.ListComments(ctx, uid, id, page) return services.Content.ListComments(ctx, uid, id, page)
} }
// Post a comment // Post a comment
// //
// @Router /v1/contents/:id/comments [post] // @Router /v1/contents/:id<int>/comments [post]
// @Summary Post comment // @Summary Post comment
// @Description Post a comment to a content // @Description Post a comment to a content
// @Tags Content // @Tags Content
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Param form body dto.CommentCreateForm true "Comment form" // @Param form body dto.CommentCreateForm true "Comment form"
// @Success 200 {string} string "Comment created" // @Success 200 {string} string "Comment created"
// @Bind id path // @Bind id path
// @Bind form body // @Bind form body
func (c *Content) CreateComment(ctx fiber.Ctx, id string, form *dto.CommentCreateForm) error { func (c *Content) CreateComment(ctx fiber.Ctx, id int64, form *dto.CommentCreateForm) error {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.CreateComment(ctx, uid, id, form) return services.Content.CreateComment(ctx, uid, id, form)
} }
// Like a comment // Like a comment
// //
// @Router /v1/comments/:id/like [post] // @Router /v1/comments/:id<int>/like [post]
// @Summary Like comment // @Summary Like comment
// @Description Like a comment // @Description Like a comment
// @Tags Content // @Tags Content
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Comment ID" // @Param id path int64 true "Comment ID"
// @Success 200 {string} string "Liked" // @Success 200 {string} string "Liked"
// @Bind id path // @Bind id path
func (c *Content) LikeComment(ctx fiber.Ctx, id string) error { func (c *Content) LikeComment(ctx fiber.Ctx, id int64) error {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.LikeComment(ctx, uid, id) return services.Content.LikeComment(ctx, uid, id)
} }
// Add like // Add like
// //
// @Router /v1/contents/:id/like [post] // @Router /v1/contents/:id<int>/like [post]
// @Summary Add like // @Summary Add like
// @Tags Content // @Tags Content
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {string} string "Liked" // @Success 200 {string} string "Liked"
// @Bind id path // @Bind id path
func (c *Content) AddLike(ctx fiber.Ctx, id string) error { func (c *Content) AddLike(ctx fiber.Ctx, id int64) error {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.AddLike(ctx, uid, id) return services.Content.AddLike(ctx, uid, id)
} }
// Remove like // Remove like
// //
// @Router /v1/contents/:id/like [delete] // @Router /v1/contents/:id<int>/like [delete]
// @Summary Remove like // @Summary Remove like
// @Tags Content // @Tags Content
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {string} string "Unliked" // @Success 200 {string} string "Unliked"
// @Bind id path // @Bind id path
func (c *Content) RemoveLike(ctx fiber.Ctx, id string) error { func (c *Content) RemoveLike(ctx fiber.Ctx, id int64) error {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.RemoveLike(ctx, uid, id) return services.Content.RemoveLike(ctx, uid, id)
} }
// Add favorite // Add favorite
// //
// @Router /v1/contents/:id/favorite [post] // @Router /v1/contents/:id<int>/favorite [post]
// @Summary Add favorite // @Summary Add favorite
// @Tags Content // @Tags Content
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {string} string "Favorited" // @Success 200 {string} string "Favorited"
// @Bind id path // @Bind id path
func (c *Content) AddFavorite(ctx fiber.Ctx, id string) error { func (c *Content) AddFavorite(ctx fiber.Ctx, id int64) error {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.AddFavorite(ctx, uid, id) return services.Content.AddFavorite(ctx, uid, id)
} }
// Remove favorite // Remove favorite
// //
// @Router /v1/contents/:id/favorite [delete] // @Router /v1/contents/:id<int>/favorite [delete]
// @Summary Remove favorite // @Summary Remove favorite
// @Tags Content // @Tags Content
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {string} string "Unfavorited" // @Success 200 {string} string "Unfavorited"
// @Bind id path // @Bind id path
func (c *Content) RemoveFavorite(ctx fiber.Ctx, id string) error { func (c *Content) RemoveFavorite(ctx fiber.Ctx, id int64) error {
uid := getUserID(ctx) uid := getUserID(ctx)
return services.Content.RemoveFavorite(ctx, uid, id) return services.Content.RemoveFavorite(ctx, uid, id)
} }

View File

@@ -44,17 +44,17 @@ func (c *Creator) Dashboard(ctx fiber.Ctx, user *models.User) (*dto.DashboardSta
// Get content details for edit // Get content details for edit
// //
// @Router /v1/creator/contents/:id [get] // @Router /v1/creator/contents/:id<int> [get]
// @Summary Get content // @Summary Get content
// @Description Get content details for edit // @Description Get content details for edit
// @Tags CreatorCenter // @Tags CreatorCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {object} dto.ContentEditDTO // @Success 200 {object} dto.ContentEditDTO
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (c *Creator) GetContent(ctx fiber.Ctx, user *models.User, id string) (*dto.ContentEditDTO, error) { func (c *Creator) GetContent(ctx fiber.Ctx, user *models.User, id int64) (*dto.ContentEditDTO, error) {
return services.Creator.GetContent(ctx, user.ID, id) return services.Creator.GetContent(ctx, user.ID, id)
} }
@@ -98,35 +98,35 @@ func (c *Creator) CreateContent(ctx fiber.Ctx, user *models.User, form *dto.Cont
// Update content // Update content
// //
// @Router /v1/creator/contents/:id [put] // @Router /v1/creator/contents/:id<int> [put]
// @Summary Update content // @Summary Update content
// @Description Update content // @Description Update content
// @Tags CreatorCenter // @Tags CreatorCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Param form body dto.ContentUpdateForm true "Update form" // @Param form body dto.ContentUpdateForm true "Update form"
// @Success 200 {string} string "Updated" // @Success 200 {string} string "Updated"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
// @Bind form body // @Bind form body
func (c *Creator) UpdateContent(ctx fiber.Ctx, user *models.User, id string, form *dto.ContentUpdateForm) error { func (c *Creator) UpdateContent(ctx fiber.Ctx, user *models.User, id int64, form *dto.ContentUpdateForm) error {
return services.Creator.UpdateContent(ctx, user.ID, id, form) return services.Creator.UpdateContent(ctx, user.ID, id, form)
} }
// Delete content // Delete content
// //
// @Router /v1/creator/contents/:id [delete] // @Router /v1/creator/contents/:id<int> [delete]
// @Summary Delete content // @Summary Delete content
// @Description Delete content // @Description Delete content
// @Tags CreatorCenter // @Tags CreatorCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Content ID" // @Param id path int64 true "Content ID"
// @Success 200 {string} string "Deleted" // @Success 200 {string} string "Deleted"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (c *Creator) DeleteContent(ctx fiber.Ctx, user *models.User, id string) error { func (c *Creator) DeleteContent(ctx fiber.Ctx, user *models.User, id int64) error {
return services.Creator.DeleteContent(ctx, user.ID, id) return services.Creator.DeleteContent(ctx, user.ID, id)
} }
@@ -153,19 +153,19 @@ func (c *Creator) ListOrders(
// Process refund // Process refund
// //
// @Router /v1/creator/orders/:id/refund [post] // @Router /v1/creator/orders/:id<int>/refund [post]
// @Summary Process refund // @Summary Process refund
// @Description Process refund // @Description Process refund
// @Tags CreatorCenter // @Tags CreatorCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Order ID" // @Param id path int64 true "Order ID"
// @Param form body dto.RefundForm true "Refund form" // @Param form body dto.RefundForm true "Refund form"
// @Success 200 {string} string "Processed" // @Success 200 {string} string "Processed"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
// @Bind form body // @Bind form body
func (c *Creator) Refund(ctx fiber.Ctx, user *models.User, id string, form *dto.RefundForm) error { func (c *Creator) Refund(ctx fiber.Ctx, user *models.User, id int64, form *dto.RefundForm) error {
return services.Creator.ProcessRefund(ctx, user.ID, id, form) return services.Creator.ProcessRefund(ctx, user.ID, id, form)
} }
@@ -237,11 +237,11 @@ func (c *Creator) AddPayoutAccount(ctx fiber.Ctx, user *models.User, form *dto.P
// @Tags CreatorCenter // @Tags CreatorCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id query string true "Account ID" // @Param id query int64 true "Account ID"
// @Success 200 {string} string "Removed" // @Success 200 {string} string "Removed"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id query // @Bind id query
func (c *Creator) RemovePayoutAccount(ctx fiber.Ctx, user *models.User, id string) error { func (c *Creator) RemovePayoutAccount(ctx fiber.Ctx, user *models.User, id int64) error {
return services.Creator.RemovePayoutAccount(ctx, user.ID, id) return services.Creator.RemovePayoutAccount(ctx, user.ID, id)
} }

View File

@@ -17,7 +17,7 @@ type LoginResponse struct {
} }
type User struct { type User struct {
ID string `json:"id"` ID int64 `json:"id"`
Phone string `json:"phone"` Phone string `json:"phone"`
Nickname string `json:"nickname"` Nickname string `json:"nickname"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`

View File

@@ -3,7 +3,7 @@ package dto
import "quyun/v2/app/requests" import "quyun/v2/app/requests"
type UploadResult struct { type UploadResult struct {
ID string `json:"id"` ID int64 `json:"id"`
URL string `json:"url"` URL string `json:"url"`
Filename string `json:"filename"` Filename string `json:"filename"`
Size int64 `json:"size"` Size int64 `json:"size"`

View File

@@ -6,20 +6,20 @@ type ContentListFilter struct {
requests.Pagination requests.Pagination
Keyword *string `query:"keyword"` Keyword *string `query:"keyword"`
Genre *string `query:"genre"` Genre *string `query:"genre"`
TenantID *string `query:"tenantId"` TenantID *int64 `query:"tenantId"`
Sort *string `query:"sort"` Sort *string `query:"sort"`
IsPinned *bool `query:"is_pinned"` IsPinned *bool `query:"is_pinned"`
PriceType *string `query:"price_type"` PriceType *string `query:"price_type"`
} }
type ContentItem struct { type ContentItem struct {
ID string `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Cover string `json:"cover"` Cover string `json:"cover"`
Genre string `json:"genre"` Genre string `json:"genre"`
Type string `json:"type"` // video, audio, article Type string `json:"type"` // video, audio, article
Price float64 `json:"price"` Price float64 `json:"price"`
AuthorID string `json:"author_id"` AuthorID int64 `json:"author_id"`
AuthorName string `json:"author_name"` AuthorName string `json:"author_name"`
AuthorAvatar string `json:"author_avatar"` AuthorAvatar string `json:"author_avatar"`
AuthorIsFollowing bool `json:"author_is_following"` AuthorIsFollowing bool `json:"author_is_following"`
@@ -52,24 +52,24 @@ type Meta struct {
} }
type Comment struct { type Comment struct {
ID string `json:"id"` ID int64 `json:"id"`
Content string `json:"content"` Content string `json:"content"`
UserID string `json:"user_id"` UserID int64 `json:"user_id"`
UserNickname string `json:"user_nickname"` UserNickname string `json:"user_nickname"`
UserAvatar string `json:"user_avatar"` UserAvatar string `json:"user_avatar"`
CreateTime string `json:"create_time"` CreateTime string `json:"create_time"`
Likes int `json:"likes"` Likes int `json:"likes"`
IsLiked bool `json:"is_liked"` IsLiked bool `json:"is_liked"`
ReplyTo string `json:"reply_to"` ReplyTo int64 `json:"reply_to"`
} }
type CommentCreateForm struct { type CommentCreateForm struct {
Content string `json:"content"` Content string `json:"content"`
ReplyTo string `json:"reply_to"` ReplyTo int64 `json:"reply_to"`
} }
type Topic struct { type Topic struct {
ID string `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Cover string `json:"cover"` Cover string `json:"cover"`
Tag string `json:"tag"` Tag string `json:"tag"`

View File

@@ -1,8 +1,8 @@
package dto package dto
type UserCouponItem struct { type UserCouponItem struct {
ID string `json:"id"` ID int64 `json:"id"`
CouponID string `json:"coupon_id"` CouponID int64 `json:"coupon_id"`
Title string `json:"title"` Title string `json:"title"`
Description string `json:"description"` Description string `json:"description"`
Type string `json:"type"` Type string `json:"type"`

View File

@@ -31,8 +31,8 @@ type ContentCreateForm struct {
Key string `json:"key"` Key string `json:"key"`
Price float64 `json:"price"` Price float64 `json:"price"`
Status string `json:"status"` Status string `json:"status"`
CoverIDs []string `json:"cover_ids"` CoverIDs []int64 `json:"cover_ids"`
MediaIDs []string `json:"media_ids"` MediaIDs []int64 `json:"media_ids"`
} }
type ContentUpdateForm struct { type ContentUpdateForm struct {
@@ -42,12 +42,12 @@ type ContentUpdateForm struct {
Price *float64 `json:"price"` Price *float64 `json:"price"`
Status string `json:"status"` Status string `json:"status"`
IsPinned *bool `json:"is_pinned"` IsPinned *bool `json:"is_pinned"`
CoverIDs []string `json:"cover_ids"` CoverIDs []int64 `json:"cover_ids"`
MediaIDs []string `json:"media_ids"` MediaIDs []int64 `json:"media_ids"`
} }
type ContentEditDTO struct { type ContentEditDTO struct {
ID string `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Genre string `json:"genre"` Genre string `json:"genre"`
Key string `json:"key"` Key string `json:"key"`
@@ -60,7 +60,7 @@ type ContentEditDTO struct {
} }
type CreatorContentItem struct { type CreatorContentItem struct {
ID string `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Genre string `json:"genre"` Genre string `json:"genre"`
Key string `json:"key"` Key string `json:"key"`
@@ -79,7 +79,7 @@ type CreatorContentItem struct {
} }
type AssetDTO struct { type AssetDTO struct {
ID string `json:"id"` ID int64 `json:"id"`
Role string `json:"role"` Role string `json:"role"`
Type string `json:"type"` Type string `json:"type"`
URL string `json:"url"` URL string `json:"url"`
@@ -110,7 +110,7 @@ type RefundForm struct {
} }
type Settings struct { type Settings struct {
ID string `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Bio string `json:"bio"` Bio string `json:"bio"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
@@ -119,7 +119,7 @@ type Settings struct {
} }
type PayoutAccount struct { type PayoutAccount struct {
ID string `json:"id"` ID int64 `json:"id"`
Type string `json:"type"` // bank, alipay Type string `json:"type"` // bank, alipay
Name string `json:"name"` Name string `json:"name"`
Account string `json:"account"` Account string `json:"account"`
@@ -129,5 +129,5 @@ type PayoutAccount struct {
type WithdrawForm struct { type WithdrawForm struct {
Amount float64 `json:"amount"` Amount float64 `json:"amount"`
Method string `json:"method"` // wallet, external Method string `json:"method"` // wallet, external
AccountID string `json:"account_id"` AccountID int64 `json:"account_id"`
} }

View File

@@ -1,14 +1,14 @@
package dto package dto
type OrderCreateForm struct { type OrderCreateForm struct {
ContentID string `json:"content_id"` ContentID int64 `json:"content_id"`
Sku string `json:"sku"` Sku string `json:"sku"`
Quantity int `json:"quantity"` Quantity int `json:"quantity"`
UserCouponID string `json:"user_coupon_id"` UserCouponID int64 `json:"user_coupon_id"`
} }
type OrderCreateResponse struct { type OrderCreateResponse struct {
OrderID string `json:"order_id"` OrderID int64 `json:"order_id"`
} }
type OrderPayForm struct { type OrderPayForm struct {

View File

@@ -9,7 +9,7 @@ type TenantListFilter struct {
} }
type TenantProfile struct { type TenantProfile struct {
ID string `json:"id"` ID int64 `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Avatar string `json:"avatar"` Avatar string `json:"avatar"`
Cover string `json:"cover"` Cover string `json:"cover"`

View File

@@ -22,7 +22,7 @@ type WalletResponse struct {
} }
type Transaction struct { type Transaction struct {
ID string `json:"id"` ID int64 `json:"id"`
Title string `json:"title"` Title string `json:"title"`
Amount float64 `json:"amount"` Amount float64 `json:"amount"`
Type string `json:"type"` // income, expense Type string `json:"type"` // income, expense
@@ -40,7 +40,7 @@ type RechargeResponse struct {
} }
type Order struct { type Order struct {
ID string `json:"id"` ID int64 `json:"id"`
Type string `json:"type"` // consts.OrderType... Type string `json:"type"` // consts.OrderType...
TypeDescription string `json:"type_description"` TypeDescription string `json:"type_description"`
CreateTime string `json:"create_time"` CreateTime string `json:"create_time"`
@@ -50,7 +50,7 @@ type Order struct {
Amount float64 `json:"amount"` Amount float64 `json:"amount"`
Quantity int `json:"quantity"` Quantity int `json:"quantity"`
Items []ContentItem `json:"items"` Items []ContentItem `json:"items"`
TenantID string `json:"tenant_id"` TenantID int64 `json:"tenant_id"`
TenantName string `json:"tenant_name"` TenantName string `json:"tenant_name"`
IsVirtual bool `json:"is_virtual"` IsVirtual bool `json:"is_virtual"`
BuyerName string `json:"buyer_name"` BuyerName string `json:"buyer_name"`
@@ -60,7 +60,7 @@ type Order struct {
} }
type Notification struct { type Notification struct {
ID string `json:"id"` ID int64 `json:"id"`
Type string `json:"type"` Type string `json:"type"`
Title string `json:"title"` Title string `json:"title"`
Content string `json:"content"` Content string `json:"content"`

View File

@@ -14,19 +14,19 @@ type Tenant struct{}
// List creator contents // List creator contents
// //
// @Router /v1/creators/:id/contents [get] // @Router /v1/creators/:id<int>/contents [get]
// @Summary List creator contents // @Summary List creator contents
// @Description List contents of a specific creator // @Description List contents of a specific creator
// @Tags TenantPublic // @Tags TenantPublic
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Tenant ID" // @Param id path int64 true "Tenant ID"
// @Param page query int false "Page" // @Param page query int false "Page"
// @Param limit query int false "Limit" // @Param limit query int false "Limit"
// @Success 200 {object} requests.Pager // @Success 200 {object} requests.Pager
// @Bind id path // @Bind id path
// @Bind filter query // @Bind filter query
func (t *Tenant) ListContents(ctx fiber.Ctx, id string, filter *dto.ContentListFilter) (*requests.Pager, error) { func (t *Tenant) ListContents(ctx fiber.Ctx, id int64, filter *dto.ContentListFilter) (*requests.Pager, error) {
if filter == nil { if filter == nil {
filter = &dto.ContentListFilter{} filter = &dto.ContentListFilter{}
} }
@@ -53,17 +53,17 @@ func (t *Tenant) List(ctx fiber.Ctx, filter *dto.TenantListFilter) (*requests.Pa
// Get tenant public profile // Get tenant public profile
// //
// @Router /v1/tenants/:id [get] // @Router /v1/tenants/:id<int> [get]
// @Summary Get tenant profile // @Summary Get tenant profile
// @Description Get tenant public profile // @Description Get tenant public profile
// @Tags TenantPublic // @Tags TenantPublic
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Tenant ID" // @Param id path int64 true "Tenant ID"
// @Success 200 {object} dto.TenantProfile // @Success 200 {object} dto.TenantProfile
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id string) (*dto.TenantProfile, error) { func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id int64) (*dto.TenantProfile, error) {
uid := int64(0) uid := int64(0)
if user != nil { if user != nil {
uid = user.ID uid = user.ID
@@ -73,32 +73,32 @@ func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id string) (*dto.TenantPr
// Follow a tenant // Follow a tenant
// //
// @Router /v1/tenants/:id/follow [post] // @Router /v1/tenants/:id<int>/follow [post]
// @Summary Follow tenant // @Summary Follow tenant
// @Description Follow a tenant // @Description Follow a tenant
// @Tags TenantPublic // @Tags TenantPublic
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Tenant ID" // @Param id path int64 true "Tenant ID"
// @Success 200 {string} string "Followed" // @Success 200 {string} string "Followed"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (t *Tenant) Follow(ctx fiber.Ctx, user *models.User, id string) error { func (t *Tenant) Follow(ctx fiber.Ctx, user *models.User, id int64) error {
return services.Tenant.Follow(ctx, user.ID, id) return services.Tenant.Follow(ctx, user.ID, id)
} }
// Unfollow a tenant // Unfollow a tenant
// //
// @Router /v1/tenants/:id/follow [delete] // @Router /v1/tenants/:id<int>/follow [delete]
// @Summary Unfollow tenant // @Summary Unfollow tenant
// @Description Unfollow a tenant // @Description Unfollow a tenant
// @Tags TenantPublic // @Tags TenantPublic
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Tenant ID" // @Param id path int64 true "Tenant ID"
// @Success 200 {string} string "Unfollowed" // @Success 200 {string} string "Unfollowed"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (t *Tenant) Unfollow(ctx fiber.Ctx, user *models.User, id string) error { func (t *Tenant) Unfollow(ctx fiber.Ctx, user *models.User, id int64) error {
return services.Tenant.Unfollow(ctx, user.ID, id) return services.Tenant.Unfollow(ctx, user.ID, id)
} }

View File

@@ -33,13 +33,13 @@ func (t *Transaction) Create(
// Pay for order // Pay for order
// //
// @Router /v1/orders/:id/pay [post] // @Router /v1/orders/:id<int>/pay [post]
// @Summary Pay for order // @Summary Pay for order
// @Description Pay for order // @Description Pay for order
// @Tags Transaction // @Tags Transaction
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Order ID" // @Param id path int64 true "Order ID"
// @Param form body dto.OrderPayForm true "Pay form" // @Param form body dto.OrderPayForm true "Pay form"
// @Success 200 {object} dto.OrderPayResponse // @Success 200 {object} dto.OrderPayResponse
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
@@ -48,7 +48,7 @@ func (t *Transaction) Create(
func (t *Transaction) Pay( func (t *Transaction) Pay(
ctx fiber.Ctx, ctx fiber.Ctx,
user *models.User, user *models.User,
id string, id int64,
form *dto.OrderPayForm, form *dto.OrderPayForm,
) (*dto.OrderPayResponse, error) { ) (*dto.OrderPayResponse, error) {
return services.Order.Pay(ctx, user.ID, id, form) return services.Order.Pay(ctx, user.ID, id, form)
@@ -56,21 +56,21 @@ func (t *Transaction) Pay(
// Check order payment status // Check order payment status
// //
// @Router /v1/orders/:id/status [get] // @Router /v1/orders/:id<int>/status [get]
// @Summary Check order status // @Summary Check order status
// @Description Check order payment status // @Description Check order payment status
// @Tags Transaction // @Tags Transaction
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Order ID" // @Param id path int64 true "Order ID"
// @Success 200 {object} dto.OrderStatusResponse // @Success 200 {object} dto.OrderStatusResponse
// @Bind id path // @Bind id path
func (t *Transaction) Status(ctx fiber.Ctx, id string) (*dto.OrderStatusResponse, error) { func (t *Transaction) Status(ctx fiber.Ctx, id int64) (*dto.OrderStatusResponse, error) {
return services.Order.Status(ctx, id) return services.Order.Status(ctx, id)
} }
type WebhookForm struct { type WebhookForm struct {
OrderID string `json:"order_id"` OrderID int64 `json:"order_id"`
ExternalID string `json:"external_id"` ExternalID string `json:"external_id"`
} }

View File

@@ -108,17 +108,17 @@ func (u *User) ListOrders(ctx fiber.Ctx, user *models.User, status string) ([]dt
// Get user order detail // Get user order detail
// //
// @Router /v1/me/orders/:id [get] // @Router /v1/me/orders/:id<int> [get]
// @Summary Get order detail // @Summary Get order detail
// @Description Get user order detail // @Description Get user order detail
// @Tags UserCenter // @Tags UserCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Order ID" // @Param id path int64 true "Order ID"
// @Success 200 {object} dto.Order // @Success 200 {object} dto.Order
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (u *User) GetOrder(ctx fiber.Ctx, user *models.User, id string) (*dto.Order, error) { func (u *User) GetOrder(ctx fiber.Ctx, user *models.User, id int64) (*dto.Order, error) {
return services.Order.GetUserOrder(ctx, user.ID, id) return services.Order.GetUserOrder(ctx, user.ID, id)
} }
@@ -158,27 +158,27 @@ func (u *User) Favorites(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, e
// @Tags UserCenter // @Tags UserCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param contentId query string true "Content ID" // @Param contentId query int64 true "Content ID"
// @Success 200 {string} string "Added" // @Success 200 {string} string "Added"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind contentId query // @Bind contentId query
func (u *User) AddFavorite(ctx fiber.Ctx, user *models.User, contentId string) error { func (u *User) AddFavorite(ctx fiber.Ctx, user *models.User, contentId int64) error {
return services.Content.AddFavorite(ctx, user.ID, contentId) return services.Content.AddFavorite(ctx, user.ID, contentId)
} }
// Remove from favorites // Remove from favorites
// //
// @Router /v1/me/favorites/:contentId [delete] // @Router /v1/me/favorites/:contentId<int> [delete]
// @Summary Remove favorite // @Summary Remove favorite
// @Description Remove from favorites // @Description Remove from favorites
// @Tags UserCenter // @Tags UserCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param contentId path string true "Content ID" // @Param contentId path int64 true "Content ID"
// @Success 200 {string} string "Removed" // @Success 200 {string} string "Removed"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind contentId path // @Bind contentId path
func (u *User) RemoveFavorite(ctx fiber.Ctx, user *models.User, contentId string) error { func (u *User) RemoveFavorite(ctx fiber.Ctx, user *models.User, contentId int64) error {
return services.Content.RemoveFavorite(ctx, user.ID, contentId) return services.Content.RemoveFavorite(ctx, user.ID, contentId)
} }
@@ -204,27 +204,27 @@ func (u *User) Likes(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, error
// @Tags UserCenter // @Tags UserCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param contentId query string true "Content ID" // @Param contentId query int64 true "Content ID"
// @Success 200 {string} string "Liked" // @Success 200 {string} string "Liked"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind contentId query // @Bind contentId query
func (u *User) AddLike(ctx fiber.Ctx, user *models.User, contentId string) error { func (u *User) AddLike(ctx fiber.Ctx, user *models.User, contentId int64) error {
return services.Content.AddLike(ctx, user.ID, contentId) return services.Content.AddLike(ctx, user.ID, contentId)
} }
// Unlike content // Unlike content
// //
// @Router /v1/me/likes/:contentId [delete] // @Router /v1/me/likes/:contentId<int> [delete]
// @Summary Unlike content // @Summary Unlike content
// @Description Unlike content // @Description Unlike content
// @Tags UserCenter // @Tags UserCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param contentId path string true "Content ID" // @Param contentId path int64 true "Content ID"
// @Success 200 {string} string "Unliked" // @Success 200 {string} string "Unliked"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind contentId path // @Bind contentId path
func (u *User) RemoveLike(ctx fiber.Ctx, user *models.User, contentId string) error { func (u *User) RemoveLike(ctx fiber.Ctx, user *models.User, contentId int64) error {
return services.Content.RemoveLike(ctx, user.ID, contentId) return services.Content.RemoveLike(ctx, user.ID, contentId)
} }
@@ -262,16 +262,16 @@ func (u *User) Notifications(ctx fiber.Ctx, user *models.User, typeArg string, p
// Mark notification as read // Mark notification as read
// //
// @Router /v1/me/notifications/:id/read [post] // @Router /v1/me/notifications/:id<int>/read [post]
// @Summary Mark as read // @Summary Mark as read
// @Tags UserCenter // @Tags UserCenter
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param id path string true "Notification ID" // @Param id path int64 true "Notification ID"
// @Success 200 {string} string "OK" // @Success 200 {string} string "OK"
// @Bind user local key(__ctx_user) // @Bind user local key(__ctx_user)
// @Bind id path // @Bind id path
func (u *User) MarkNotificationRead(ctx fiber.Ctx, user *models.User, id string) error { func (u *User) MarkNotificationRead(ctx fiber.Ctx, user *models.User, id int64) error {
return services.Notification.MarkRead(ctx, user.ID, id) return services.Notification.MarkRead(ctx, user.ID, id)
} }

View File

@@ -3,17 +3,13 @@ package services
import ( import (
"context" "context"
"quyun/v2/pkg/consts"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/spf13/cast"
) )
// @provider // @provider
type audit struct{} type audit struct{}
func (s *audit) Log(ctx context.Context, action, targetID, detail string) { func (s *audit) Log(ctx context.Context, operatorID int64, action, targetID, detail string) {
operatorID := cast.ToInt64(ctx.Value(consts.CtxKeyUser))
logrus.WithFields(logrus.Fields{ logrus.WithFields(logrus.Fields{
"audit": true, "audit": true,
"operator": operatorID, "operator": operatorID,

View File

@@ -22,7 +22,6 @@ import (
"quyun/v2/providers/storage" "quyun/v2/providers/storage"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/spf13/cast"
"go.ipao.vip/gen/types" "go.ipao.vip/gen/types"
) )
@@ -261,17 +260,16 @@ func (s *common) CompleteUpload(ctx context.Context, userID int64, form *common_
return s.composeUploadResult(asset), nil return s.composeUploadResult(asset), nil
} }
func (s *common) DeleteMediaAsset(ctx context.Context, userID int64, id string) error { func (s *common) DeleteMediaAsset(ctx context.Context, userID int64, id int64) error {
aid := cast.ToInt64(id)
asset, err := models.MediaAssetQuery.WithContext(ctx). asset, err := models.MediaAssetQuery.WithContext(ctx).
Where(models.MediaAssetQuery.ID.Eq(aid), models.MediaAssetQuery.UserID.Eq(userID)). Where(models.MediaAssetQuery.ID.Eq(id), models.MediaAssetQuery.UserID.Eq(userID)).
First() First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
} }
// Delete DB record // Delete DB record
if _, err := models.MediaAssetQuery.WithContext(ctx).Where(models.MediaAssetQuery.ID.Eq(aid)).Delete(); err != nil { if _, err := models.MediaAssetQuery.WithContext(ctx).Where(models.MediaAssetQuery.ID.Eq(id)).Delete(); err != nil {
return errorx.ErrDatabaseError.WithCause(err) return errorx.ErrDatabaseError.WithCause(err)
} }
@@ -411,7 +409,7 @@ func (s *common) composeUploadResult(asset *models.MediaAsset) *common_dto.Uploa
size := asset.Meta.Data().Size size := asset.Meta.Data().Size
return &common_dto.UploadResult{ return &common_dto.UploadResult{
ID: cast.ToString(asset.ID), ID: asset.ID,
URL: url, URL: url,
Filename: filename, Filename: filename,
Size: size, Size: size,

View File

@@ -11,7 +11,6 @@ import (
"quyun/v2/database/models" "quyun/v2/database/models"
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
"github.com/spf13/cast"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -30,9 +29,8 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
if filter.Genre != nil && *filter.Genre != "" { if filter.Genre != nil && *filter.Genre != "" {
q = q.Where(tbl.Genre.Eq(*filter.Genre)) q = q.Where(tbl.Genre.Eq(*filter.Genre))
} }
if filter.TenantID != nil && *filter.TenantID != "" { if filter.TenantID != nil && *filter.TenantID > 0 {
tid := cast.ToInt64(*filter.TenantID) q = q.Where(tbl.TenantID.Eq(*filter.TenantID))
q = q.Where(tbl.TenantID.Eq(tid))
} }
if filter.IsPinned != nil { if filter.IsPinned != nil {
q = q.Where(tbl.IsPinned.Is(*filter.IsPinned)) q = q.Where(tbl.IsPinned.Is(*filter.IsPinned))
@@ -129,12 +127,11 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
}, nil }, nil
} }
func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dto.ContentDetail, error) { func (s *content) Get(ctx context.Context, userID int64, id int64) (*content_dto.ContentDetail, error) {
cid := cast.ToInt64(id)
// Increment Views // Increment Views
_, _ = models.ContentQuery.WithContext(ctx). _, _ = models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.ID.Eq(cid)). Where(models.ContentQuery.ID.Eq(id)).
UpdateSimple(models.ContentQuery.Views.Add(1)) UpdateSimple(models.ContentQuery.Views.Add(1))
_, q := models.ContentQuery.QueryContext(ctx) _, q := models.ContentQuery.QueryContext(ctx)
@@ -146,7 +143,7 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
return db.Order("sort ASC") return db.Order("sort ASC")
}). }).
Preload("ContentAssets.Asset"). Preload("ContentAssets.Asset").
Where("id = ?", cid). Where("id = ?", id).
First(&item).Error First(&item).Error
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
@@ -157,7 +154,7 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
// Fetch Price // Fetch Price
var price float64 var price float64
cp, err := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.Eq(cid)).First() cp, err := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.Eq(id)).First()
if err == nil { if err == nil {
price = float64(cp.PriceAmount) / 100.0 price = float64(cp.PriceAmount) / 100.0
} }
@@ -172,12 +169,12 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
// Interaction // Interaction
isLiked, _ = models.UserContentActionQuery.WithContext(ctx). isLiked, _ = models.UserContentActionQuery.WithContext(ctx).
Where(models.UserContentActionQuery.UserID.Eq(uid), Where(models.UserContentActionQuery.UserID.Eq(uid),
models.UserContentActionQuery.ContentID.Eq(cid), models.UserContentActionQuery.ContentID.Eq(id),
models.UserContentActionQuery.Type.Eq("like")). models.UserContentActionQuery.Type.Eq("like")).
Exists() Exists()
isFavorited, _ = models.UserContentActionQuery.WithContext(ctx). isFavorited, _ = models.UserContentActionQuery.WithContext(ctx).
Where(models.UserContentActionQuery.UserID.Eq(uid), Where(models.UserContentActionQuery.UserID.Eq(uid),
models.UserContentActionQuery.ContentID.Eq(cid), models.UserContentActionQuery.ContentID.Eq(id),
models.UserContentActionQuery.Type.Eq("favorite")). models.UserContentActionQuery.Type.Eq("favorite")).
Exists() Exists()
@@ -188,7 +185,7 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
// Check Purchase // Check Purchase
exists, _ := models.ContentAccessQuery.WithContext(ctx). exists, _ := models.ContentAccessQuery.WithContext(ctx).
Where(models.ContentAccessQuery.UserID.Eq(uid), Where(models.ContentAccessQuery.UserID.Eq(uid),
models.ContentAccessQuery.ContentID.Eq(cid), models.ContentAccessQuery.ContentID.Eq(id),
models.ContentAccessQuery.Status.Eq(consts.ContentAccessStatusActive)). models.ContentAccessQuery.Status.Eq(consts.ContentAccessStatusActive)).
Exists() Exists()
if exists { if exists {
@@ -235,11 +232,10 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
return detail, nil return detail, nil
} }
func (s *content) ListComments(ctx context.Context, userID int64, id string, page int) (*requests.Pager, error) { func (s *content) ListComments(ctx context.Context, userID int64, id int64, page int) (*requests.Pager, error) {
cid := cast.ToInt64(id)
tbl, q := models.CommentQuery.QueryContext(ctx) tbl, q := models.CommentQuery.QueryContext(ctx)
q = q.Where(tbl.ContentID.Eq(cid)).Preload(tbl.User) q = q.Where(tbl.ContentID.Eq(id)).Preload(tbl.User)
q = q.Order(tbl.CreatedAt.Desc()) q = q.Order(tbl.CreatedAt.Desc())
p := requests.Pagination{Page: int64(page), Limit: 10} p := requests.Pagination{Page: int64(page), Limit: 10}
@@ -274,14 +270,14 @@ func (s *content) ListComments(ctx context.Context, userID int64, id string, pag
data := make([]content_dto.Comment, len(list)) data := make([]content_dto.Comment, len(list))
for i, v := range list { for i, v := range list {
data[i] = content_dto.Comment{ data[i] = content_dto.Comment{
ID: cast.ToString(v.ID), ID: v.ID,
Content: v.Content, Content: v.Content,
UserID: cast.ToString(v.UserID), UserID: v.UserID,
UserNickname: v.User.Nickname, UserNickname: v.User.Nickname,
UserAvatar: v.User.Avatar, UserAvatar: v.User.Avatar,
CreateTime: v.CreatedAt.Format("2006-01-02 15:04:05"), CreateTime: v.CreatedAt.Format("2006-01-02 15:04:05"),
Likes: int(v.Likes), Likes: int(v.Likes),
ReplyTo: cast.ToString(v.ReplyTo), ReplyTo: v.ReplyTo,
IsLiked: likedMap[v.ID], IsLiked: likedMap[v.ID],
} }
} }
@@ -296,16 +292,15 @@ func (s *content) ListComments(ctx context.Context, userID int64, id string, pag
func (s *content) CreateComment( func (s *content) CreateComment(
ctx context.Context, ctx context.Context,
userID int64, userID int64,
id string, id int64,
form *content_dto.CommentCreateForm, form *content_dto.CommentCreateForm,
) error { ) error {
if userID == 0 { if userID == 0 {
return errorx.ErrUnauthorized return errorx.ErrUnauthorized
} }
uid := userID uid := userID
cid := cast.ToInt64(id)
c, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid)).First() c, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(id)).First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
} }
@@ -313,9 +308,9 @@ func (s *content) CreateComment(
comment := &models.Comment{ comment := &models.Comment{
TenantID: c.TenantID, TenantID: c.TenantID,
UserID: uid, UserID: uid,
ContentID: cid, ContentID: id,
Content: form.Content, Content: form.Content,
ReplyTo: cast.ToInt64(form.ReplyTo), ReplyTo: form.ReplyTo,
} }
if err := models.CommentQuery.WithContext(ctx).Create(comment); err != nil { if err := models.CommentQuery.WithContext(ctx).Create(comment); err != nil {
@@ -324,33 +319,32 @@ func (s *content) CreateComment(
return nil return nil
} }
func (s *content) LikeComment(ctx context.Context, userID int64, id string) error { func (s *content) LikeComment(ctx context.Context, userID int64, id int64) error {
if userID == 0 { if userID == 0 {
return errorx.ErrUnauthorized return errorx.ErrUnauthorized
} }
uid := userID uid := userID
cmid := cast.ToInt64(id)
// Fetch comment for author // Fetch comment for author
cm, err := models.CommentQuery.WithContext(ctx).Where(models.CommentQuery.ID.Eq(cmid)).First() cm, err := models.CommentQuery.WithContext(ctx).Where(models.CommentQuery.ID.Eq(id)).First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
} }
err = models.Q.Transaction(func(tx *models.Query) error { err = models.Q.Transaction(func(tx *models.Query) error {
exists, _ := tx.UserCommentAction.WithContext(ctx). exists, _ := tx.UserCommentAction.WithContext(ctx).
Where(tx.UserCommentAction.UserID.Eq(uid), tx.UserCommentAction.CommentID.Eq(cmid), tx.UserCommentAction.Type.Eq("like")). Where(tx.UserCommentAction.UserID.Eq(uid), tx.UserCommentAction.CommentID.Eq(id), tx.UserCommentAction.Type.Eq("like")).
Exists() Exists()
if exists { if exists {
return nil return nil
} }
action := &models.UserCommentAction{UserID: uid, CommentID: cmid, Type: "like"} action := &models.UserCommentAction{UserID: uid, CommentID: id, Type: "like"}
if err := tx.UserCommentAction.WithContext(ctx).Create(action); err != nil { if err := tx.UserCommentAction.WithContext(ctx).Create(action); err != nil {
return err return err
} }
_, err := tx.Comment.WithContext(ctx).Where(tx.Comment.ID.Eq(cmid)).UpdateSimple(tx.Comment.Likes.Add(1)) _, err := tx.Comment.WithContext(ctx).Where(tx.Comment.ID.Eq(id)).UpdateSimple(tx.Comment.Likes.Add(1))
return err return err
}) })
if err != nil { if err != nil {
@@ -408,11 +402,11 @@ func (s *content) GetFavorites(ctx context.Context, userID int64) ([]user_dto.Co
return s.getInteractList(ctx, userID, "favorite") return s.getInteractList(ctx, userID, "favorite")
} }
func (s *content) AddFavorite(ctx context.Context, userID int64, contentId string) error { func (s *content) AddFavorite(ctx context.Context, userID int64, contentId int64) error {
return s.addInteract(ctx, userID, contentId, "favorite") return s.addInteract(ctx, userID, contentId, "favorite")
} }
func (s *content) RemoveFavorite(ctx context.Context, userID int64, contentId string) error { func (s *content) RemoveFavorite(ctx context.Context, userID int64, contentId int64) error {
return s.removeInteract(ctx, userID, contentId, "favorite") return s.removeInteract(ctx, userID, contentId, "favorite")
} }
@@ -420,11 +414,11 @@ func (s *content) GetLikes(ctx context.Context, userID int64) ([]user_dto.Conten
return s.getInteractList(ctx, userID, "like") return s.getInteractList(ctx, userID, "like")
} }
func (s *content) AddLike(ctx context.Context, userID int64, contentId string) error { func (s *content) AddLike(ctx context.Context, userID int64, contentId int64) error {
return s.addInteract(ctx, userID, contentId, "like") return s.addInteract(ctx, userID, contentId, "like")
} }
func (s *content) RemoveLike(ctx context.Context, userID int64, contentId string) error { func (s *content) RemoveLike(ctx context.Context, userID int64, contentId int64) error {
return s.removeInteract(ctx, userID, contentId, "like") return s.removeInteract(ctx, userID, contentId, "like")
} }
@@ -470,7 +464,7 @@ func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) {
} }
topics = append(topics, content_dto.Topic{ topics = append(topics, content_dto.Topic{
ID: cast.ToString(i + 1), // Use index as ID for aggregation results ID: int64(i + 1), // Use index as ID for aggregation results
Title: r.Genre, Title: r.Genre,
Tag: r.Genre, Tag: r.Genre,
Count: r.Count, Count: r.Count,
@@ -484,10 +478,10 @@ func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) {
func (s *content) toContentItemDTO(item *models.Content, price float64, authorIsFollowing bool) content_dto.ContentItem { func (s *content) toContentItemDTO(item *models.Content, price float64, authorIsFollowing bool) content_dto.ContentItem {
dto := content_dto.ContentItem{ dto := content_dto.ContentItem{
ID: cast.ToString(item.ID), ID: item.ID,
Title: item.Title, Title: item.Title,
Genre: item.Genre, Genre: item.Genre,
AuthorID: cast.ToString(item.UserID), AuthorID: item.UserID,
Views: int(item.Views), Views: int(item.Views),
Likes: int(item.Likes), Likes: int(item.Likes),
CreatedAt: item.CreatedAt.Format("2006-01-02"), CreatedAt: item.CreatedAt.Format("2006-01-02"),
@@ -553,16 +547,15 @@ func (s *content) toMediaURLs(assets []*models.ContentAsset) []content_dto.Media
return urls return urls
} }
func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ string) error { func (s *content) addInteract(ctx context.Context, userID int64, contentId int64, typ string) error {
if userID == 0 { if userID == 0 {
return errorx.ErrUnauthorized return errorx.ErrUnauthorized
} }
uid := userID uid := userID
cid := cast.ToInt64(contentId)
// Fetch content for author // Fetch content for author
c, err := models.ContentQuery.WithContext(ctx). c, err := models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.ID.Eq(cid)). Where(models.ContentQuery.ID.Eq(contentId)).
Select(models.ContentQuery.UserID, models.ContentQuery.Title). Select(models.ContentQuery.UserID, models.ContentQuery.Title).
First() First()
if err != nil { if err != nil {
@@ -571,19 +564,19 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ
err = models.Q.Transaction(func(tx *models.Query) error { err = models.Q.Transaction(func(tx *models.Query) error {
exists, _ := tx.UserContentAction.WithContext(ctx). exists, _ := tx.UserContentAction.WithContext(ctx).
Where(tx.UserContentAction.UserID.Eq(uid), tx.UserContentAction.ContentID.Eq(cid), tx.UserContentAction.Type.Eq(typ)). Where(tx.UserContentAction.UserID.Eq(uid), tx.UserContentAction.ContentID.Eq(contentId), tx.UserContentAction.Type.Eq(typ)).
Exists() Exists()
if exists { if exists {
return nil return nil
} }
action := &models.UserContentAction{UserID: uid, ContentID: cid, Type: typ} action := &models.UserContentAction{UserID: uid, ContentID: contentId, Type: typ}
if err := tx.UserContentAction.WithContext(ctx).Create(action); err != nil { if err := tx.UserContentAction.WithContext(ctx).Create(action); err != nil {
return err return err
} }
if typ == "like" { if typ == "like" {
_, err := tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.Likes.Add(1)) _, err := tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(contentId)).UpdateSimple(tx.Content.Likes.Add(1))
return err return err
} }
return nil return nil
@@ -605,16 +598,15 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ
return nil return nil
} }
func (s *content) removeInteract(ctx context.Context, userID int64, contentId, typ string) error { func (s *content) removeInteract(ctx context.Context, userID int64, contentId int64, typ string) error {
if userID == 0 { if userID == 0 {
return errorx.ErrUnauthorized return errorx.ErrUnauthorized
} }
uid := userID uid := userID
cid := cast.ToInt64(contentId)
return models.Q.Transaction(func(tx *models.Query) error { return models.Q.Transaction(func(tx *models.Query) error {
res, err := tx.UserContentAction.WithContext(ctx). res, err := tx.UserContentAction.WithContext(ctx).
Where(tx.UserContentAction.UserID.Eq(uid), tx.UserContentAction.ContentID.Eq(cid), tx.UserContentAction.Type.Eq(typ)). Where(tx.UserContentAction.UserID.Eq(uid), tx.UserContentAction.ContentID.Eq(contentId), tx.UserContentAction.Type.Eq(typ)).
Delete() Delete()
if err != nil { if err != nil {
return err return err
@@ -624,7 +616,7 @@ func (s *content) removeInteract(ctx context.Context, userID int64, contentId, t
} }
if typ == "like" { if typ == "like" {
_, err := tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.Likes.Sub(1)) _, err := tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(contentId)).UpdateSimple(tx.Content.Likes.Sub(1))
return err return err
} }
return nil return nil

View File

@@ -13,7 +13,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -126,7 +125,7 @@ func (s *ContentTestSuite) Test_Get() {
ctx = context.WithValue(ctx, consts.CtxKeyUser, author.ID) ctx = context.WithValue(ctx, consts.CtxKeyUser, author.ID)
Convey("should get detail with assets", func() { Convey("should get detail with assets", func() {
detail, err := Content.Get(ctx, author.ID, cast.ToString(content.ID)) detail, err := Content.Get(ctx, author.ID, content.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(detail.Title, ShouldEqual, "Detail Content") So(detail.Title, ShouldEqual, "Detail Content")
So(detail.AuthorName, ShouldEqual, "Author1") So(detail.AuthorName, ShouldEqual, "Author1")
@@ -154,7 +153,7 @@ func (s *ContentTestSuite) Test_CreateComment() {
form := &content_dto.CommentCreateForm{ form := &content_dto.CommentCreateForm{
Content: "Nice!", Content: "Nice!",
} }
err := Content.CreateComment(ctx, u.ID, cast.ToString(c.ID), form) err := Content.CreateComment(ctx, u.ID, c.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
count, _ := models.CommentQuery.WithContext(ctx).Where(models.CommentQuery.ContentID.Eq(c.ID)).Count() count, _ := models.CommentQuery.WithContext(ctx).Where(models.CommentQuery.ContentID.Eq(c.ID)).Count()
@@ -219,7 +218,7 @@ func (s *ContentTestSuite) Test_Interact() {
Convey("Like flow", func() { Convey("Like flow", func() {
// Add Like // Add Like
err := Content.AddLike(ctx, u.ID, cast.ToString(c.ID)) err := Content.AddLike(ctx, u.ID, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify count // Verify count
@@ -230,10 +229,10 @@ func (s *ContentTestSuite) Test_Interact() {
likes, err := Content.GetLikes(ctx, u.ID) likes, err := Content.GetLikes(ctx, u.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(likes), ShouldEqual, 1) So(len(likes), ShouldEqual, 1)
So(likes[0].ID, ShouldEqual, cast.ToString(c.ID)) So(likes[0].ID, ShouldEqual, c.ID)
// Remove Like // Remove Like
err = Content.RemoveLike(ctx, u.ID, cast.ToString(c.ID)) err = Content.RemoveLike(ctx, u.ID, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify count // Verify count
@@ -243,17 +242,17 @@ func (s *ContentTestSuite) Test_Interact() {
Convey("Favorite flow", func() { Convey("Favorite flow", func() {
// Add Favorite // Add Favorite
err := Content.AddFavorite(ctx, u.ID, cast.ToString(c.ID)) err := Content.AddFavorite(ctx, u.ID, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Get Favorites // Get Favorites
favs, err := Content.GetFavorites(ctx, u.ID) favs, err := Content.GetFavorites(ctx, u.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(favs), ShouldEqual, 1) So(len(favs), ShouldEqual, 1)
So(favs[0].ID, ShouldEqual, cast.ToString(c.ID)) So(favs[0].ID, ShouldEqual, c.ID)
// Remove Favorite // Remove Favorite
err = Content.RemoveFavorite(ctx, u.ID, cast.ToString(c.ID)) err = Content.RemoveFavorite(ctx, u.ID, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Get Favorites // Get Favorites
@@ -325,7 +324,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
models.UserQuery.WithContext(ctx).Create(guest) models.UserQuery.WithContext(ctx).Create(guest)
guestCtx := context.WithValue(ctx, consts.CtxKeyUser, guest.ID) guestCtx := context.WithValue(ctx, consts.CtxKeyUser, guest.ID)
detail, err := Content.Get(guestCtx, 0, cast.ToString(c.ID)) detail, err := Content.Get(guestCtx, 0, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(detail.MediaUrls), ShouldEqual, 1) So(len(detail.MediaUrls), ShouldEqual, 1)
So(detail.MediaUrls[0].URL, ShouldEndWith, "preview.mp4") So(detail.MediaUrls[0].URL, ShouldEndWith, "preview.mp4")
@@ -334,7 +333,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
Convey("owner should see all", func() { Convey("owner should see all", func() {
ownerCtx := context.WithValue(ctx, consts.CtxKeyUser, author.ID) ownerCtx := context.WithValue(ctx, consts.CtxKeyUser, author.ID)
detail, err := Content.Get(ownerCtx, author.ID, cast.ToString(c.ID)) detail, err := Content.Get(ownerCtx, author.ID, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(detail.MediaUrls), ShouldEqual, 2) So(len(detail.MediaUrls), ShouldEqual, 2)
So(detail.IsPurchased, ShouldBeTrue) So(detail.IsPurchased, ShouldBeTrue)
@@ -349,7 +348,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
UserID: buyer.ID, ContentID: c.ID, Status: consts.ContentAccessStatusActive, UserID: buyer.ID, ContentID: c.ID, Status: consts.ContentAccessStatusActive,
}) })
detail, err := Content.Get(buyerCtx, buyer.ID, cast.ToString(c.ID)) detail, err := Content.Get(buyerCtx, buyer.ID, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(len(detail.MediaUrls), ShouldEqual, 2) So(len(detail.MediaUrls), ShouldEqual, 2)
So(detail.IsPurchased, ShouldBeTrue) So(detail.IsPurchased, ShouldBeTrue)
@@ -369,7 +368,7 @@ func (s *ContentTestSuite) Test_ViewCounting() {
models.ContentQuery.WithContext(ctx).Create(c) models.ContentQuery.WithContext(ctx).Create(c)
Convey("should increment views", func() { Convey("should increment views", func() {
_, err := Content.Get(ctx, 0, cast.ToString(c.ID)) _, err := Content.Get(ctx, 0, c.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
cReload, _ := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(c.ID)).First() cReload, _ := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(c.ID)).First()

View File

@@ -7,8 +7,6 @@ import (
"quyun/v2/app/errorx" "quyun/v2/app/errorx"
coupon_dto "quyun/v2/app/http/v1/dto" coupon_dto "quyun/v2/app/http/v1/dto"
"quyun/v2/database/models" "quyun/v2/database/models"
"github.com/spf13/cast"
) )
// @provider // @provider
@@ -40,8 +38,8 @@ func (s *coupon) ListUserCoupons(
c, _ := models.CouponQuery.WithContext(ctx).Where(models.CouponQuery.ID.Eq(v.CouponID)).First() c, _ := models.CouponQuery.WithContext(ctx).Where(models.CouponQuery.ID.Eq(v.CouponID)).First()
item := coupon_dto.UserCouponItem{ item := coupon_dto.UserCouponItem{
ID: cast.ToString(v.ID), ID: v.ID,
CouponID: cast.ToString(v.CouponID), CouponID: v.CouponID,
Status: v.Status, Status: v.Status,
} }
if c != nil { if c != nil {

View File

@@ -12,7 +12,6 @@ import (
"quyun/v2/providers/storage" "quyun/v2/providers/storage"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -94,15 +93,15 @@ func (s *CouponTestSuite) Test_CouponFlow() {
}) })
form := &order_dto.OrderCreateForm{ form := &order_dto.OrderCreateForm{
ContentID: cast.ToString(c.ID), ContentID: c.ID,
UserCouponID: cast.ToString(uc.ID), UserCouponID: uc.ID,
} }
// Simulate Auth context for Order service // Simulate Auth context for Order service
res, err := Order.Create(ctx, user.ID, form) res, err := Order.Create(ctx, user.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify Order // Verify Order
oid := cast.ToInt64(res.OrderID) oid := res.OrderID
o, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First() o, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
So(o.AmountOriginal, ShouldEqual, 2000) So(o.AmountOriginal, ShouldEqual, 2000)
So(o.AmountDiscount, ShouldEqual, 500) So(o.AmountDiscount, ShouldEqual, 500)

View File

@@ -3,7 +3,7 @@ package services
import ( import (
"context" "context"
"errors" "errors"
"fmt" "strconv"
"time" "time"
"quyun/v2/app/errorx" "quyun/v2/app/errorx"
@@ -14,7 +14,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/spf13/cast"
"go.ipao.vip/gen/types" "go.ipao.vip/gen/types"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -125,9 +124,6 @@ func (s *creator) ListContents(
if filter.Visibility != nil && *filter.Visibility != "" { if filter.Visibility != nil && *filter.Visibility != "" {
q = q.Where(tbl.Visibility.Eq(consts.ContentVisibility(*filter.Visibility))) q = q.Where(tbl.Visibility.Eq(consts.ContentVisibility(*filter.Visibility)))
} }
if filter.Visibility != nil && *filter.Visibility != "" {
q = q.Where(tbl.Visibility.Eq(consts.ContentVisibility(*filter.Visibility)))
}
if filter.Genre != nil && *filter.Genre != "" { if filter.Genre != nil && *filter.Genre != "" {
val := *filter.Genre val := *filter.Genre
if cn, ok := genreMap[val]; ok { if cn, ok := genreMap[val]; ok {
@@ -137,7 +133,6 @@ func (s *creator) ListContents(
} }
} }
if filter.Key != nil && *filter.Key != "" { if filter.Key != nil && *filter.Key != "" {
fmt.Printf("DEBUG: Filter Key: '%s'\n", *filter.Key)
q = q.Where(tbl.Key.Eq(*filter.Key)) q = q.Where(tbl.Key.Eq(*filter.Key))
} }
if filter.Keyword != nil && *filter.Keyword != "" { if filter.Keyword != nil && *filter.Keyword != "" {
@@ -227,7 +222,7 @@ func (s *creator) ListContents(
} }
data = append(data, creator_dto.CreatorContentItem{ data = append(data, creator_dto.CreatorContentItem{
ID: cast.ToString(item.ID), ID: item.ID,
Title: item.Title, Title: item.Title,
Genre: item.Genre, Genre: item.Genre,
Key: item.Key, Key: item.Key,
@@ -286,7 +281,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
TenantID: tid, TenantID: tid,
UserID: uid, UserID: uid,
ContentID: content.ID, ContentID: content.ID,
AssetID: cast.ToInt64(mid), AssetID: mid,
Sort: int32(i), Sort: int32(i),
Role: consts.ContentAssetRoleCover, Role: consts.ContentAssetRoleCover,
}) })
@@ -297,7 +292,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
TenantID: tid, TenantID: tid,
UserID: uid, UserID: uid,
ContentID: content.ID, ContentID: content.ID,
AssetID: cast.ToInt64(mid), AssetID: mid,
Sort: int32(i), Sort: int32(i),
Role: consts.ContentAssetRoleMain, Role: consts.ContentAssetRoleMain,
}) })
@@ -327,19 +322,18 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
func (s *creator) UpdateContent( func (s *creator) UpdateContent(
ctx context.Context, ctx context.Context,
userID int64, userID int64,
id string, id int64,
form *creator_dto.ContentUpdateForm, form *creator_dto.ContentUpdateForm,
) error { ) error {
tid, err := s.getTenantID(ctx, userID) tid, err := s.getTenantID(ctx, userID)
if err != nil { if err != nil {
return err return err
} }
cid := cast.ToInt64(id)
uid := userID uid := userID
return models.Q.Transaction(func(tx *models.Query) error { return models.Q.Transaction(func(tx *models.Query) error {
// 1. Check Ownership // 1. Check Ownership
c, err := tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid), tx.Content.TenantID.Eq(tid)).First() c, err := tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(id), tx.Content.TenantID.Eq(tid)).First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
} }
@@ -366,7 +360,7 @@ func (s *creator) UpdateContent(
} }
// Perform standard updates // Perform standard updates
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).Updates(contentUpdates) _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(id)).Updates(contentUpdates)
if err != nil { if err != nil {
return err return err
} }
@@ -374,13 +368,13 @@ func (s *creator) UpdateContent(
// Handle IsPinned Logic // Handle IsPinned Logic
if finalStatus != consts.ContentStatusPublished { if finalStatus != consts.ContentStatusPublished {
// Force Unpin if not published // Force Unpin if not published
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(false)) _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(id)).UpdateSimple(tx.Content.IsPinned.Value(false))
if err != nil { if err != nil {
return err return err
} }
} else if form.IsPinned != nil { } else if form.IsPinned != nil {
// Explicit Pin Update requested // Explicit Pin Update requested
_, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(cid)).UpdateSimple(tx.Content.IsPinned.Value(*form.IsPinned)) _, err = tx.Content.WithContext(ctx).Where(tx.Content.ID.Eq(id)).UpdateSimple(tx.Content.IsPinned.Value(*form.IsPinned))
if err != nil { if err != nil {
return err return err
} }
@@ -388,7 +382,7 @@ func (s *creator) UpdateContent(
// If setting to true, unpin others // If setting to true, unpin others
if *form.IsPinned { if *form.IsPinned {
if _, err := tx.Content.WithContext(ctx). if _, err := tx.Content.WithContext(ctx).
Where(tx.Content.TenantID.Eq(tid), tx.Content.ID.Neq(cid)). Where(tx.Content.TenantID.Eq(tid), tx.Content.ID.Neq(id)).
UpdateSimple(tx.Content.IsPinned.Value(false)); err != nil { UpdateSimple(tx.Content.IsPinned.Value(false)); err != nil {
return err return err
} }
@@ -398,17 +392,17 @@ func (s *creator) UpdateContent(
// 3. Update Price // 3. Update Price
// Check if price exists // Check if price exists
if form.Price != nil { if form.Price != nil {
count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(cid)).Count() count, _ := tx.ContentPrice.WithContext(ctx).Where(tx.ContentPrice.ContentID.Eq(id)).Count()
newPrice := int64(*form.Price * 100) newPrice := int64(*form.Price * 100)
if count > 0 { if count > 0 {
_, err = tx.ContentPrice.WithContext(ctx). _, err = tx.ContentPrice.WithContext(ctx).
Where(tx.ContentPrice.ContentID.Eq(cid)). Where(tx.ContentPrice.ContentID.Eq(id)).
UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice)) UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice))
} else { } else {
err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{ err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{
TenantID: tid, TenantID: tid,
UserID: c.UserID, UserID: c.UserID,
ContentID: cid, ContentID: id,
PriceAmount: newPrice, PriceAmount: newPrice,
Currency: consts.CurrencyCNY, Currency: consts.CurrencyCNY,
}) })
@@ -419,7 +413,7 @@ func (s *creator) UpdateContent(
} }
// 4. Update Assets (Full replacement strategy) // 4. Update Assets (Full replacement strategy)
_, err = tx.ContentAsset.WithContext(ctx).Where(tx.ContentAsset.ContentID.Eq(cid)).Delete() _, err = tx.ContentAsset.WithContext(ctx).Where(tx.ContentAsset.ContentID.Eq(id)).Delete()
if err != nil { if err != nil {
return err return err
} }
@@ -430,8 +424,8 @@ func (s *creator) UpdateContent(
assets = append(assets, &models.ContentAsset{ assets = append(assets, &models.ContentAsset{
TenantID: tid, TenantID: tid,
UserID: uid, UserID: uid,
ContentID: cid, ContentID: id,
AssetID: cast.ToInt64(mid), AssetID: mid,
Sort: int32(i), Sort: int32(i),
Role: consts.ContentAssetRoleCover, Role: consts.ContentAssetRoleCover,
}) })
@@ -441,8 +435,8 @@ func (s *creator) UpdateContent(
assets = append(assets, &models.ContentAsset{ assets = append(assets, &models.ContentAsset{
TenantID: tid, TenantID: tid,
UserID: uid, UserID: uid,
ContentID: cid, ContentID: id,
AssetID: cast.ToInt64(mid), AssetID: mid,
Sort: int32(i), Sort: int32(i),
Role: consts.ContentAssetRoleMain, Role: consts.ContentAssetRoleMain,
}) })
@@ -457,21 +451,20 @@ func (s *creator) UpdateContent(
}) })
} }
func (s *creator) DeleteContent(ctx context.Context, userID int64, id string) error { func (s *creator) DeleteContent(ctx context.Context, userID int64, id int64) error {
cid := cast.ToInt64(id)
tid, err := s.getTenantID(ctx, userID) tid, err := s.getTenantID(ctx, userID)
if err != nil { if err != nil {
return err return err
} }
// Check if purchased (ContentAccess exists) // Check if purchased (ContentAccess exists)
count, _ := models.ContentAccessQuery.WithContext(ctx).Where(models.ContentAccessQuery.ContentID.Eq(cid)).Count() count, _ := models.ContentAccessQuery.WithContext(ctx).Where(models.ContentAccessQuery.ContentID.Eq(id)).Count()
if count > 0 { if count > 0 {
return errorx.ErrPreconditionFailed.WithMsg("该内容已被购买,无法删除") return errorx.ErrPreconditionFailed.WithMsg("该内容已被购买,无法删除")
} }
_, err = models.ContentQuery.WithContext(ctx). _, err = models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.ID.Eq(cid), models.ContentQuery.TenantID.Eq(tid)). Where(models.ContentQuery.ID.Eq(id), models.ContentQuery.TenantID.Eq(tid)).
Delete() Delete()
if err != nil { if err != nil {
return errorx.ErrDatabaseError.WithCause(err) return errorx.ErrDatabaseError.WithCause(err)
@@ -479,17 +472,16 @@ func (s *creator) DeleteContent(ctx context.Context, userID int64, id string) er
return nil return nil
} }
func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*creator_dto.ContentEditDTO, error) { func (s *creator) GetContent(ctx context.Context, userID int64, id int64) (*creator_dto.ContentEditDTO, error) {
tid, err := s.getTenantID(ctx, userID) tid, err := s.getTenantID(ctx, userID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
cid := cast.ToInt64(id)
// Fetch Content with preloads // Fetch Content with preloads
var c models.Content var c models.Content
err = models.ContentQuery.WithContext(ctx). err = models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.ID.Eq(cid), models.ContentQuery.TenantID.Eq(tid)). Where(models.ContentQuery.ID.Eq(id), models.ContentQuery.TenantID.Eq(tid)).
UnderlyingDB(). UnderlyingDB().
Preload("ContentAssets", func(db *gorm.DB) *gorm.DB { Preload("ContentAssets", func(db *gorm.DB) *gorm.DB {
return db.Order("sort ASC") return db.Order("sort ASC")
@@ -505,13 +497,13 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre
// Fetch Price // Fetch Price
var price float64 var price float64
cp, err := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.Eq(cid)).First() cp, err := models.ContentPriceQuery.WithContext(ctx).Where(models.ContentPriceQuery.ContentID.Eq(id)).First()
if err == nil { if err == nil {
price = float64(cp.PriceAmount) / 100.0 price = float64(cp.PriceAmount) / 100.0
} }
dto := &creator_dto.ContentEditDTO{ dto := &creator_dto.ContentEditDTO{
ID: cast.ToString(c.ID), ID: c.ID,
Title: c.Title, Title: c.Title,
Genre: c.Genre, Genre: c.Genre,
Key: c.Key, Key: c.Key,
@@ -538,10 +530,10 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre
sizeBytes := meta.Size sizeBytes := meta.Size
sizeMB := float64(sizeBytes) / 1024.0 / 1024.0 sizeMB := float64(sizeBytes) / 1024.0 / 1024.0
sizeStr := cast.ToString(float64(int(sizeMB*100))/100.0) + " MB" sizeStr := strconv.FormatFloat(float64(int(sizeMB*100))/100.0, 'f', -1, 64) + " MB"
dto.Assets = append(dto.Assets, creator_dto.AssetDTO{ dto.Assets = append(dto.Assets, creator_dto.AssetDTO{
ID: cast.ToString(ca.AssetID), ID: ca.AssetID,
Role: string(ca.Role), Role: string(ca.Role),
Type: string(ca.Asset.Type), Type: string(ca.Asset.Type),
URL: Common.GetAssetURL(ca.Asset.ObjectKey), URL: Common.GetAssetURL(ca.Asset.ObjectKey),
@@ -573,7 +565,7 @@ func (s *creator) ListOrders(
if filter.Keyword != nil && *filter.Keyword != "" { if filter.Keyword != nil && *filter.Keyword != "" {
k := *filter.Keyword k := *filter.Keyword
if id, err := cast.ToInt64E(k); err == nil { if id, err := strconv.ParseInt(k, 10, 64); err == nil {
q = q.Where(tbl.ID.Eq(id)) q = q.Where(tbl.ID.Eq(id))
} else { } else {
uTbl, uQ := models.UserQuery.QueryContext(ctx) uTbl, uQ := models.UserQuery.QueryContext(ctx)
@@ -629,7 +621,7 @@ func (s *creator) ListOrders(
} }
data = append(data, creator_dto.Order{ data = append(data, creator_dto.Order{
ID: cast.ToString(o.ID), ID: o.ID,
Status: string(o.Status), Status: string(o.Status),
Amount: float64(o.AmountPaid) / 100.0, Amount: float64(o.AmountPaid) / 100.0,
CreateTime: o.CreatedAt.Format(time.RFC3339), CreateTime: o.CreatedAt.Format(time.RFC3339),
@@ -642,17 +634,16 @@ func (s *creator) ListOrders(
return data, nil return data, nil
} }
func (s *creator) ProcessRefund(ctx context.Context, userID int64, id string, form *creator_dto.RefundForm) error { func (s *creator) ProcessRefund(ctx context.Context, userID int64, id int64, form *creator_dto.RefundForm) error {
tid, err := s.getTenantID(ctx, userID) tid, err := s.getTenantID(ctx, userID)
if err != nil { if err != nil {
return err return err
} }
oid := cast.ToInt64(id)
uid := userID // Creator ID uid := userID // Creator ID
// Fetch Order // Fetch Order
o, err := models.OrderQuery.WithContext(ctx). o, err := models.OrderQuery.WithContext(ctx).
Where(models.OrderQuery.ID.Eq(oid), models.OrderQuery.TenantID.Eq(tid)). Where(models.OrderQuery.ID.Eq(id), models.OrderQuery.TenantID.Eq(tid)).
First() First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
@@ -666,7 +657,7 @@ func (s *creator) ProcessRefund(ctx context.Context, userID int64, id string, fo
} }
if form.Action == "reject" { if form.Action == "reject" {
_, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).Updates(&models.Order{ _, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(id)).Updates(&models.Order{
Status: consts.OrderStatusPaid, Status: consts.OrderStatusPaid,
RefundReason: form.Reason, // Store reject reason? Or clear it? RefundReason: form.Reason, // Store reject reason? Or clear it?
}) })
@@ -696,7 +687,7 @@ func (s *creator) ProcessRefund(ctx context.Context, userID int64, id string, fo
} }
// 3. Update Order Status // 3. Update Order Status
_, err = tx.Order.WithContext(ctx).Where(tx.Order.ID.Eq(oid)).Updates(&models.Order{ _, err = tx.Order.WithContext(ctx).Where(tx.Order.ID.Eq(id)).Updates(&models.Order{
Status: consts.OrderStatusRefunded, Status: consts.OrderStatusRefunded,
RefundedAt: time.Now(), RefundedAt: time.Now(),
RefundOperatorUserID: uid, RefundOperatorUserID: uid,
@@ -755,7 +746,7 @@ func (s *creator) GetSettings(ctx context.Context, userID int64) (*creator_dto.S
} }
cfg := t.Config.Data() cfg := t.Config.Data()
return &creator_dto.Settings{ return &creator_dto.Settings{
ID: cast.ToString(t.ID), ID: t.ID,
Name: t.Name, Name: t.Name,
Bio: cfg.Bio, Bio: cfg.Bio,
Avatar: cfg.Avatar, Avatar: cfg.Avatar,
@@ -802,7 +793,7 @@ func (s *creator) ListPayoutAccounts(ctx context.Context, userID int64) ([]creat
var data []creator_dto.PayoutAccount var data []creator_dto.PayoutAccount
for _, v := range list { for _, v := range list {
data = append(data, creator_dto.PayoutAccount{ data = append(data, creator_dto.PayoutAccount{
ID: cast.ToString(v.ID), ID: v.ID,
Type: v.Type, Type: v.Type,
Name: v.Name, Name: v.Name,
Account: v.Account, Account: v.Account,
@@ -833,15 +824,14 @@ func (s *creator) AddPayoutAccount(ctx context.Context, userID int64, form *crea
return nil return nil
} }
func (s *creator) RemovePayoutAccount(ctx context.Context, userID int64, id string) error { func (s *creator) RemovePayoutAccount(ctx context.Context, userID int64, id int64) error {
tid, err := s.getTenantID(ctx, userID) tid, err := s.getTenantID(ctx, userID)
if err != nil { if err != nil {
return err return err
} }
pid := cast.ToInt64(id)
_, err = models.PayoutAccountQuery.WithContext(ctx). _, err = models.PayoutAccountQuery.WithContext(ctx).
Where(models.PayoutAccountQuery.ID.Eq(pid), models.PayoutAccountQuery.TenantID.Eq(tid)). Where(models.PayoutAccountQuery.ID.Eq(id), models.PayoutAccountQuery.TenantID.Eq(tid)).
Delete() Delete()
if err != nil { if err != nil {
return errorx.ErrDatabaseError.WithCause(err) return errorx.ErrDatabaseError.WithCause(err)
@@ -872,7 +862,7 @@ func (s *creator) Withdraw(ctx context.Context, userID int64, form *creator_dto.
// Validate Payout Account // Validate Payout Account
_, err = models.PayoutAccountQuery.WithContext(ctx). _, err = models.PayoutAccountQuery.WithContext(ctx).
Where(models.PayoutAccountQuery.ID.Eq(cast.ToInt64(form.AccountID)), models.PayoutAccountQuery.TenantID.Eq(tid)). Where(models.PayoutAccountQuery.ID.Eq(form.AccountID), models.PayoutAccountQuery.TenantID.Eq(tid)).
First() First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound.WithMsg("收款账户不存在") return errorx.ErrRecordNotFound.WithMsg("收款账户不存在")

View File

@@ -12,7 +12,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -145,7 +144,7 @@ func (s *CreatorTestSuite) Test_UpdateContent() {
Genre: "video", Genre: "video",
Price: 20.00, Price: 20.00,
} }
err := Creator.UpdateContent(ctx, u.ID, cast.ToString(c.ID), form) err := Creator.UpdateContent(ctx, u.ID, c.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify // Verify
@@ -281,7 +280,7 @@ func (s *CreatorTestSuite) Test_Withdraw() {
Convey("should withdraw successfully", func() { Convey("should withdraw successfully", func() {
form := &creator_dto.WithdrawForm{ form := &creator_dto.WithdrawForm{
Amount: 20.00, Amount: 20.00,
AccountID: cast.ToString(pa.ID), AccountID: pa.ID,
} }
err := Creator.Withdraw(ctx, u.ID, form) err := Creator.Withdraw(ctx, u.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
@@ -306,7 +305,7 @@ func (s *CreatorTestSuite) Test_Withdraw() {
Convey("should fail if insufficient balance", func() { Convey("should fail if insufficient balance", func() {
form := &creator_dto.WithdrawForm{ form := &creator_dto.WithdrawForm{
Amount: 100.00, Amount: 100.00,
AccountID: cast.ToString(pa.ID), AccountID: pa.ID,
} }
err := Creator.Withdraw(ctx, u.ID, form) err := Creator.Withdraw(ctx, u.ID, form)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
@@ -349,7 +348,7 @@ func (s *CreatorTestSuite) Test_Refund() {
Convey("should accept refund", func() { Convey("should accept refund", func() {
form := &creator_dto.RefundForm{Action: "accept", Reason: "Defective"} form := &creator_dto.RefundForm{Action: "accept", Reason: "Defective"}
err := Creator.ProcessRefund(ctx, creator.ID, cast.ToString(o.ID), form) err := Creator.ProcessRefund(ctx, creator.ID, o.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify Order // Verify Order

View File

@@ -10,8 +10,6 @@ import (
"quyun/v2/app/requests" "quyun/v2/app/requests"
"quyun/v2/database/models" "quyun/v2/database/models"
"quyun/v2/providers/job" "quyun/v2/providers/job"
"github.com/spf13/cast"
) )
// @provider // @provider
@@ -43,7 +41,7 @@ func (s *notification) List(ctx context.Context, userID int64, page int, typeArg
data := make([]user_dto.Notification, len(list)) data := make([]user_dto.Notification, len(list))
for i, v := range list { for i, v := range list {
data[i] = user_dto.Notification{ data[i] = user_dto.Notification{
ID: cast.ToString(v.ID), ID: v.ID,
Type: v.Type, Type: v.Type,
Title: v.Title, Title: v.Title,
Content: v.Content, Content: v.Content,
@@ -59,11 +57,9 @@ func (s *notification) List(ctx context.Context, userID int64, page int, typeArg
}, nil }, nil
} }
func (s *notification) MarkRead(ctx context.Context, userID int64, id string) error { func (s *notification) MarkRead(ctx context.Context, userID int64, id int64) error {
nid := cast.ToInt64(id)
_, err := models.NotificationQuery.WithContext(ctx). _, err := models.NotificationQuery.WithContext(ctx).
Where(models.NotificationQuery.ID.Eq(nid), models.NotificationQuery.UserID.Eq(userID)). Where(models.NotificationQuery.ID.Eq(id), models.NotificationQuery.UserID.Eq(userID)).
UpdateSimple(models.NotificationQuery.IsRead.Value(true)) UpdateSimple(models.NotificationQuery.IsRead.Value(true))
if err != nil { if err != nil {
return errorx.ErrDatabaseError.WithCause(err) return errorx.ErrDatabaseError.WithCause(err)

View File

@@ -12,7 +12,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -61,7 +60,7 @@ func (s *NotificationTestSuite) Test_CRUD() {
// Mark Read // Mark Read
// Need ID // Need ID
n, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.UserID.Eq(uID)).First() n, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.UserID.Eq(uID)).First()
err = Notification.MarkRead(ctx, uID, cast.ToString(n.ID)) err = Notification.MarkRead(ctx, uID, n.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
nReload, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.ID.Eq(n.ID)).First() nReload, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.ID.Eq(n.ID)).First()

View File

@@ -13,7 +13,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/spf13/cast"
"go.ipao.vip/gen/types" "go.ipao.vip/gen/types"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -47,15 +46,14 @@ func (s *order) ListUserOrders(ctx context.Context, userID int64, status string)
return data, nil return data, nil
} }
func (s *order) GetUserOrder(ctx context.Context, userID int64, id string) (*user_dto.Order, error) { func (s *order) GetUserOrder(ctx context.Context, userID int64, id int64) (*user_dto.Order, error) {
if userID == 0 { if userID == 0 {
return nil, errorx.ErrUnauthorized return nil, errorx.ErrUnauthorized
} }
uid := userID uid := userID
oid := cast.ToInt64(id)
tbl, q := models.OrderQuery.QueryContext(ctx) tbl, q := models.OrderQuery.QueryContext(ctx)
item, err := q.Where(tbl.ID.Eq(oid), tbl.UserID.Eq(uid)).First() item, err := q.Where(tbl.ID.Eq(id), tbl.UserID.Eq(uid)).First()
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.ErrRecordNotFound return nil, errorx.ErrRecordNotFound
@@ -79,7 +77,7 @@ func (s *order) Create(
return nil, errorx.ErrUnauthorized return nil, errorx.ErrUnauthorized
} }
uid := userID uid := userID
cid := cast.ToInt64(form.ContentID) cid := form.ContentID
// 1. Fetch Content & Price // 1. Fetch Content & Price
content, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid)).First() content, err := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(cid)).First()
@@ -100,15 +98,14 @@ func (s *order) Create(
var couponID int64 = 0 var couponID int64 = 0
// Validate Coupon // Validate Coupon
if form.UserCouponID != "" { if form.UserCouponID > 0 {
ucid := cast.ToInt64(form.UserCouponID) discount, err := Coupon.Validate(ctx, uid, form.UserCouponID, amountOriginal)
discount, err := Coupon.Validate(ctx, uid, ucid, amountOriginal)
if err != nil { if err != nil {
return nil, err return nil, err
} }
amountDiscount = discount amountDiscount = discount
uc, err := models.UserCouponQuery.WithContext(ctx).Where(models.UserCouponQuery.ID.Eq(ucid)).First() uc, err := models.UserCouponQuery.WithContext(ctx).Where(models.UserCouponQuery.ID.Eq(form.UserCouponID)).First()
if err == nil { if err == nil {
couponID = uc.CouponID couponID = uc.CouponID
} }
@@ -150,8 +147,8 @@ func (s *order) Create(
} }
// Mark Coupon Used // Mark Coupon Used
if form.UserCouponID != "" { if form.UserCouponID > 0 {
if err := Coupon.MarkUsed(ctx, tx, cast.ToInt64(form.UserCouponID), order.ID); err != nil { if err := Coupon.MarkUsed(ctx, tx, form.UserCouponID, order.ID); err != nil {
return err return err
} }
} }
@@ -166,25 +163,24 @@ func (s *order) Create(
} }
return &transaction_dto.OrderCreateResponse{ return &transaction_dto.OrderCreateResponse{
OrderID: cast.ToString(order.ID), OrderID: order.ID,
}, nil }, nil
} }
func (s *order) Pay( func (s *order) Pay(
ctx context.Context, ctx context.Context,
userID int64, userID int64,
id string, id int64,
form *transaction_dto.OrderPayForm, form *transaction_dto.OrderPayForm,
) (*transaction_dto.OrderPayResponse, error) { ) (*transaction_dto.OrderPayResponse, error) {
if userID == 0 { if userID == 0 {
return nil, errorx.ErrUnauthorized return nil, errorx.ErrUnauthorized
} }
uid := userID uid := userID
oid := cast.ToInt64(id)
// Fetch Order // Fetch Order
o, err := models.OrderQuery.WithContext(ctx). o, err := models.OrderQuery.WithContext(ctx).
Where(models.OrderQuery.ID.Eq(oid), models.OrderQuery.UserID.Eq(uid)). Where(models.OrderQuery.ID.Eq(id), models.OrderQuery.UserID.Eq(uid)).
First() First()
if err != nil { if err != nil {
return nil, errorx.ErrRecordNotFound return nil, errorx.ErrRecordNotFound
@@ -204,9 +200,8 @@ func (s *order) Pay(
} }
// ProcessExternalPayment handles callback from payment gateway // ProcessExternalPayment handles callback from payment gateway
func (s *order) ProcessExternalPayment(ctx context.Context, orderID, externalID string) error { func (s *order) ProcessExternalPayment(ctx context.Context, orderID int64, externalID string) error {
oid := cast.ToInt64(orderID) o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(orderID)).First()
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
} }
@@ -347,20 +342,30 @@ func (s *order) settleOrder(ctx context.Context, o *models.Order, method, extern
return nil return nil
} }
func (s *order) Status(ctx context.Context, id string) (*transaction_dto.OrderStatusResponse, error) { func (s *order) Status(ctx context.Context, id int64) (*transaction_dto.OrderStatusResponse, error) {
return nil, nil o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(id)).First()
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.ErrRecordNotFound
}
return nil, errorx.ErrDatabaseError.WithCause(err)
}
return &transaction_dto.OrderStatusResponse{
Status: string(o.Status),
}, nil
} }
func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.Order, error) { func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.Order, error) {
dto := user_dto.Order{ dto := user_dto.Order{
ID: cast.ToString(o.ID), ID: o.ID,
Type: string(o.Type), Type: string(o.Type),
TypeDescription: o.Type.Description(), TypeDescription: o.Type.Description(),
Status: string(o.Status), Status: string(o.Status),
StatusDescription: o.Status.Description(), StatusDescription: o.Status.Description(),
Amount: float64(o.AmountPaid) / 100.0, Amount: float64(o.AmountPaid) / 100.0,
CreateTime: o.CreatedAt.Format(time.RFC3339), CreateTime: o.CreatedAt.Format(time.RFC3339),
TenantID: cast.ToString(o.TenantID), TenantID: o.TenantID,
} }
// Fetch Tenant Name // Fetch Tenant Name
@@ -385,10 +390,10 @@ func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.
if err == nil { if err == nil {
ci := transaction_dto.ContentItem{ ci := transaction_dto.ContentItem{
ID: cast.ToString(c.ID), ID: c.ID,
Title: c.Title, Title: c.Title,
Genre: c.Genre, Genre: c.Genre,
AuthorID: cast.ToString(c.UserID), AuthorID: c.UserID,
Price: float64(item.AmountPaid) / 100.0, // Use actual paid amount Price: float64(item.AmountPaid) / 100.0, // Use actual paid amount
} }
// Cover logic (simplified from content service) // Cover logic (simplified from content service)
@@ -408,7 +413,7 @@ func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.
func (s *order) toUserOrderDTO(o *models.Order) user_dto.Order { func (s *order) toUserOrderDTO(o *models.Order) user_dto.Order {
return user_dto.Order{ return user_dto.Order{
ID: cast.ToString(o.ID), ID: o.ID,
Status: string(o.Status), // Need cast for DTO string field if DTO field is string Status: string(o.Status), // Need cast for DTO string field if DTO field is string
Amount: float64(o.AmountPaid) / 100.0, Amount: float64(o.AmountPaid) / 100.0,
CreateTime: o.CreatedAt.Format(time.RFC3339), CreateTime: o.CreatedAt.Format(time.RFC3339),

View File

@@ -11,7 +11,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -83,13 +82,13 @@ func (s *OrderTestSuite) Test_PurchaseFlow() {
Convey("should create and pay order successfully", func() { Convey("should create and pay order successfully", func() {
// Step 1: Create Order // Step 1: Create Order
form := &order_dto.OrderCreateForm{ContentID: cast.ToString(content.ID)} form := &order_dto.OrderCreateForm{ContentID: content.ID}
createRes, err := Order.Create(ctx, buyer.ID, form) createRes, err := Order.Create(ctx, buyer.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(createRes.OrderID, ShouldNotBeEmpty) So(createRes.OrderID, ShouldNotBeEmpty)
// Verify created status // Verify created status
oid := cast.ToInt64(createRes.OrderID) oid := createRes.OrderID
o, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First() o, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
So(o.Status, ShouldEqual, consts.OrderStatusCreated) So(o.Status, ShouldEqual, consts.OrderStatusCreated)
So(o.AmountPaid, ShouldEqual, 1000) So(o.AmountPaid, ShouldEqual, 1000)
@@ -130,7 +129,7 @@ func (s *OrderTestSuite) Test_PurchaseFlow() {
Where(models.UserQuery.ID.Eq(buyer.ID)). Where(models.UserQuery.ID.Eq(buyer.ID)).
Update(models.UserQuery.Balance, 500) Update(models.UserQuery.Balance, 500)
form := &order_dto.OrderCreateForm{ContentID: cast.ToString(content.ID)} form := &order_dto.OrderCreateForm{ContentID: content.ID}
createRes, err := Order.Create(ctx, buyer.ID, form) createRes, err := Order.Create(ctx, buyer.ID, form)
So(err, ShouldBeNil) So(err, ShouldBeNil)
@@ -201,7 +200,7 @@ func (s *OrderTestSuite) Test_OrderDetails() {
createRes, _ := Order.Create( createRes, _ := Order.Create(
ctx, ctx,
buyer.ID, buyer.ID,
&order_dto.OrderCreateForm{ContentID: cast.ToString(content.ID)}, &order_dto.OrderCreateForm{ContentID: content.ID},
) )
Order.Pay(ctx, buyer.ID, createRes.OrderID, &order_dto.OrderPayForm{Method: "balance"}) Order.Pay(ctx, buyer.ID, createRes.OrderID, &order_dto.OrderPayForm{Method: "balance"})
@@ -254,7 +253,7 @@ func (s *OrderTestSuite) Test_PlatformCommission() {
Convey("should deduct 10% fee", func() { Convey("should deduct 10% fee", func() {
payForm := &order_dto.OrderPayForm{Method: "balance"} payForm := &order_dto.OrderPayForm{Method: "balance"}
_, err := Order.Pay(ctx, buyer.ID, cast.ToString(o.ID), payForm) _, err := Order.Pay(ctx, buyer.ID, o.ID, payForm)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify Creator Balance (1000 - 10% = 900) // Verify Creator Balance (1000 - 10% = 900)
@@ -303,7 +302,7 @@ func (s *OrderTestSuite) Test_ExternalPayment() {
models.OrderItemQuery.WithContext(ctx).Create(&models.OrderItem{OrderID: o.ID, ContentID: 999}) models.OrderItemQuery.WithContext(ctx).Create(&models.OrderItem{OrderID: o.ID, ContentID: 999})
Convey("should process external payment callback", func() { Convey("should process external payment callback", func() {
err := Order.ProcessExternalPayment(ctx, cast.ToString(o.ID), "ext_tx_id_123") err := Order.ProcessExternalPayment(ctx, o.ID, "ext_tx_id_123")
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify Status // Verify Status

View File

@@ -156,7 +156,7 @@ func (s *super) ListTenants(ctx context.Context, filter *super_dto.TenantListFil
} }
func (s *super) CreateTenant(ctx context.Context, form *super_dto.TenantCreateForm) error { func (s *super) CreateTenant(ctx context.Context, form *super_dto.TenantCreateForm) error {
uid := cast.ToInt64(form.AdminUserID) uid := form.AdminUserID
if _, err := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(uid)).First(); err != nil { if _, err := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(uid)).First(); err != nil {
return errorx.ErrRecordNotFound.WithMsg("用户不存在") return errorx.ErrRecordNotFound.WithMsg("用户不存在")
} }
@@ -331,7 +331,7 @@ func (s *super) ApproveWithdrawal(ctx context.Context, id int64) error {
UpdatedAt: time.Now(), UpdatedAt: time.Now(),
}) })
if err == nil && Audit != nil { if err == nil && Audit != nil {
Audit.Log(ctx, "approve_withdrawal", cast.ToString(id), "Approved withdrawal") Audit.Log(ctx, 0, "approve_withdrawal", cast.ToString(id), "Approved withdrawal")
} }
return err return err
} }
@@ -381,7 +381,7 @@ func (s *super) RejectWithdrawal(ctx context.Context, id int64, reason string) e
}) })
if err == nil && Audit != nil { if err == nil && Audit != nil {
Audit.Log(ctx, "reject_withdrawal", cast.ToString(id), "Rejected: "+reason) Audit.Log(ctx, 0, "reject_withdrawal", cast.ToString(id), "Rejected: "+reason)
} }
return err return err
} }

View File

@@ -3,15 +3,12 @@ package services
import ( import (
"context" "context"
"errors" "errors"
"fmt"
"quyun/v2/app/errorx" "quyun/v2/app/errorx"
"quyun/v2/app/http/v1/dto" "quyun/v2/app/http/v1/dto"
"quyun/v2/app/requests" "quyun/v2/app/requests"
"quyun/v2/database/models" "quyun/v2/database/models"
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
"github.com/spf13/cast"
"go.ipao.vip/gen/types" "go.ipao.vip/gen/types"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -47,7 +44,7 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
cfg := t.Config.Data() cfg := t.Config.Data()
data = append(data, dto.TenantProfile{ data = append(data, dto.TenantProfile{
ID: cast.ToString(t.ID), ID: t.ID,
Name: t.Name, Name: t.Name,
Avatar: cfg.Avatar, Avatar: cfg.Avatar,
Bio: cfg.Bio, Bio: cfg.Bio,
@@ -65,9 +62,8 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
}, nil }, nil
} }
func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string) (*dto.TenantProfile, error) { func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id int64) (*dto.TenantProfile, error) {
tid := cast.ToInt64(id) t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(tid)).First()
if err != nil { if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) { if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, errorx.ErrRecordNotFound return nil, errorx.ErrRecordNotFound
@@ -76,9 +72,9 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
} }
// Stats // Stats
followers, _ := models.TenantUserQuery.WithContext(ctx).Where(models.TenantUserQuery.TenantID.Eq(tid)).Count() followers, _ := models.TenantUserQuery.WithContext(ctx).Where(models.TenantUserQuery.TenantID.Eq(id)).Count()
contents, _ := models.ContentQuery.WithContext(ctx). contents, _ := models.ContentQuery.WithContext(ctx).
Where(models.ContentQuery.TenantID.Eq(tid), models.ContentQuery.Status.Eq(consts.ContentStatusPublished)). Where(models.ContentQuery.TenantID.Eq(id), models.ContentQuery.Status.Eq(consts.ContentStatusPublished)).
Count() Count()
// Following status // Following status
@@ -86,14 +82,13 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
if userID > 0 { if userID > 0 {
uid := userID uid := userID
isFollowing, _ = models.TenantUserQuery.WithContext(ctx). isFollowing, _ = models.TenantUserQuery.WithContext(ctx).
Where(models.TenantUserQuery.TenantID.Eq(tid), models.TenantUserQuery.UserID.Eq(uid)). Where(models.TenantUserQuery.TenantID.Eq(id), models.TenantUserQuery.UserID.Eq(uid)).
Exists() Exists()
} }
cfg := t.Config.Data() cfg := t.Config.Data()
fmt.Printf("DEBUG: Tenant Config: %+v\n", cfg)
return &dto.TenantProfile{ return &dto.TenantProfile{
ID: cast.ToString(t.ID), ID: t.ID,
Name: t.Name, Name: t.Name,
Avatar: cfg.Avatar, Avatar: cfg.Avatar,
Cover: cfg.Cover, Cover: cfg.Cover,
@@ -107,21 +102,20 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
}, nil }, nil
} }
func (s *tenant) Follow(ctx context.Context, userID int64, id string) error { func (s *tenant) Follow(ctx context.Context, userID int64, id int64) error {
if userID == 0 { if userID == 0 {
return errorx.ErrUnauthorized return errorx.ErrUnauthorized
} }
uid := userID uid := userID
tid := cast.ToInt64(id)
// Check if tenant exists // Check if tenant exists
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(tid)).First() t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
if err != nil { if err != nil {
return errorx.ErrRecordNotFound return errorx.ErrRecordNotFound
} }
tu := &models.TenantUser{ tu := &models.TenantUser{
TenantID: tid, TenantID: id,
UserID: uid, UserID: uid,
Role: types.Array[consts.TenantUserRole]{consts.TenantUserRoleMember}, Role: types.Array[consts.TenantUserRole]{consts.TenantUserRoleMember},
Status: consts.UserStatusVerified, Status: consts.UserStatusVerified,
@@ -137,15 +131,14 @@ func (s *tenant) Follow(ctx context.Context, userID int64, id string) error {
return nil return nil
} }
func (s *tenant) Unfollow(ctx context.Context, userID int64, id string) error { func (s *tenant) Unfollow(ctx context.Context, userID int64, id int64) error {
if userID == 0 { if userID == 0 {
return errorx.ErrUnauthorized return errorx.ErrUnauthorized
} }
uid := userID uid := userID
tid := cast.ToInt64(id)
_, err := models.TenantUserQuery.WithContext(ctx). _, err := models.TenantUserQuery.WithContext(ctx).
Where(models.TenantUserQuery.TenantID.Eq(tid), models.TenantUserQuery.UserID.Eq(uid)). Where(models.TenantUserQuery.TenantID.Eq(id), models.TenantUserQuery.UserID.Eq(uid)).
Delete() Delete()
if err != nil { if err != nil {
return errorx.ErrDatabaseError.WithCause(err) return errorx.ErrDatabaseError.WithCause(err)
@@ -182,7 +175,7 @@ func (s *tenant) ListFollowed(ctx context.Context, userID int64) ([]dto.TenantPr
Count() Count()
data = append(data, dto.TenantProfile{ data = append(data, dto.TenantProfile{
ID: cast.ToString(t.ID), ID: t.ID,
Name: t.Name, Name: t.Name,
Avatar: "", Avatar: "",
Stats: dto.Stats{ Stats: dto.Stats{

View File

@@ -11,7 +11,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -52,11 +51,11 @@ func (s *TenantTestSuite) Test_Follow() {
models.TenantQuery.WithContext(ctx).Create(t) models.TenantQuery.WithContext(ctx).Create(t)
Convey("should follow tenant", func() { Convey("should follow tenant", func() {
err := Tenant.Follow(ctx, u.ID, cast.ToString(t.ID)) err := Tenant.Follow(ctx, u.ID, t.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify stats // Verify stats
profile, err := Tenant.GetPublicProfile(ctx, u.ID, cast.ToString(t.ID)) profile, err := Tenant.GetPublicProfile(ctx, u.ID, t.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(profile.IsFollowing, ShouldBeTrue) So(profile.IsFollowing, ShouldBeTrue)
So(profile.Stats.Followers, ShouldEqual, 1) So(profile.Stats.Followers, ShouldEqual, 1)
@@ -68,11 +67,11 @@ func (s *TenantTestSuite) Test_Follow() {
So(list[0].Name, ShouldEqual, "Tenant A") So(list[0].Name, ShouldEqual, "Tenant A")
// Unfollow // Unfollow
err = Tenant.Unfollow(ctx, u.ID, cast.ToString(t.ID)) err = Tenant.Unfollow(ctx, u.ID, t.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
// Verify // Verify
profile, err = Tenant.GetPublicProfile(ctx, u.ID, cast.ToString(t.ID)) profile, err = Tenant.GetPublicProfile(ctx, u.ID, t.ID)
So(err, ShouldBeNil) So(err, ShouldBeNil)
So(profile.IsFollowing, ShouldBeFalse) So(profile.IsFollowing, ShouldBeFalse)
So(profile.Stats.Followers, ShouldEqual, 0) So(profile.Stats.Followers, ShouldEqual, 0)

View File

@@ -13,7 +13,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
"quyun/v2/providers/jwt" "quyun/v2/providers/jwt"
"github.com/spf13/cast"
"go.ipao.vip/gen/types" "go.ipao.vip/gen/types"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -176,7 +175,7 @@ func (s *user) GetNotifications(ctx context.Context, userID int64, typeArg strin
result := make([]user_dto.Notification, len(list)) result := make([]user_dto.Notification, len(list))
for i, v := range list { for i, v := range list {
result[i] = user_dto.Notification{ result[i] = user_dto.Notification{
ID: cast.ToString(v.ID), ID: v.ID,
Type: v.Type, Type: v.Type,
Title: v.Title, Title: v.Title,
Content: v.Content, Content: v.Content,
@@ -189,7 +188,7 @@ func (s *user) GetNotifications(ctx context.Context, userID int64, typeArg strin
func (s *user) ToAuthUserDTO(u *models.User) *auth_dto.User { func (s *user) ToAuthUserDTO(u *models.User) *auth_dto.User {
return &auth_dto.User{ return &auth_dto.User{
ID: cast.ToString(u.ID), ID: u.ID,
Phone: u.Phone, Phone: u.Phone,
Nickname: u.Nickname, Nickname: u.Nickname,
Avatar: u.Avatar, Avatar: u.Avatar,

View File

@@ -12,7 +12,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
. "github.com/smartystreets/goconvey/convey" . "github.com/smartystreets/goconvey/convey"
"github.com/spf13/cast"
"github.com/stretchr/testify/suite" "github.com/stretchr/testify/suite"
"go.ipao.vip/atom/contracts" "go.ipao.vip/atom/contracts"
"go.uber.org/dig" "go.uber.org/dig"
@@ -81,7 +80,7 @@ func (s *UserTestSuite) Test_Me() {
// Create user // Create user
phone := "13800138003" phone := "13800138003"
resp, _ := User.LoginWithOTP(ctx, phone, "123456") resp, _ := User.LoginWithOTP(ctx, phone, "123456")
userID := cast.ToInt64(resp.User.ID) userID := resp.User.ID
Convey("should return user profile", func() { Convey("should return user profile", func() {
// Mock context with user ID // Mock context with user ID
@@ -109,7 +108,7 @@ func (s *UserTestSuite) Test_Update() {
phone := "13800138004" phone := "13800138004"
resp, _ := User.LoginWithOTP(ctx, phone, "123456") resp, _ := User.LoginWithOTP(ctx, phone, "123456")
userID := cast.ToInt64(resp.User.ID) userID := resp.User.ID
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID) ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
Convey("should update nickname and bio", func() { Convey("should update nickname and bio", func() {
@@ -137,7 +136,7 @@ func (s *UserTestSuite) Test_RealName() {
phone := "13800138005" phone := "13800138005"
resp, _ := User.LoginWithOTP(ctx, phone, "123456") resp, _ := User.LoginWithOTP(ctx, phone, "123456")
userID := cast.ToInt64(resp.User.ID) userID := resp.User.ID
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID) ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
Convey("should update realname status", func() { Convey("should update realname status", func() {
@@ -162,7 +161,7 @@ func (s *UserTestSuite) Test_GetNotifications() {
phone := "13800138006" phone := "13800138006"
resp, _ := User.LoginWithOTP(ctx, phone, "123456") resp, _ := User.LoginWithOTP(ctx, phone, "123456")
userID := cast.ToInt64(resp.User.ID) userID := resp.User.ID
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID) ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
// Mock notifications // Mock notifications

View File

@@ -12,7 +12,6 @@ import (
"quyun/v2/pkg/consts" "quyun/v2/pkg/consts"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/spf13/cast"
"go.ipao.vip/gen/types" "go.ipao.vip/gen/types"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -55,7 +54,7 @@ func (s *wallet) GetWallet(ctx context.Context, userID int64) (*user_dto.WalletR
} }
txs = append(txs, user_dto.Transaction{ txs = append(txs, user_dto.Transaction{
ID: cast.ToString(o.ID), ID: o.ID,
Title: title, Title: title,
Amount: float64(o.AmountPaid) / 100.0, Amount: float64(o.AmountPaid) / 100.0,
Type: txType, Type: txType,
@@ -98,13 +97,13 @@ func (s *wallet) Recharge(
// MOCK: Automatically pay for recharge order to close the loop // MOCK: Automatically pay for recharge order to close the loop
// In production, this would be a callback from payment gateway // In production, this would be a callback from payment gateway
if err := Order.ProcessExternalPayment(ctx, cast.ToString(order.ID), "mock_auto_pay"); err != nil { if err := Order.ProcessExternalPayment(ctx, order.ID, "mock_auto_pay"); err != nil {
return nil, err return nil, err
} }
// Mock Pay Params // Mock Pay Params
return &user_dto.RechargeResponse{ return &user_dto.RechargeResponse{
PayParams: "mock_paid_success", PayParams: "mock_paid_success",
OrderID: cast.ToString(order.ID), OrderID: order.ID,
}, nil }, nil
} }

View File

@@ -6,7 +6,7 @@
### P0 / 安全与数据隔离 ### P0 / 安全与数据隔离
1) 多租户路由与上下文缺失,无法满足 `/t/:tenant_code/v1` 规范,存在跨租户数据泄漏风险。 1) (暂时不需要管,后续统一优化)多租户路由与上下文缺失,无法满足 `/t/:tenant_code/v1` 规范,存在跨租户数据泄漏风险。
- 后端路由基座仍为 `/v1``backend/app/http/v1/routes.manual.go` - 后端路由基座仍为 `/v1``backend/app/http/v1/routes.manual.go`
- 前端路由与 API 基座未含 tenant_code`frontend/portal/src/router/index.js``frontend/portal/src/utils/request.js` - 前端路由与 API 基座未含 tenant_code`frontend/portal/src/router/index.js``frontend/portal/src/utils/request.js`
- 多数服务查询未强制带 `tenant_id` 条件(仅依赖 query 传参):如 `backend/app/services/content.go``backend/app/services/order.go``backend/app/services/common.go` - 多数服务查询未强制带 `tenant_id` 条件(仅依赖 query 传参):如 `backend/app/services/content.go``backend/app/services/order.go``backend/app/services/common.go`
@@ -25,7 +25,7 @@
- 超管统计/订单详情/退款等均为空:`backend/app/services/super.go` - 超管统计/订单详情/退款等均为空:`backend/app/services/super.go`
- 超管内容/订单列表 DTO 映射 TODO`backend/app/services/super.go` - 超管内容/订单列表 DTO 映射 TODO`backend/app/services/super.go`
5) 认证方式与规格偏离:现实现 OTP 登录 + JWT规格为 WeChat OAuth + Cookie。 5) 认证方式与规格偏离:现实现 OTP 登录 + JWT规格为 WeChat OAuth + Cookie(已经移除,仅使用jwt认证)
- 认证流程:`backend/app/http/v1/auth/auth.go``backend/app/services/user.go` - 认证流程:`backend/app/http/v1/auth/auth.go``backend/app/services/user.go`
- 前端调用 OTP 登录:`frontend/portal/src/api/auth.js` - 前端调用 OTP 登录:`frontend/portal/src/api/auth.js`
@@ -44,7 +44,7 @@
9) Service 读取 `ctx` 获取用户信息,违反“上下文提取必须在 Controller 层”的规则。 9) Service 读取 `ctx` 获取用户信息,违反“上下文提取必须在 Controller 层”的规则。
- `services.audit.Log` 直接读 `ctx.Value``backend/app/services/audit.go` - `services.audit.Log` 直接读 `ctx.Value``backend/app/services/audit.go`
10) 数据库迁移与规格不一致,初始迁移为空,实际表结构仅在 `specs/DB.sql` 10) 数据库迁移与规格不一致,初始迁移为空,实际表结构仅在 `specs/DB.sql`(此文件仅做迁移参考,根据业务需求进行优化)
- `backend/database/migrations/20251227112605_init.sql` 为空。 - `backend/database/migrations/20251227112605_init.sql` 为空。
11) N+1 查询与聚合性能风险。 11) N+1 查询与聚合性能风险。
@@ -72,7 +72,7 @@
- 控制器签名支持 `@Bind id path` + `int64``@Bind tenant model(id)` 进行 model 注入。 - 控制器签名支持 `@Bind id path` + `int64``@Bind tenant model(id)` 进行 model 注入。
- swagger `@Router` 必须使用 `:id<int>` / `:tenantID<int>` - swagger `@Router` 必须使用 `:id<int>` / `:tenantID<int>`
### 4) 规格一致性修复 ### 4) 规格一致性修复 (仅使用JWT
- 统一认证模型OTP vs WeChat要么按规格实现 WeChat OAuth要么更新规格文档。 - 统一认证模型OTP vs WeChat要么按规格实现 WeChat OAuth要么更新规格文档。
- 统一存储方案OSS + tenant_uuid + md5 命名);当前本地存储仅作开发 fallback。 - 统一存储方案OSS + tenant_uuid + md5 命名);当前本地存储仅作开发 fallback。
-`specs/DB.sql` 迁入真实迁移文件并补齐中文字段注释。 -`specs/DB.sql` 迁入真实迁移文件并补齐中文字段注释。

View File

@@ -10,10 +10,10 @@ export const userApi = {
getOrder: (id) => request(`/me/orders/${id}`), getOrder: (id) => request(`/me/orders/${id}`),
getLibrary: () => request('/me/library'), getLibrary: () => request('/me/library'),
getFavorites: () => request('/me/favorites'), getFavorites: () => request('/me/favorites'),
addFavorite: (contentId) => request(`/me/favorites?content_id=${contentId}`, { method: 'POST' }), addFavorite: (contentId) => request(`/me/favorites?contentId=${contentId}`, { method: 'POST' }),
removeFavorite: (contentId) => request(`/me/favorites/${contentId}`, { method: 'DELETE' }), removeFavorite: (contentId) => request(`/me/favorites/${contentId}`, { method: 'DELETE' }),
getLikes: () => request('/me/likes'), getLikes: () => request('/me/likes'),
addLike: (contentId) => request(`/me/likes?content_id=${contentId}`, { method: 'POST' }), addLike: (contentId) => request(`/me/likes?contentId=${contentId}`, { method: 'POST' }),
removeLike: (contentId) => request(`/me/likes/${contentId}`, { method: 'DELETE' }), removeLike: (contentId) => request(`/me/likes/${contentId}`, { method: 'DELETE' }),
getNotifications: (type, page) => request(`/me/notifications?type=${type || 'all'}&page=${page || 1}`), getNotifications: (type, page) => request(`/me/notifications?type=${type || 'all'}&page=${page || 1}`),
markNotificationRead: (id) => request(`/me/notifications/${id}/read`, { method: 'POST' }), markNotificationRead: (id) => request(`/me/notifications/${id}/read`, { method: 'POST' }),