feat: align ids to int64
This commit is contained in:
@@ -3,17 +3,13 @@ package services
|
||||
import (
|
||||
"context"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type audit struct{}
|
||||
|
||||
func (s *audit) Log(ctx context.Context, action, targetID, detail string) {
|
||||
operatorID := cast.ToInt64(ctx.Value(consts.CtxKeyUser))
|
||||
func (s *audit) Log(ctx context.Context, operatorID int64, action, targetID, detail string) {
|
||||
logrus.WithFields(logrus.Fields{
|
||||
"audit": true,
|
||||
"operator": operatorID,
|
||||
|
||||
@@ -22,7 +22,6 @@ import (
|
||||
"quyun/v2/providers/storage"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"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
|
||||
}
|
||||
|
||||
func (s *common) DeleteMediaAsset(ctx context.Context, userID int64, id string) error {
|
||||
aid := cast.ToInt64(id)
|
||||
func (s *common) DeleteMediaAsset(ctx context.Context, userID int64, id int64) error {
|
||||
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()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
@@ -411,7 +409,7 @@ func (s *common) composeUploadResult(asset *models.MediaAsset) *common_dto.Uploa
|
||||
size := asset.Meta.Data().Size
|
||||
|
||||
return &common_dto.UploadResult{
|
||||
ID: cast.ToString(asset.ID),
|
||||
ID: asset.ID,
|
||||
URL: url,
|
||||
Filename: filename,
|
||||
Size: size,
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -30,9 +29,8 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
||||
if filter.Genre != nil && *filter.Genre != "" {
|
||||
q = q.Where(tbl.Genre.Eq(*filter.Genre))
|
||||
}
|
||||
if filter.TenantID != nil && *filter.TenantID != "" {
|
||||
tid := cast.ToInt64(*filter.TenantID)
|
||||
q = q.Where(tbl.TenantID.Eq(tid))
|
||||
if filter.TenantID != nil && *filter.TenantID > 0 {
|
||||
q = q.Where(tbl.TenantID.Eq(*filter.TenantID))
|
||||
}
|
||||
if filter.IsPinned != nil {
|
||||
q = q.Where(tbl.IsPinned.Is(*filter.IsPinned))
|
||||
@@ -129,12 +127,11 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dto.ContentDetail, error) {
|
||||
cid := cast.ToInt64(id)
|
||||
func (s *content) Get(ctx context.Context, userID int64, id int64) (*content_dto.ContentDetail, error) {
|
||||
|
||||
// Increment Views
|
||||
_, _ = models.ContentQuery.WithContext(ctx).
|
||||
Where(models.ContentQuery.ID.Eq(cid)).
|
||||
Where(models.ContentQuery.ID.Eq(id)).
|
||||
UpdateSimple(models.ContentQuery.Views.Add(1))
|
||||
|
||||
_, 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")
|
||||
}).
|
||||
Preload("ContentAssets.Asset").
|
||||
Where("id = ?", cid).
|
||||
Where("id = ?", id).
|
||||
First(&item).Error
|
||||
if err != nil {
|
||||
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
|
||||
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 {
|
||||
price = float64(cp.PriceAmount) / 100.0
|
||||
}
|
||||
@@ -172,12 +169,12 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
|
||||
// Interaction
|
||||
isLiked, _ = models.UserContentActionQuery.WithContext(ctx).
|
||||
Where(models.UserContentActionQuery.UserID.Eq(uid),
|
||||
models.UserContentActionQuery.ContentID.Eq(cid),
|
||||
models.UserContentActionQuery.ContentID.Eq(id),
|
||||
models.UserContentActionQuery.Type.Eq("like")).
|
||||
Exists()
|
||||
isFavorited, _ = models.UserContentActionQuery.WithContext(ctx).
|
||||
Where(models.UserContentActionQuery.UserID.Eq(uid),
|
||||
models.UserContentActionQuery.ContentID.Eq(cid),
|
||||
models.UserContentActionQuery.ContentID.Eq(id),
|
||||
models.UserContentActionQuery.Type.Eq("favorite")).
|
||||
Exists()
|
||||
|
||||
@@ -188,7 +185,7 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
|
||||
// Check Purchase
|
||||
exists, _ := models.ContentAccessQuery.WithContext(ctx).
|
||||
Where(models.ContentAccessQuery.UserID.Eq(uid),
|
||||
models.ContentAccessQuery.ContentID.Eq(cid),
|
||||
models.ContentAccessQuery.ContentID.Eq(id),
|
||||
models.ContentAccessQuery.Status.Eq(consts.ContentAccessStatusActive)).
|
||||
Exists()
|
||||
if exists {
|
||||
@@ -235,11 +232,10 @@ func (s *content) Get(ctx context.Context, userID int64, id string) (*content_dt
|
||||
return detail, nil
|
||||
}
|
||||
|
||||
func (s *content) ListComments(ctx context.Context, userID int64, id string, page int) (*requests.Pager, error) {
|
||||
cid := cast.ToInt64(id)
|
||||
func (s *content) ListComments(ctx context.Context, userID int64, id int64, page int) (*requests.Pager, error) {
|
||||
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())
|
||||
|
||||
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))
|
||||
for i, v := range list {
|
||||
data[i] = content_dto.Comment{
|
||||
ID: cast.ToString(v.ID),
|
||||
ID: v.ID,
|
||||
Content: v.Content,
|
||||
UserID: cast.ToString(v.UserID),
|
||||
UserID: v.UserID,
|
||||
UserNickname: v.User.Nickname,
|
||||
UserAvatar: v.User.Avatar,
|
||||
CreateTime: v.CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
Likes: int(v.Likes),
|
||||
ReplyTo: cast.ToString(v.ReplyTo),
|
||||
ReplyTo: v.ReplyTo,
|
||||
IsLiked: likedMap[v.ID],
|
||||
}
|
||||
}
|
||||
@@ -296,16 +292,15 @@ func (s *content) ListComments(ctx context.Context, userID int64, id string, pag
|
||||
func (s *content) CreateComment(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
id string,
|
||||
id int64,
|
||||
form *content_dto.CommentCreateForm,
|
||||
) error {
|
||||
if userID == 0 {
|
||||
return errorx.ErrUnauthorized
|
||||
}
|
||||
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 {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
@@ -313,9 +308,9 @@ func (s *content) CreateComment(
|
||||
comment := &models.Comment{
|
||||
TenantID: c.TenantID,
|
||||
UserID: uid,
|
||||
ContentID: cid,
|
||||
ContentID: id,
|
||||
Content: form.Content,
|
||||
ReplyTo: cast.ToInt64(form.ReplyTo),
|
||||
ReplyTo: form.ReplyTo,
|
||||
}
|
||||
|
||||
if err := models.CommentQuery.WithContext(ctx).Create(comment); err != nil {
|
||||
@@ -324,33 +319,32 @@ func (s *content) CreateComment(
|
||||
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 {
|
||||
return errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
cmid := cast.ToInt64(id)
|
||||
|
||||
// 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 {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
|
||||
err = models.Q.Transaction(func(tx *models.Query) error {
|
||||
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()
|
||||
if exists {
|
||||
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 {
|
||||
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
|
||||
})
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -420,11 +414,11 @@ func (s *content) GetLikes(ctx context.Context, userID int64) ([]user_dto.Conten
|
||||
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")
|
||||
}
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
@@ -470,7 +464,7 @@ func (s *content) ListTopics(ctx context.Context) ([]content_dto.Topic, error) {
|
||||
}
|
||||
|
||||
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,
|
||||
Tag: r.Genre,
|
||||
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 {
|
||||
dto := content_dto.ContentItem{
|
||||
ID: cast.ToString(item.ID),
|
||||
ID: item.ID,
|
||||
Title: item.Title,
|
||||
Genre: item.Genre,
|
||||
AuthorID: cast.ToString(item.UserID),
|
||||
AuthorID: item.UserID,
|
||||
Views: int(item.Views),
|
||||
Likes: int(item.Likes),
|
||||
CreatedAt: item.CreatedAt.Format("2006-01-02"),
|
||||
@@ -553,16 +547,15 @@ func (s *content) toMediaURLs(assets []*models.ContentAsset) []content_dto.Media
|
||||
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 {
|
||||
return errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
cid := cast.ToInt64(contentId)
|
||||
|
||||
// Fetch content for author
|
||||
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).
|
||||
First()
|
||||
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 {
|
||||
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()
|
||||
if exists {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
|
||||
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 nil
|
||||
@@ -605,16 +598,15 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId, typ
|
||||
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 {
|
||||
return errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
cid := cast.ToInt64(contentId)
|
||||
|
||||
return models.Q.Transaction(func(tx *models.Query) error {
|
||||
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()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -624,7 +616,7 @@ func (s *content) removeInteract(ctx context.Context, userID int64, contentId, t
|
||||
}
|
||||
|
||||
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 nil
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -126,7 +125,7 @@ func (s *ContentTestSuite) Test_Get() {
|
||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, author.ID)
|
||||
|
||||
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(detail.Title, ShouldEqual, "Detail Content")
|
||||
So(detail.AuthorName, ShouldEqual, "Author1")
|
||||
@@ -154,7 +153,7 @@ func (s *ContentTestSuite) Test_CreateComment() {
|
||||
form := &content_dto.CommentCreateForm{
|
||||
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)
|
||||
|
||||
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() {
|
||||
// Add Like
|
||||
err := Content.AddLike(ctx, u.ID, cast.ToString(c.ID))
|
||||
err := Content.AddLike(ctx, u.ID, c.ID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify count
|
||||
@@ -230,10 +229,10 @@ func (s *ContentTestSuite) Test_Interact() {
|
||||
likes, err := Content.GetLikes(ctx, u.ID)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(likes), ShouldEqual, 1)
|
||||
So(likes[0].ID, ShouldEqual, cast.ToString(c.ID))
|
||||
So(likes[0].ID, ShouldEqual, c.ID)
|
||||
|
||||
// Remove Like
|
||||
err = Content.RemoveLike(ctx, u.ID, cast.ToString(c.ID))
|
||||
err = Content.RemoveLike(ctx, u.ID, c.ID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify count
|
||||
@@ -243,17 +242,17 @@ func (s *ContentTestSuite) Test_Interact() {
|
||||
|
||||
Convey("Favorite flow", func() {
|
||||
// Add Favorite
|
||||
err := Content.AddFavorite(ctx, u.ID, cast.ToString(c.ID))
|
||||
err := Content.AddFavorite(ctx, u.ID, c.ID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Get Favorites
|
||||
favs, err := Content.GetFavorites(ctx, u.ID)
|
||||
So(err, ShouldBeNil)
|
||||
So(len(favs), ShouldEqual, 1)
|
||||
So(favs[0].ID, ShouldEqual, cast.ToString(c.ID))
|
||||
So(favs[0].ID, ShouldEqual, c.ID)
|
||||
|
||||
// Remove Favorite
|
||||
err = Content.RemoveFavorite(ctx, u.ID, cast.ToString(c.ID))
|
||||
err = Content.RemoveFavorite(ctx, u.ID, c.ID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Get Favorites
|
||||
@@ -325,7 +324,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
||||
models.UserQuery.WithContext(ctx).Create(guest)
|
||||
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(len(detail.MediaUrls), ShouldEqual, 1)
|
||||
So(detail.MediaUrls[0].URL, ShouldEndWith, "preview.mp4")
|
||||
@@ -334,7 +333,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
||||
|
||||
Convey("owner should see all", func() {
|
||||
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(len(detail.MediaUrls), ShouldEqual, 2)
|
||||
So(detail.IsPurchased, ShouldBeTrue)
|
||||
@@ -349,7 +348,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
||||
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(len(detail.MediaUrls), ShouldEqual, 2)
|
||||
So(detail.IsPurchased, ShouldBeTrue)
|
||||
@@ -369,7 +368,7 @@ func (s *ContentTestSuite) Test_ViewCounting() {
|
||||
models.ContentQuery.WithContext(ctx).Create(c)
|
||||
|
||||
Convey("should increment views", func() {
|
||||
_, err := Content.Get(ctx, 0, cast.ToString(c.ID))
|
||||
_, err := Content.Get(ctx, 0, c.ID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cReload, _ := models.ContentQuery.WithContext(ctx).Where(models.ContentQuery.ID.Eq(c.ID)).First()
|
||||
|
||||
@@ -7,8 +7,6 @@ import (
|
||||
"quyun/v2/app/errorx"
|
||||
coupon_dto "quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -40,8 +38,8 @@ func (s *coupon) ListUserCoupons(
|
||||
c, _ := models.CouponQuery.WithContext(ctx).Where(models.CouponQuery.ID.Eq(v.CouponID)).First()
|
||||
|
||||
item := coupon_dto.UserCouponItem{
|
||||
ID: cast.ToString(v.ID),
|
||||
CouponID: cast.ToString(v.CouponID),
|
||||
ID: v.ID,
|
||||
CouponID: v.CouponID,
|
||||
Status: v.Status,
|
||||
}
|
||||
if c != nil {
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"quyun/v2/providers/storage"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -94,15 +93,15 @@ func (s *CouponTestSuite) Test_CouponFlow() {
|
||||
})
|
||||
|
||||
form := &order_dto.OrderCreateForm{
|
||||
ContentID: cast.ToString(c.ID),
|
||||
UserCouponID: cast.ToString(uc.ID),
|
||||
ContentID: c.ID,
|
||||
UserCouponID: uc.ID,
|
||||
}
|
||||
// Simulate Auth context for Order service
|
||||
res, err := Order.Create(ctx, user.ID, form)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// Verify Order
|
||||
oid := cast.ToInt64(res.OrderID)
|
||||
oid := res.OrderID
|
||||
o, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
|
||||
So(o.AmountOriginal, ShouldEqual, 2000)
|
||||
So(o.AmountDiscount, ShouldEqual, 500)
|
||||
|
||||
@@ -3,7 +3,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -14,7 +14,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"go.ipao.vip/gen/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -125,9 +124,6 @@ func (s *creator) ListContents(
|
||||
if filter.Visibility != nil && *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 != "" {
|
||||
val := *filter.Genre
|
||||
if cn, ok := genreMap[val]; ok {
|
||||
@@ -137,7 +133,6 @@ func (s *creator) ListContents(
|
||||
}
|
||||
}
|
||||
if filter.Key != nil && *filter.Key != "" {
|
||||
fmt.Printf("DEBUG: Filter Key: '%s'\n", *filter.Key)
|
||||
q = q.Where(tbl.Key.Eq(*filter.Key))
|
||||
}
|
||||
if filter.Keyword != nil && *filter.Keyword != "" {
|
||||
@@ -227,7 +222,7 @@ func (s *creator) ListContents(
|
||||
}
|
||||
|
||||
data = append(data, creator_dto.CreatorContentItem{
|
||||
ID: cast.ToString(item.ID),
|
||||
ID: item.ID,
|
||||
Title: item.Title,
|
||||
Genre: item.Genre,
|
||||
Key: item.Key,
|
||||
@@ -286,7 +281,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: content.ID,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
AssetID: mid,
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleCover,
|
||||
})
|
||||
@@ -297,7 +292,7 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: content.ID,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
AssetID: mid,
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleMain,
|
||||
})
|
||||
@@ -327,19 +322,18 @@ func (s *creator) CreateContent(ctx context.Context, userID int64, form *creator
|
||||
func (s *creator) UpdateContent(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
id string,
|
||||
id int64,
|
||||
form *creator_dto.ContentUpdateForm,
|
||||
) error {
|
||||
tid, err := s.getTenantID(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cid := cast.ToInt64(id)
|
||||
uid := userID
|
||||
|
||||
return models.Q.Transaction(func(tx *models.Query) error {
|
||||
// 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 {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
@@ -366,7 +360,7 @@ func (s *creator) UpdateContent(
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
@@ -374,13 +368,13 @@ func (s *creator) UpdateContent(
|
||||
// Handle IsPinned Logic
|
||||
if finalStatus != consts.ContentStatusPublished {
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
} else if form.IsPinned != nil {
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
@@ -388,7 +382,7 @@ func (s *creator) UpdateContent(
|
||||
// If setting to true, unpin others
|
||||
if *form.IsPinned {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
@@ -398,17 +392,17 @@ func (s *creator) UpdateContent(
|
||||
// 3. Update Price
|
||||
// Check if price exists
|
||||
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)
|
||||
if count > 0 {
|
||||
_, err = tx.ContentPrice.WithContext(ctx).
|
||||
Where(tx.ContentPrice.ContentID.Eq(cid)).
|
||||
Where(tx.ContentPrice.ContentID.Eq(id)).
|
||||
UpdateSimple(tx.ContentPrice.PriceAmount.Value(newPrice))
|
||||
} else {
|
||||
err = tx.ContentPrice.WithContext(ctx).Create(&models.ContentPrice{
|
||||
TenantID: tid,
|
||||
UserID: c.UserID,
|
||||
ContentID: cid,
|
||||
ContentID: id,
|
||||
PriceAmount: newPrice,
|
||||
Currency: consts.CurrencyCNY,
|
||||
})
|
||||
@@ -419,7 +413,7 @@ func (s *creator) UpdateContent(
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
@@ -430,8 +424,8 @@ func (s *creator) UpdateContent(
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: cid,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
ContentID: id,
|
||||
AssetID: mid,
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleCover,
|
||||
})
|
||||
@@ -441,8 +435,8 @@ func (s *creator) UpdateContent(
|
||||
assets = append(assets, &models.ContentAsset{
|
||||
TenantID: tid,
|
||||
UserID: uid,
|
||||
ContentID: cid,
|
||||
AssetID: cast.ToInt64(mid),
|
||||
ContentID: id,
|
||||
AssetID: mid,
|
||||
Sort: int32(i),
|
||||
Role: consts.ContentAssetRoleMain,
|
||||
})
|
||||
@@ -457,21 +451,20 @@ func (s *creator) UpdateContent(
|
||||
})
|
||||
}
|
||||
|
||||
func (s *creator) DeleteContent(ctx context.Context, userID int64, id string) error {
|
||||
cid := cast.ToInt64(id)
|
||||
func (s *creator) DeleteContent(ctx context.Context, userID int64, id int64) error {
|
||||
tid, err := s.getTenantID(ctx, userID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 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 {
|
||||
return errorx.ErrPreconditionFailed.WithMsg("该内容已被购买,无法删除")
|
||||
}
|
||||
|
||||
_, 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()
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
@@ -479,17 +472,16 @@ func (s *creator) DeleteContent(ctx context.Context, userID int64, id string) er
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cid := cast.ToInt64(id)
|
||||
|
||||
// Fetch Content with preloads
|
||||
var c models.Content
|
||||
err = models.ContentQuery.WithContext(ctx).
|
||||
Where(models.ContentQuery.ID.Eq(cid), models.ContentQuery.TenantID.Eq(tid)).
|
||||
Where(models.ContentQuery.ID.Eq(id), models.ContentQuery.TenantID.Eq(tid)).
|
||||
UnderlyingDB().
|
||||
Preload("ContentAssets", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Order("sort ASC")
|
||||
@@ -505,13 +497,13 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre
|
||||
|
||||
// Fetch Price
|
||||
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 {
|
||||
price = float64(cp.PriceAmount) / 100.0
|
||||
}
|
||||
|
||||
dto := &creator_dto.ContentEditDTO{
|
||||
ID: cast.ToString(c.ID),
|
||||
ID: c.ID,
|
||||
Title: c.Title,
|
||||
Genre: c.Genre,
|
||||
Key: c.Key,
|
||||
@@ -538,10 +530,10 @@ func (s *creator) GetContent(ctx context.Context, userID int64, id string) (*cre
|
||||
|
||||
sizeBytes := meta.Size
|
||||
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{
|
||||
ID: cast.ToString(ca.AssetID),
|
||||
ID: ca.AssetID,
|
||||
Role: string(ca.Role),
|
||||
Type: string(ca.Asset.Type),
|
||||
URL: Common.GetAssetURL(ca.Asset.ObjectKey),
|
||||
@@ -573,7 +565,7 @@ func (s *creator) ListOrders(
|
||||
|
||||
if filter.Keyword != nil && *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))
|
||||
} else {
|
||||
uTbl, uQ := models.UserQuery.QueryContext(ctx)
|
||||
@@ -629,7 +621,7 @@ func (s *creator) ListOrders(
|
||||
}
|
||||
|
||||
data = append(data, creator_dto.Order{
|
||||
ID: cast.ToString(o.ID),
|
||||
ID: o.ID,
|
||||
Status: string(o.Status),
|
||||
Amount: float64(o.AmountPaid) / 100.0,
|
||||
CreateTime: o.CreatedAt.Format(time.RFC3339),
|
||||
@@ -642,17 +634,16 @@ func (s *creator) ListOrders(
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
oid := cast.ToInt64(id)
|
||||
uid := userID // Creator ID
|
||||
|
||||
// Fetch Order
|
||||
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()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound
|
||||
@@ -666,7 +657,7 @@ func (s *creator) ProcessRefund(ctx context.Context, userID int64, id string, fo
|
||||
}
|
||||
|
||||
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,
|
||||
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
|
||||
_, 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,
|
||||
RefundedAt: time.Now(),
|
||||
RefundOperatorUserID: uid,
|
||||
@@ -755,7 +746,7 @@ func (s *creator) GetSettings(ctx context.Context, userID int64) (*creator_dto.S
|
||||
}
|
||||
cfg := t.Config.Data()
|
||||
return &creator_dto.Settings{
|
||||
ID: cast.ToString(t.ID),
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Bio: cfg.Bio,
|
||||
Avatar: cfg.Avatar,
|
||||
@@ -802,7 +793,7 @@ func (s *creator) ListPayoutAccounts(ctx context.Context, userID int64) ([]creat
|
||||
var data []creator_dto.PayoutAccount
|
||||
for _, v := range list {
|
||||
data = append(data, creator_dto.PayoutAccount{
|
||||
ID: cast.ToString(v.ID),
|
||||
ID: v.ID,
|
||||
Type: v.Type,
|
||||
Name: v.Name,
|
||||
Account: v.Account,
|
||||
@@ -833,15 +824,14 @@ func (s *creator) AddPayoutAccount(ctx context.Context, userID int64, form *crea
|
||||
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)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pid := cast.ToInt64(id)
|
||||
|
||||
_, 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()
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
@@ -872,7 +862,7 @@ func (s *creator) Withdraw(ctx context.Context, userID int64, form *creator_dto.
|
||||
|
||||
// Validate Payout Account
|
||||
_, 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()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound.WithMsg("收款账户不存在")
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -145,7 +144,7 @@ func (s *CreatorTestSuite) Test_UpdateContent() {
|
||||
Genre: "video",
|
||||
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)
|
||||
|
||||
// Verify
|
||||
@@ -281,7 +280,7 @@ func (s *CreatorTestSuite) Test_Withdraw() {
|
||||
Convey("should withdraw successfully", func() {
|
||||
form := &creator_dto.WithdrawForm{
|
||||
Amount: 20.00,
|
||||
AccountID: cast.ToString(pa.ID),
|
||||
AccountID: pa.ID,
|
||||
}
|
||||
err := Creator.Withdraw(ctx, u.ID, form)
|
||||
So(err, ShouldBeNil)
|
||||
@@ -306,7 +305,7 @@ func (s *CreatorTestSuite) Test_Withdraw() {
|
||||
Convey("should fail if insufficient balance", func() {
|
||||
form := &creator_dto.WithdrawForm{
|
||||
Amount: 100.00,
|
||||
AccountID: cast.ToString(pa.ID),
|
||||
AccountID: pa.ID,
|
||||
}
|
||||
err := Creator.Withdraw(ctx, u.ID, form)
|
||||
So(err, ShouldNotBeNil)
|
||||
@@ -349,7 +348,7 @@ func (s *CreatorTestSuite) Test_Refund() {
|
||||
|
||||
Convey("should accept refund", func() {
|
||||
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)
|
||||
|
||||
// Verify Order
|
||||
|
||||
@@ -10,8 +10,6 @@ import (
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/providers/job"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -43,7 +41,7 @@ func (s *notification) List(ctx context.Context, userID int64, page int, typeArg
|
||||
data := make([]user_dto.Notification, len(list))
|
||||
for i, v := range list {
|
||||
data[i] = user_dto.Notification{
|
||||
ID: cast.ToString(v.ID),
|
||||
ID: v.ID,
|
||||
Type: v.Type,
|
||||
Title: v.Title,
|
||||
Content: v.Content,
|
||||
@@ -59,11 +57,9 @@ func (s *notification) List(ctx context.Context, userID int64, page int, typeArg
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *notification) MarkRead(ctx context.Context, userID int64, id string) error {
|
||||
nid := cast.ToInt64(id)
|
||||
|
||||
func (s *notification) MarkRead(ctx context.Context, userID int64, id int64) error {
|
||||
_, 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))
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -61,7 +60,7 @@ func (s *NotificationTestSuite) Test_CRUD() {
|
||||
// Mark Read
|
||||
// Need ID
|
||||
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)
|
||||
|
||||
nReload, _ := models.NotificationQuery.WithContext(ctx).Where(models.NotificationQuery.ID.Eq(n.ID)).First()
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"go.ipao.vip/gen/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -47,15 +46,14 @@ func (s *order) ListUserOrders(ctx context.Context, userID int64, status string)
|
||||
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 {
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
oid := cast.ToInt64(id)
|
||||
|
||||
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 errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
@@ -79,7 +77,7 @@ func (s *order) Create(
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
cid := cast.ToInt64(form.ContentID)
|
||||
cid := form.ContentID
|
||||
|
||||
// 1. Fetch Content & Price
|
||||
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
|
||||
|
||||
// Validate Coupon
|
||||
if form.UserCouponID != "" {
|
||||
ucid := cast.ToInt64(form.UserCouponID)
|
||||
discount, err := Coupon.Validate(ctx, uid, ucid, amountOriginal)
|
||||
if form.UserCouponID > 0 {
|
||||
discount, err := Coupon.Validate(ctx, uid, form.UserCouponID, amountOriginal)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
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 {
|
||||
couponID = uc.CouponID
|
||||
}
|
||||
@@ -150,8 +147,8 @@ func (s *order) Create(
|
||||
}
|
||||
|
||||
// Mark Coupon Used
|
||||
if form.UserCouponID != "" {
|
||||
if err := Coupon.MarkUsed(ctx, tx, cast.ToInt64(form.UserCouponID), order.ID); err != nil {
|
||||
if form.UserCouponID > 0 {
|
||||
if err := Coupon.MarkUsed(ctx, tx, form.UserCouponID, order.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -166,25 +163,24 @@ func (s *order) Create(
|
||||
}
|
||||
|
||||
return &transaction_dto.OrderCreateResponse{
|
||||
OrderID: cast.ToString(order.ID),
|
||||
OrderID: order.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *order) Pay(
|
||||
ctx context.Context,
|
||||
userID int64,
|
||||
id string,
|
||||
id int64,
|
||||
form *transaction_dto.OrderPayForm,
|
||||
) (*transaction_dto.OrderPayResponse, error) {
|
||||
if userID == 0 {
|
||||
return nil, errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
oid := cast.ToInt64(id)
|
||||
|
||||
// Fetch Order
|
||||
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()
|
||||
if err != nil {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
@@ -204,9 +200,8 @@ func (s *order) Pay(
|
||||
}
|
||||
|
||||
// ProcessExternalPayment handles callback from payment gateway
|
||||
func (s *order) ProcessExternalPayment(ctx context.Context, orderID, externalID string) error {
|
||||
oid := cast.ToInt64(orderID)
|
||||
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
|
||||
func (s *order) ProcessExternalPayment(ctx context.Context, orderID int64, externalID string) error {
|
||||
o, err := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(orderID)).First()
|
||||
if err != nil {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
@@ -347,20 +342,30 @@ func (s *order) settleOrder(ctx context.Context, o *models.Order, method, extern
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *order) Status(ctx context.Context, id string) (*transaction_dto.OrderStatusResponse, error) {
|
||||
return nil, nil
|
||||
func (s *order) Status(ctx context.Context, id int64) (*transaction_dto.OrderStatusResponse, error) {
|
||||
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) {
|
||||
dto := user_dto.Order{
|
||||
ID: cast.ToString(o.ID),
|
||||
ID: o.ID,
|
||||
Type: string(o.Type),
|
||||
TypeDescription: o.Type.Description(),
|
||||
Status: string(o.Status),
|
||||
StatusDescription: o.Status.Description(),
|
||||
Amount: float64(o.AmountPaid) / 100.0,
|
||||
CreateTime: o.CreatedAt.Format(time.RFC3339),
|
||||
TenantID: cast.ToString(o.TenantID),
|
||||
TenantID: o.TenantID,
|
||||
}
|
||||
|
||||
// Fetch Tenant Name
|
||||
@@ -385,10 +390,10 @@ func (s *order) composeOrderDTO(ctx context.Context, o *models.Order) (user_dto.
|
||||
|
||||
if err == nil {
|
||||
ci := transaction_dto.ContentItem{
|
||||
ID: cast.ToString(c.ID),
|
||||
ID: c.ID,
|
||||
Title: c.Title,
|
||||
Genre: c.Genre,
|
||||
AuthorID: cast.ToString(c.UserID),
|
||||
AuthorID: c.UserID,
|
||||
Price: float64(item.AmountPaid) / 100.0, // Use actual paid amount
|
||||
}
|
||||
// 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 {
|
||||
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
|
||||
Amount: float64(o.AmountPaid) / 100.0,
|
||||
CreateTime: o.CreatedAt.Format(time.RFC3339),
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -83,13 +82,13 @@ func (s *OrderTestSuite) Test_PurchaseFlow() {
|
||||
|
||||
Convey("should create and pay order successfully", func() {
|
||||
// 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)
|
||||
So(err, ShouldBeNil)
|
||||
So(createRes.OrderID, ShouldNotBeEmpty)
|
||||
|
||||
// Verify created status
|
||||
oid := cast.ToInt64(createRes.OrderID)
|
||||
oid := createRes.OrderID
|
||||
o, _ := models.OrderQuery.WithContext(ctx).Where(models.OrderQuery.ID.Eq(oid)).First()
|
||||
So(o.Status, ShouldEqual, consts.OrderStatusCreated)
|
||||
So(o.AmountPaid, ShouldEqual, 1000)
|
||||
@@ -130,7 +129,7 @@ func (s *OrderTestSuite) Test_PurchaseFlow() {
|
||||
Where(models.UserQuery.ID.Eq(buyer.ID)).
|
||||
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)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
@@ -201,7 +200,7 @@ func (s *OrderTestSuite) Test_OrderDetails() {
|
||||
createRes, _ := Order.Create(
|
||||
ctx,
|
||||
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"})
|
||||
|
||||
@@ -254,7 +253,7 @@ func (s *OrderTestSuite) Test_PlatformCommission() {
|
||||
|
||||
Convey("should deduct 10% fee", func() {
|
||||
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)
|
||||
|
||||
// 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})
|
||||
|
||||
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)
|
||||
|
||||
// Verify Status
|
||||
|
||||
@@ -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 {
|
||||
uid := cast.ToInt64(form.AdminUserID)
|
||||
uid := form.AdminUserID
|
||||
if _, err := models.UserQuery.WithContext(ctx).Where(models.UserQuery.ID.Eq(uid)).First(); err != nil {
|
||||
return errorx.ErrRecordNotFound.WithMsg("用户不存在")
|
||||
}
|
||||
@@ -331,7 +331,7 @@ func (s *super) ApproveWithdrawal(ctx context.Context, id int64) error {
|
||||
UpdatedAt: time.Now(),
|
||||
})
|
||||
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
|
||||
}
|
||||
@@ -381,7 +381,7 @@ func (s *super) RejectWithdrawal(ctx context.Context, id int64, reason string) e
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
@@ -3,15 +3,12 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"go.ipao.vip/gen/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -47,7 +44,7 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
|
||||
|
||||
cfg := t.Config.Data()
|
||||
data = append(data, dto.TenantProfile{
|
||||
ID: cast.ToString(t.ID),
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Avatar: cfg.Avatar,
|
||||
Bio: cfg.Bio,
|
||||
@@ -65,9 +62,8 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string) (*dto.TenantProfile, error) {
|
||||
tid := cast.ToInt64(id)
|
||||
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(tid)).First()
|
||||
func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id int64) (*dto.TenantProfile, error) {
|
||||
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, errorx.ErrRecordNotFound
|
||||
@@ -76,9 +72,9 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
|
||||
}
|
||||
|
||||
// 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).
|
||||
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()
|
||||
|
||||
// Following status
|
||||
@@ -86,14 +82,13 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
|
||||
if userID > 0 {
|
||||
uid := userID
|
||||
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()
|
||||
}
|
||||
|
||||
cfg := t.Config.Data()
|
||||
fmt.Printf("DEBUG: Tenant Config: %+v\n", cfg)
|
||||
return &dto.TenantProfile{
|
||||
ID: cast.ToString(t.ID),
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Avatar: cfg.Avatar,
|
||||
Cover: cfg.Cover,
|
||||
@@ -107,21 +102,20 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id string)
|
||||
}, 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 {
|
||||
return errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
tid := cast.ToInt64(id)
|
||||
|
||||
// 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 {
|
||||
return errorx.ErrRecordNotFound
|
||||
}
|
||||
|
||||
tu := &models.TenantUser{
|
||||
TenantID: tid,
|
||||
TenantID: id,
|
||||
UserID: uid,
|
||||
Role: types.Array[consts.TenantUserRole]{consts.TenantUserRoleMember},
|
||||
Status: consts.UserStatusVerified,
|
||||
@@ -137,15 +131,14 @@ func (s *tenant) Follow(ctx context.Context, userID int64, id string) error {
|
||||
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 {
|
||||
return errorx.ErrUnauthorized
|
||||
}
|
||||
uid := userID
|
||||
tid := cast.ToInt64(id)
|
||||
|
||||
_, 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()
|
||||
if err != nil {
|
||||
return errorx.ErrDatabaseError.WithCause(err)
|
||||
@@ -182,7 +175,7 @@ func (s *tenant) ListFollowed(ctx context.Context, userID int64) ([]dto.TenantPr
|
||||
Count()
|
||||
|
||||
data = append(data, dto.TenantProfile{
|
||||
ID: cast.ToString(t.ID),
|
||||
ID: t.ID,
|
||||
Name: t.Name,
|
||||
Avatar: "",
|
||||
Stats: dto.Stats{
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -52,11 +51,11 @@ func (s *TenantTestSuite) Test_Follow() {
|
||||
models.TenantQuery.WithContext(ctx).Create(t)
|
||||
|
||||
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)
|
||||
|
||||
// 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(profile.IsFollowing, ShouldBeTrue)
|
||||
So(profile.Stats.Followers, ShouldEqual, 1)
|
||||
@@ -68,11 +67,11 @@ func (s *TenantTestSuite) Test_Follow() {
|
||||
So(list[0].Name, ShouldEqual, "Tenant A")
|
||||
|
||||
// Unfollow
|
||||
err = Tenant.Unfollow(ctx, u.ID, cast.ToString(t.ID))
|
||||
err = Tenant.Unfollow(ctx, u.ID, t.ID)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// 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(profile.IsFollowing, ShouldBeFalse)
|
||||
So(profile.Stats.Followers, ShouldEqual, 0)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"go.ipao.vip/gen/types"
|
||||
"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))
|
||||
for i, v := range list {
|
||||
result[i] = user_dto.Notification{
|
||||
ID: cast.ToString(v.ID),
|
||||
ID: v.ID,
|
||||
Type: v.Type,
|
||||
Title: v.Title,
|
||||
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 {
|
||||
return &auth_dto.User{
|
||||
ID: cast.ToString(u.ID),
|
||||
ID: u.ID,
|
||||
Phone: u.Phone,
|
||||
Nickname: u.Nickname,
|
||||
Avatar: u.Avatar,
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/spf13/cast"
|
||||
"github.com/stretchr/testify/suite"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.uber.org/dig"
|
||||
@@ -81,7 +80,7 @@ func (s *UserTestSuite) Test_Me() {
|
||||
// Create user
|
||||
phone := "13800138003"
|
||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
||||
userID := cast.ToInt64(resp.User.ID)
|
||||
userID := resp.User.ID
|
||||
|
||||
Convey("should return user profile", func() {
|
||||
// Mock context with user ID
|
||||
@@ -109,7 +108,7 @@ func (s *UserTestSuite) Test_Update() {
|
||||
|
||||
phone := "13800138004"
|
||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
||||
userID := cast.ToInt64(resp.User.ID)
|
||||
userID := resp.User.ID
|
||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
||||
|
||||
Convey("should update nickname and bio", func() {
|
||||
@@ -137,7 +136,7 @@ func (s *UserTestSuite) Test_RealName() {
|
||||
|
||||
phone := "13800138005"
|
||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
||||
userID := cast.ToInt64(resp.User.ID)
|
||||
userID := resp.User.ID
|
||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
||||
|
||||
Convey("should update realname status", func() {
|
||||
@@ -162,7 +161,7 @@ func (s *UserTestSuite) Test_GetNotifications() {
|
||||
|
||||
phone := "13800138006"
|
||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
||||
userID := cast.ToInt64(resp.User.ID)
|
||||
userID := resp.User.ID
|
||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
||||
|
||||
// Mock notifications
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"go.ipao.vip/gen/types"
|
||||
"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{
|
||||
ID: cast.ToString(o.ID),
|
||||
ID: o.ID,
|
||||
Title: title,
|
||||
Amount: float64(o.AmountPaid) / 100.0,
|
||||
Type: txType,
|
||||
@@ -98,13 +97,13 @@ func (s *wallet) Recharge(
|
||||
|
||||
// MOCK: Automatically pay for recharge order to close the loop
|
||||
// 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
|
||||
}
|
||||
|
||||
// Mock Pay Params
|
||||
return &user_dto.RechargeResponse{
|
||||
PayParams: "mock_paid_success",
|
||||
OrderID: cast.ToString(order.ID),
|
||||
OrderID: order.ID,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user