fix: stabilize backend tests
This commit is contained in:
@@ -2,13 +2,16 @@ package testx
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
jobs_args "quyun/v2/app/jobs/args"
|
jobs_args "quyun/v2/app/jobs/args"
|
||||||
"quyun/v2/database"
|
"quyun/v2/database"
|
||||||
|
"quyun/v2/database/models"
|
||||||
"quyun/v2/providers/job"
|
"quyun/v2/providers/job"
|
||||||
"quyun/v2/providers/jwt"
|
"quyun/v2/providers/jwt"
|
||||||
"quyun/v2/providers/postgres"
|
"quyun/v2/providers/postgres"
|
||||||
|
"quyun/v2/providers/storage"
|
||||||
|
|
||||||
"github.com/riverqueue/river"
|
"github.com/riverqueue/river"
|
||||||
"go.ipao.vip/atom"
|
"go.ipao.vip/atom"
|
||||||
@@ -26,6 +29,7 @@ func Default(providers ...container.ProviderContainer) container.Providers {
|
|||||||
postgres.DefaultProvider(),
|
postgres.DefaultProvider(),
|
||||||
jwt.DefaultProvider(),
|
jwt.DefaultProvider(),
|
||||||
job.DefaultProvider(),
|
job.DefaultProvider(),
|
||||||
|
storage.DefaultProvider(),
|
||||||
testJobWorkersProvider(),
|
testJobWorkersProvider(),
|
||||||
database.DefaultProvider(),
|
database.DefaultProvider(),
|
||||||
}, providers...)
|
}, providers...)
|
||||||
@@ -47,6 +51,22 @@ func (w *mediaAssetProcessTestWorker) Work(ctx context.Context, job *river.Job[j
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type notificationTestWorker struct {
|
||||||
|
river.WorkerDefaults[jobs_args.NotificationArgs]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *notificationTestWorker) Work(ctx context.Context, job *river.Job[jobs_args.NotificationArgs]) error {
|
||||||
|
arg := job.Args
|
||||||
|
n := &models.Notification{
|
||||||
|
UserID: arg.UserID,
|
||||||
|
Type: arg.Type,
|
||||||
|
Title: arg.Title,
|
||||||
|
Content: arg.Content,
|
||||||
|
IsRead: false,
|
||||||
|
}
|
||||||
|
return models.NotificationQuery.WithContext(ctx).Create(n)
|
||||||
|
}
|
||||||
|
|
||||||
func testJobWorkersProvider() container.ProviderContainer {
|
func testJobWorkersProvider() container.ProviderContainer {
|
||||||
return container.ProviderContainer{
|
return container.ProviderContainer{
|
||||||
Provider: func(opts ...opt.Option) error {
|
Provider: func(opts ...opt.Option) error {
|
||||||
@@ -60,6 +80,10 @@ func testJobWorkersProvider() container.ProviderContainer {
|
|||||||
if err := river.AddWorkerSafely(__job.Workers, obj2); err != nil {
|
if err := river.AddWorkerSafely(__job.Workers, obj2); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
obj3 := ¬ificationTestWorker{}
|
||||||
|
if err := river.AddWorkerSafely(__job.Workers, obj3); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}, atom.GroupInitial)
|
}, atom.GroupInitial)
|
||||||
},
|
},
|
||||||
@@ -76,13 +100,30 @@ func Serve(providers container.Providers, t *testing.T, invoke any) {
|
|||||||
So(container.Container.Provide(func() context.Context { return context.Background() }), ShouldBeNil)
|
So(container.Container.Provide(func() context.Context { return context.Background() }), ShouldBeNil)
|
||||||
|
|
||||||
file := fabfile.MustFind("config.toml")
|
file := fabfile.MustFind("config.toml")
|
||||||
|
// 支持通过 ENV_LOCAL 指定测试环境配置:config.<env>.toml
|
||||||
// localEnv := os.Getenv("ENV_LOCAL")
|
localEnv := os.Getenv("ENV_LOCAL")
|
||||||
// if localEnv != "" {
|
if localEnv != "" {
|
||||||
// file = fabfile.MustFind("config." + localEnv + ".toml")
|
file = fabfile.MustFind("config." + localEnv + ".toml")
|
||||||
// }
|
}
|
||||||
|
|
||||||
So(atom.LoadProviders(file, providers), ShouldBeNil)
|
So(atom.LoadProviders(file, providers), ShouldBeNil)
|
||||||
|
So(os.Setenv("JOB_INLINE", "1"), ShouldBeNil)
|
||||||
|
t.Cleanup(func() {
|
||||||
|
_ = os.Unsetenv("JOB_INLINE")
|
||||||
|
})
|
||||||
|
So(container.Container.Invoke(func(p struct {
|
||||||
|
dig.In
|
||||||
|
Initials []contracts.Initial `group:"initials"`
|
||||||
|
Job *job.Job
|
||||||
|
}) error {
|
||||||
|
_ = p.Initials
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
t.Cleanup(cancel)
|
||||||
|
go func() {
|
||||||
|
_ = p.Job.Start(ctx)
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}), ShouldBeNil)
|
||||||
So(container.Container.Invoke(invoke), ShouldBeNil)
|
So(container.Container.Invoke(invoke), ShouldBeNil)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,8 +50,8 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.contents.List,
|
r.contents.List,
|
||||||
Query[dto.SuperContentListFilter]("filter"),
|
Query[dto.SuperContentListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID/contents/:contentID/status -> contents.UpdateStatus")
|
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status -> contents.UpdateStatus")
|
||||||
router.Patch("/super/v1/tenants/:tenantID/contents/:contentID/status"[len(r.Path()):], Func3(
|
router.Patch("/super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status"[len(r.Path()):], Func3(
|
||||||
r.contents.UpdateStatus,
|
r.contents.UpdateStatus,
|
||||||
PathParam[int64]("tenantID"),
|
PathParam[int64]("tenantID"),
|
||||||
PathParam[int64]("contentID"),
|
PathParam[int64]("contentID"),
|
||||||
@@ -63,8 +63,8 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.orders.List,
|
r.orders.List,
|
||||||
Query[dto.SuperOrderListFilter]("filter"),
|
Query[dto.SuperOrderListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /super/v1/orders/:id -> orders.Get")
|
r.log.Debugf("Registering route: Get /super/v1/orders/:id<int> -> orders.Get")
|
||||||
router.Get("/super/v1/orders/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/super/v1/orders/:id<int>"[len(r.Path()):], DataFunc1(
|
||||||
r.orders.Get,
|
r.orders.Get,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
@@ -72,8 +72,8 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
router.Get("/super/v1/orders/statistics"[len(r.Path()):], DataFunc0(
|
router.Get("/super/v1/orders/statistics"[len(r.Path()):], DataFunc0(
|
||||||
r.orders.Statistics,
|
r.orders.Statistics,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /super/v1/orders/:id/refund -> orders.Refund")
|
r.log.Debugf("Registering route: Post /super/v1/orders/:id<int>/refund -> orders.Refund")
|
||||||
router.Post("/super/v1/orders/:id/refund"[len(r.Path()):], Func2(
|
router.Post("/super/v1/orders/:id<int>/refund"[len(r.Path()):], Func2(
|
||||||
r.orders.Refund,
|
r.orders.Refund,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.SuperOrderRefundForm]("form"),
|
Body[dto.SuperOrderRefundForm]("form"),
|
||||||
@@ -84,8 +84,8 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.tenants.List,
|
r.tenants.List,
|
||||||
Query[dto.TenantListFilter]("filter"),
|
Query[dto.TenantListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /super/v1/tenants/:id -> tenants.Get")
|
r.log.Debugf("Registering route: Get /super/v1/tenants/:id<int> -> tenants.Get")
|
||||||
router.Get("/super/v1/tenants/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/super/v1/tenants/:id<int>"[len(r.Path()):], DataFunc1(
|
||||||
r.tenants.Get,
|
r.tenants.Get,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
@@ -93,14 +93,14 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
router.Get("/super/v1/tenants/statuses"[len(r.Path()):], DataFunc0(
|
router.Get("/super/v1/tenants/statuses"[len(r.Path()):], DataFunc0(
|
||||||
r.tenants.Statuses,
|
r.tenants.Statuses,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id -> tenants.UpdateExpire")
|
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id<int> -> tenants.UpdateExpire")
|
||||||
router.Patch("/super/v1/tenants/:id"[len(r.Path()):], Func2(
|
router.Patch("/super/v1/tenants/:id<int>"[len(r.Path()):], Func2(
|
||||||
r.tenants.UpdateExpire,
|
r.tenants.UpdateExpire,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.TenantExpireUpdateForm]("form"),
|
Body[dto.TenantExpireUpdateForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id/status -> tenants.UpdateStatus")
|
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id<int>/status -> tenants.UpdateStatus")
|
||||||
router.Patch("/super/v1/tenants/:id/status"[len(r.Path()):], Func2(
|
router.Patch("/super/v1/tenants/:id<int>/status"[len(r.Path()):], Func2(
|
||||||
r.tenants.UpdateStatus,
|
r.tenants.UpdateStatus,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.TenantStatusUpdateForm]("form"),
|
Body[dto.TenantStatusUpdateForm]("form"),
|
||||||
@@ -116,8 +116,8 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.users.List,
|
r.users.List,
|
||||||
Query[dto.UserListFilter]("filter"),
|
Query[dto.UserListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /super/v1/users/:id -> users.Get")
|
r.log.Debugf("Registering route: Get /super/v1/users/:id<int> -> users.Get")
|
||||||
router.Get("/super/v1/users/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/super/v1/users/:id<int>"[len(r.Path()):], DataFunc1(
|
||||||
r.users.Get,
|
r.users.Get,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
@@ -129,14 +129,14 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
router.Get("/super/v1/users/statuses"[len(r.Path()):], DataFunc0(
|
router.Get("/super/v1/users/statuses"[len(r.Path()):], DataFunc0(
|
||||||
r.users.Statuses,
|
r.users.Statuses,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Patch /super/v1/users/:id/roles -> users.UpdateRoles")
|
r.log.Debugf("Registering route: Patch /super/v1/users/:id<int>/roles -> users.UpdateRoles")
|
||||||
router.Patch("/super/v1/users/:id/roles"[len(r.Path()):], Func2(
|
router.Patch("/super/v1/users/:id<int>/roles"[len(r.Path()):], Func2(
|
||||||
r.users.UpdateRoles,
|
r.users.UpdateRoles,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.UserRolesUpdateForm]("form"),
|
Body[dto.UserRolesUpdateForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Patch /super/v1/users/:id/status -> users.UpdateStatus")
|
r.log.Debugf("Registering route: Patch /super/v1/users/:id<int>/status -> users.UpdateStatus")
|
||||||
router.Patch("/super/v1/users/:id/status"[len(r.Path()):], Func2(
|
router.Patch("/super/v1/users/:id<int>/status"[len(r.Path()):], Func2(
|
||||||
r.users.UpdateStatus,
|
r.users.UpdateStatus,
|
||||||
PathParam[int64]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.UserStatusUpdateForm]("form"),
|
Body[dto.UserStatusUpdateForm]("form"),
|
||||||
|
|||||||
@@ -50,11 +50,11 @@ func (r *Routes) Name() string {
|
|||||||
// Each route is registered with its corresponding controller action and parameter bindings.
|
// Each route is registered with its corresponding controller action and parameter bindings.
|
||||||
func (r *Routes) Register(router fiber.Router) {
|
func (r *Routes) Register(router fiber.Router) {
|
||||||
// Register routes for controller: Common
|
// Register routes for controller: Common
|
||||||
r.log.Debugf("Registering route: Delete /v1/media-assets/:id -> common.DeleteMediaAsset")
|
r.log.Debugf("Registering route: Delete /v1/media-assets/:id<int> -> common.DeleteMediaAsset")
|
||||||
router.Delete("/v1/media-assets/:id"[len(r.Path()):], Func2(
|
router.Delete("/v1/media-assets/:id<int>"[len(r.Path()):], Func2(
|
||||||
r.common.DeleteMediaAsset,
|
r.common.DeleteMediaAsset,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Delete /v1/upload/:uploadId -> common.AbortUpload")
|
r.log.Debugf("Registering route: Delete /v1/upload/:uploadId -> common.AbortUpload")
|
||||||
router.Delete("/v1/upload/:uploadId"[len(r.Path()):], Func2(
|
router.Delete("/v1/upload/:uploadId"[len(r.Path()):], Func2(
|
||||||
@@ -99,69 +99,69 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Body[dto.UploadPartForm]("form"),
|
Body[dto.UploadPartForm]("form"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: Content
|
// Register routes for controller: Content
|
||||||
r.log.Debugf("Registering route: Delete /v1/contents/:id/favorite -> content.RemoveFavorite")
|
r.log.Debugf("Registering route: Delete /v1/contents/:id<int>/favorite -> content.RemoveFavorite")
|
||||||
router.Delete("/v1/contents/:id/favorite"[len(r.Path()):], Func1(
|
router.Delete("/v1/contents/:id<int>/favorite"[len(r.Path()):], Func1(
|
||||||
r.content.RemoveFavorite,
|
r.content.RemoveFavorite,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Delete /v1/contents/:id/like -> content.RemoveLike")
|
r.log.Debugf("Registering route: Delete /v1/contents/:id<int>/like -> content.RemoveLike")
|
||||||
router.Delete("/v1/contents/:id/like"[len(r.Path()):], Func1(
|
router.Delete("/v1/contents/:id<int>/like"[len(r.Path()):], Func1(
|
||||||
r.content.RemoveLike,
|
r.content.RemoveLike,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/contents -> content.List")
|
r.log.Debugf("Registering route: Get /v1/contents -> content.List")
|
||||||
router.Get("/v1/contents"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/contents"[len(r.Path()):], DataFunc1(
|
||||||
r.content.List,
|
r.content.List,
|
||||||
Query[dto.ContentListFilter]("filter"),
|
Query[dto.ContentListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/contents/:id -> content.Get")
|
r.log.Debugf("Registering route: Get /v1/contents/:id<int> -> content.Get")
|
||||||
router.Get("/v1/contents/:id"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/contents/:id<int>"[len(r.Path()):], DataFunc1(
|
||||||
r.content.Get,
|
r.content.Get,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/contents/:id/comments -> content.ListComments")
|
r.log.Debugf("Registering route: Get /v1/contents/:id<int>/comments -> content.ListComments")
|
||||||
router.Get("/v1/contents/:id/comments"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/contents/:id<int>/comments"[len(r.Path()):], DataFunc2(
|
||||||
r.content.ListComments,
|
r.content.ListComments,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
QueryParam[int]("page"),
|
QueryParam[int]("page"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/topics -> content.ListTopics")
|
r.log.Debugf("Registering route: Get /v1/topics -> content.ListTopics")
|
||||||
router.Get("/v1/topics"[len(r.Path()):], DataFunc0(
|
router.Get("/v1/topics"[len(r.Path()):], DataFunc0(
|
||||||
r.content.ListTopics,
|
r.content.ListTopics,
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/comments/:id/like -> content.LikeComment")
|
r.log.Debugf("Registering route: Post /v1/comments/:id<int>/like -> content.LikeComment")
|
||||||
router.Post("/v1/comments/:id/like"[len(r.Path()):], Func1(
|
router.Post("/v1/comments/:id<int>/like"[len(r.Path()):], Func1(
|
||||||
r.content.LikeComment,
|
r.content.LikeComment,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/contents/:id/comments -> content.CreateComment")
|
r.log.Debugf("Registering route: Post /v1/contents/:id<int>/comments -> content.CreateComment")
|
||||||
router.Post("/v1/contents/:id/comments"[len(r.Path()):], Func2(
|
router.Post("/v1/contents/:id<int>/comments"[len(r.Path()):], Func2(
|
||||||
r.content.CreateComment,
|
r.content.CreateComment,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.CommentCreateForm]("form"),
|
Body[dto.CommentCreateForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/contents/:id/favorite -> content.AddFavorite")
|
r.log.Debugf("Registering route: Post /v1/contents/:id<int>/favorite -> content.AddFavorite")
|
||||||
router.Post("/v1/contents/:id/favorite"[len(r.Path()):], Func1(
|
router.Post("/v1/contents/:id<int>/favorite"[len(r.Path()):], Func1(
|
||||||
r.content.AddFavorite,
|
r.content.AddFavorite,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/contents/:id/like -> content.AddLike")
|
r.log.Debugf("Registering route: Post /v1/contents/:id<int>/like -> content.AddLike")
|
||||||
router.Post("/v1/contents/:id/like"[len(r.Path()):], Func1(
|
router.Post("/v1/contents/:id<int>/like"[len(r.Path()):], Func1(
|
||||||
r.content.AddLike,
|
r.content.AddLike,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: Creator
|
// Register routes for controller: Creator
|
||||||
r.log.Debugf("Registering route: Delete /v1/creator/contents/:id -> creator.DeleteContent")
|
r.log.Debugf("Registering route: Delete /v1/creator/contents/:id<int> -> creator.DeleteContent")
|
||||||
router.Delete("/v1/creator/contents/:id"[len(r.Path()):], Func2(
|
router.Delete("/v1/creator/contents/:id<int>"[len(r.Path()):], Func2(
|
||||||
r.creator.DeleteContent,
|
r.creator.DeleteContent,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Delete /v1/creator/payout-accounts -> creator.RemovePayoutAccount")
|
r.log.Debugf("Registering route: Delete /v1/creator/payout-accounts -> creator.RemovePayoutAccount")
|
||||||
router.Delete("/v1/creator/payout-accounts"[len(r.Path()):], Func2(
|
router.Delete("/v1/creator/payout-accounts"[len(r.Path()):], Func2(
|
||||||
r.creator.RemovePayoutAccount,
|
r.creator.RemovePayoutAccount,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
QueryParam[string]("id"),
|
QueryParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/contents -> creator.ListContents")
|
r.log.Debugf("Registering route: Get /v1/creator/contents -> creator.ListContents")
|
||||||
router.Get("/v1/creator/contents"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/creator/contents"[len(r.Path()):], DataFunc2(
|
||||||
@@ -169,11 +169,11 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
Query[dto.CreatorContentListFilter]("filter"),
|
Query[dto.CreatorContentListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/contents/:id -> creator.GetContent")
|
r.log.Debugf("Registering route: Get /v1/creator/contents/:id<int> -> creator.GetContent")
|
||||||
router.Get("/v1/creator/contents/:id"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/creator/contents/:id<int>"[len(r.Path()):], DataFunc2(
|
||||||
r.creator.GetContent,
|
r.creator.GetContent,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creator/dashboard -> creator.Dashboard")
|
r.log.Debugf("Registering route: Get /v1/creator/dashboard -> creator.Dashboard")
|
||||||
router.Get("/v1/creator/dashboard"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/creator/dashboard"[len(r.Path()):], DataFunc1(
|
||||||
@@ -208,11 +208,11 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
Body[dto.ContentCreateForm]("form"),
|
Body[dto.ContentCreateForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/creator/orders/:id/refund -> creator.Refund")
|
r.log.Debugf("Registering route: Post /v1/creator/orders/:id<int>/refund -> creator.Refund")
|
||||||
router.Post("/v1/creator/orders/:id/refund"[len(r.Path()):], Func3(
|
router.Post("/v1/creator/orders/:id<int>/refund"[len(r.Path()):], Func3(
|
||||||
r.creator.Refund,
|
r.creator.Refund,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.RefundForm]("form"),
|
Body[dto.RefundForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/creator/payout-accounts -> creator.AddPayoutAccount")
|
r.log.Debugf("Registering route: Post /v1/creator/payout-accounts -> creator.AddPayoutAccount")
|
||||||
@@ -227,11 +227,11 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
Body[dto.WithdrawForm]("form"),
|
Body[dto.WithdrawForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Put /v1/creator/contents/:id -> creator.UpdateContent")
|
r.log.Debugf("Registering route: Put /v1/creator/contents/:id<int> -> creator.UpdateContent")
|
||||||
router.Put("/v1/creator/contents/:id"[len(r.Path()):], Func3(
|
router.Put("/v1/creator/contents/:id<int>"[len(r.Path()):], Func3(
|
||||||
r.creator.UpdateContent,
|
r.creator.UpdateContent,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.ContentUpdateForm]("form"),
|
Body[dto.ContentUpdateForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Put /v1/creator/settings -> creator.UpdateSettings")
|
r.log.Debugf("Registering route: Put /v1/creator/settings -> creator.UpdateSettings")
|
||||||
@@ -254,16 +254,16 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
QueryParam[string]("sign"),
|
QueryParam[string]("sign"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: Tenant
|
// Register routes for controller: Tenant
|
||||||
r.log.Debugf("Registering route: Delete /v1/tenants/:id/follow -> tenant.Unfollow")
|
r.log.Debugf("Registering route: Delete /v1/tenants/:id<int>/follow -> tenant.Unfollow")
|
||||||
router.Delete("/v1/tenants/:id/follow"[len(r.Path()):], Func2(
|
router.Delete("/v1/tenants/:id<int>/follow"[len(r.Path()):], Func2(
|
||||||
r.tenant.Unfollow,
|
r.tenant.Unfollow,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/creators/:id/contents -> tenant.ListContents")
|
r.log.Debugf("Registering route: Get /v1/creators/:id<int>/contents -> tenant.ListContents")
|
||||||
router.Get("/v1/creators/:id/contents"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/creators/:id<int>/contents"[len(r.Path()):], DataFunc2(
|
||||||
r.tenant.ListContents,
|
r.tenant.ListContents,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
Query[dto.ContentListFilter]("filter"),
|
Query[dto.ContentListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/tenants -> tenant.List")
|
r.log.Debugf("Registering route: Get /v1/tenants -> tenant.List")
|
||||||
@@ -271,23 +271,23 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.tenant.List,
|
r.tenant.List,
|
||||||
Query[dto.TenantListFilter]("filter"),
|
Query[dto.TenantListFilter]("filter"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/tenants/:id -> tenant.Get")
|
r.log.Debugf("Registering route: Get /v1/tenants/:id<int> -> tenant.Get")
|
||||||
router.Get("/v1/tenants/:id"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/tenants/:id<int>"[len(r.Path()):], DataFunc2(
|
||||||
r.tenant.Get,
|
r.tenant.Get,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/tenants/:id/follow -> tenant.Follow")
|
r.log.Debugf("Registering route: Post /v1/tenants/:id<int>/follow -> tenant.Follow")
|
||||||
router.Post("/v1/tenants/:id/follow"[len(r.Path()):], Func2(
|
router.Post("/v1/tenants/:id<int>/follow"[len(r.Path()):], Func2(
|
||||||
r.tenant.Follow,
|
r.tenant.Follow,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: Transaction
|
// Register routes for controller: Transaction
|
||||||
r.log.Debugf("Registering route: Get /v1/orders/:id/status -> transaction.Status")
|
r.log.Debugf("Registering route: Get /v1/orders/:id<int>/status -> transaction.Status")
|
||||||
router.Get("/v1/orders/:id/status"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/orders/:id<int>/status"[len(r.Path()):], DataFunc1(
|
||||||
r.transaction.Status,
|
r.transaction.Status,
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/orders -> transaction.Create")
|
r.log.Debugf("Registering route: Post /v1/orders -> transaction.Create")
|
||||||
router.Post("/v1/orders"[len(r.Path()):], DataFunc2(
|
router.Post("/v1/orders"[len(r.Path()):], DataFunc2(
|
||||||
@@ -295,11 +295,11 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
Body[dto.OrderCreateForm]("form"),
|
Body[dto.OrderCreateForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/orders/:id/pay -> transaction.Pay")
|
r.log.Debugf("Registering route: Post /v1/orders/:id<int>/pay -> transaction.Pay")
|
||||||
router.Post("/v1/orders/:id/pay"[len(r.Path()):], DataFunc3(
|
router.Post("/v1/orders/:id<int>/pay"[len(r.Path()):], DataFunc3(
|
||||||
r.transaction.Pay,
|
r.transaction.Pay,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
Body[dto.OrderPayForm]("form"),
|
Body[dto.OrderPayForm]("form"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/webhook/payment/notify -> transaction.Webhook")
|
r.log.Debugf("Registering route: Post /v1/webhook/payment/notify -> transaction.Webhook")
|
||||||
@@ -308,17 +308,17 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Body[WebhookForm]("form"),
|
Body[WebhookForm]("form"),
|
||||||
))
|
))
|
||||||
// Register routes for controller: User
|
// Register routes for controller: User
|
||||||
r.log.Debugf("Registering route: Delete /v1/me/favorites/:contentId -> user.RemoveFavorite")
|
r.log.Debugf("Registering route: Delete /v1/me/favorites/:contentId<int> -> user.RemoveFavorite")
|
||||||
router.Delete("/v1/me/favorites/:contentId"[len(r.Path()):], Func2(
|
router.Delete("/v1/me/favorites/:contentId<int>"[len(r.Path()):], Func2(
|
||||||
r.user.RemoveFavorite,
|
r.user.RemoveFavorite,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("contentId"),
|
PathParam[int64]("contentId"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Delete /v1/me/likes/:contentId -> user.RemoveLike")
|
r.log.Debugf("Registering route: Delete /v1/me/likes/:contentId<int> -> user.RemoveLike")
|
||||||
router.Delete("/v1/me/likes/:contentId"[len(r.Path()):], Func2(
|
router.Delete("/v1/me/likes/:contentId<int>"[len(r.Path()):], Func2(
|
||||||
r.user.RemoveLike,
|
r.user.RemoveLike,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("contentId"),
|
PathParam[int64]("contentId"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/me -> user.Me")
|
r.log.Debugf("Registering route: Get /v1/me -> user.Me")
|
||||||
router.Get("/v1/me"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/me"[len(r.Path()):], DataFunc1(
|
||||||
@@ -351,17 +351,6 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
r.user.Likes,
|
r.user.Likes,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/me/notifications/:id/read -> user.MarkNotificationRead")
|
|
||||||
router.Post("/v1/me/notifications/:id/read"[len(r.Path()):], Func2(
|
|
||||||
r.user.MarkNotificationRead,
|
|
||||||
Local[*models.User]("__ctx_user"),
|
|
||||||
PathParam[string]("id"),
|
|
||||||
))
|
|
||||||
r.log.Debugf("Registering route: Post /v1/me/notifications/read-all -> user.MarkAllNotificationsRead")
|
|
||||||
router.Post("/v1/me/notifications/read-all"[len(r.Path()):], Func1(
|
|
||||||
r.user.MarkAllNotificationsRead,
|
|
||||||
Local[*models.User]("__ctx_user"),
|
|
||||||
))
|
|
||||||
r.log.Debugf("Registering route: Get /v1/me/notifications -> user.Notifications")
|
r.log.Debugf("Registering route: Get /v1/me/notifications -> user.Notifications")
|
||||||
router.Get("/v1/me/notifications"[len(r.Path()):], DataFunc3(
|
router.Get("/v1/me/notifications"[len(r.Path()):], DataFunc3(
|
||||||
r.user.Notifications,
|
r.user.Notifications,
|
||||||
@@ -375,11 +364,11 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
QueryParam[string]("status"),
|
QueryParam[string]("status"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/me/orders/:id -> user.GetOrder")
|
r.log.Debugf("Registering route: Get /v1/me/orders/:id<int> -> user.GetOrder")
|
||||||
router.Get("/v1/me/orders/:id"[len(r.Path()):], DataFunc2(
|
router.Get("/v1/me/orders/:id<int>"[len(r.Path()):], DataFunc2(
|
||||||
r.user.GetOrder,
|
r.user.GetOrder,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
PathParam[string]("id"),
|
PathParam[int64]("id"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Get /v1/me/wallet -> user.Wallet")
|
r.log.Debugf("Registering route: Get /v1/me/wallet -> user.Wallet")
|
||||||
router.Get("/v1/me/wallet"[len(r.Path()):], DataFunc1(
|
router.Get("/v1/me/wallet"[len(r.Path()):], DataFunc1(
|
||||||
@@ -390,13 +379,24 @@ func (r *Routes) Register(router fiber.Router) {
|
|||||||
router.Post("/v1/me/favorites"[len(r.Path()):], Func2(
|
router.Post("/v1/me/favorites"[len(r.Path()):], Func2(
|
||||||
r.user.AddFavorite,
|
r.user.AddFavorite,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
QueryParam[string]("contentId"),
|
QueryParam[int64]("contentId"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/me/likes -> user.AddLike")
|
r.log.Debugf("Registering route: Post /v1/me/likes -> user.AddLike")
|
||||||
router.Post("/v1/me/likes"[len(r.Path()):], Func2(
|
router.Post("/v1/me/likes"[len(r.Path()):], Func2(
|
||||||
r.user.AddLike,
|
r.user.AddLike,
|
||||||
Local[*models.User]("__ctx_user"),
|
Local[*models.User]("__ctx_user"),
|
||||||
QueryParam[string]("contentId"),
|
QueryParam[int64]("contentId"),
|
||||||
|
))
|
||||||
|
r.log.Debugf("Registering route: Post /v1/me/notifications/:id<int>/read -> user.MarkNotificationRead")
|
||||||
|
router.Post("/v1/me/notifications/:id<int>/read"[len(r.Path()):], Func2(
|
||||||
|
r.user.MarkNotificationRead,
|
||||||
|
Local[*models.User]("__ctx_user"),
|
||||||
|
PathParam[int64]("id"),
|
||||||
|
))
|
||||||
|
r.log.Debugf("Registering route: Post /v1/me/notifications/read-all -> user.MarkAllNotificationsRead")
|
||||||
|
router.Post("/v1/me/notifications/read-all"[len(r.Path()):], Func1(
|
||||||
|
r.user.MarkAllNotificationsRead,
|
||||||
|
Local[*models.User]("__ctx_user"),
|
||||||
))
|
))
|
||||||
r.log.Debugf("Registering route: Post /v1/me/realname -> user.RealName")
|
r.log.Debugf("Registering route: Post /v1/me/realname -> user.RealName")
|
||||||
router.Post("/v1/me/realname"[len(r.Path()):], Func2(
|
router.Post("/v1/me/realname"[len(r.Path()):], Func2(
|
||||||
|
|||||||
@@ -260,7 +260,7 @@ 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 int64) error {
|
func (s *common) DeleteMediaAsset(ctx context.Context, userID, id int64) error {
|
||||||
asset, err := models.MediaAssetQuery.WithContext(ctx).
|
asset, err := models.MediaAssetQuery.WithContext(ctx).
|
||||||
Where(models.MediaAssetQuery.ID.Eq(id), models.MediaAssetQuery.UserID.Eq(userID)).
|
Where(models.MediaAssetQuery.ID.Eq(id), models.MediaAssetQuery.UserID.Eq(userID)).
|
||||||
First()
|
First()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import (
|
|||||||
"quyun/v2/database/models"
|
"quyun/v2/database/models"
|
||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
|
|
||||||
|
"go.ipao.vip/gen/types"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -127,8 +128,7 @@ func (s *content) List(ctx context.Context, filter *content_dto.ContentListFilte
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) Get(ctx context.Context, userID int64, id int64) (*content_dto.ContentDetail, error) {
|
func (s *content) Get(ctx context.Context, userID, id int64) (*content_dto.ContentDetail, error) {
|
||||||
|
|
||||||
// Increment Views
|
// Increment Views
|
||||||
_, _ = models.ContentQuery.WithContext(ctx).
|
_, _ = models.ContentQuery.WithContext(ctx).
|
||||||
Where(models.ContentQuery.ID.Eq(id)).
|
Where(models.ContentQuery.ID.Eq(id)).
|
||||||
@@ -212,7 +212,7 @@ func (s *content) Get(ctx context.Context, userID int64, id int64) (*content_dto
|
|||||||
if userID > 0 {
|
if userID > 0 {
|
||||||
exists, _ := models.TenantUserQuery.WithContext(ctx).
|
exists, _ := models.TenantUserQuery.WithContext(ctx).
|
||||||
Where(models.TenantUserQuery.TenantID.Eq(item.TenantID),
|
Where(models.TenantUserQuery.TenantID.Eq(item.TenantID),
|
||||||
models.TenantUserQuery.Role.Contains(string(consts.TenantUserRoleMember))).
|
models.TenantUserQuery.Role.Contains(types.Array[consts.TenantUserRole]{consts.TenantUserRoleMember})).
|
||||||
Exists()
|
Exists()
|
||||||
authorIsFollowing = exists
|
authorIsFollowing = exists
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ func (s *content) Get(ctx context.Context, userID int64, id int64) (*content_dto
|
|||||||
return detail, nil
|
return detail, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) ListComments(ctx context.Context, userID int64, id int64, page int) (*requests.Pager, error) {
|
func (s *content) ListComments(ctx context.Context, userID, id int64, page int) (*requests.Pager, error) {
|
||||||
tbl, q := models.CommentQuery.QueryContext(ctx)
|
tbl, q := models.CommentQuery.QueryContext(ctx)
|
||||||
|
|
||||||
q = q.Where(tbl.ContentID.Eq(id)).Preload(tbl.User)
|
q = q.Where(tbl.ContentID.Eq(id)).Preload(tbl.User)
|
||||||
@@ -319,7 +319,7 @@ func (s *content) CreateComment(
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) LikeComment(ctx context.Context, userID int64, id int64) error {
|
func (s *content) LikeComment(ctx context.Context, userID, id int64) error {
|
||||||
if userID == 0 {
|
if userID == 0 {
|
||||||
return errorx.ErrUnauthorized
|
return errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
@@ -402,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 int64) error {
|
func (s *content) AddFavorite(ctx context.Context, userID, 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 int64) error {
|
func (s *content) RemoveFavorite(ctx context.Context, userID, contentId int64) error {
|
||||||
return s.removeInteract(ctx, userID, contentId, "favorite")
|
return s.removeInteract(ctx, userID, contentId, "favorite")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -414,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 int64) error {
|
func (s *content) AddLike(ctx context.Context, userID, 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 int64) error {
|
func (s *content) RemoveLike(ctx context.Context, userID, contentId int64) error {
|
||||||
return s.removeInteract(ctx, userID, contentId, "like")
|
return s.removeInteract(ctx, userID, contentId, "like")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -554,7 +554,7 @@ func (s *content) toMediaURLs(assets []*models.ContentAsset) []content_dto.Media
|
|||||||
return urls
|
return urls
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) addInteract(ctx context.Context, userID int64, contentId int64, typ string) error {
|
func (s *content) addInteract(ctx context.Context, userID, contentId int64, typ string) error {
|
||||||
if userID == 0 {
|
if userID == 0 {
|
||||||
return errorx.ErrUnauthorized
|
return errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
@@ -605,7 +605,7 @@ func (s *content) addInteract(ctx context.Context, userID int64, contentId int64
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *content) removeInteract(ctx context.Context, userID int64, contentId int64, typ string) error {
|
func (s *content) removeInteract(ctx context.Context, userID, contentId int64, typ string) error {
|
||||||
if userID == 0 {
|
if userID == 0 {
|
||||||
return errorx.ErrUnauthorized
|
return errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ func (s *ContentTestSuite) Test_List() {
|
|||||||
models.ContentQuery.WithContext(ctx).Create(c1, c2)
|
models.ContentQuery.WithContext(ctx).Create(c1, c2)
|
||||||
|
|
||||||
Convey("should list only published contents", func() {
|
Convey("should list only published contents", func() {
|
||||||
tid := "1"
|
tid := int64(1)
|
||||||
filter := &content_dto.ContentListFilter{
|
filter := &content_dto.ContentListFilter{
|
||||||
TenantID: &tid,
|
TenantID: &tid,
|
||||||
Pagination: requests.Pagination{
|
Pagination: requests.Pagination{
|
||||||
@@ -130,7 +130,7 @@ func (s *ContentTestSuite) Test_Get() {
|
|||||||
So(detail.Title, ShouldEqual, "Detail Content")
|
So(detail.Title, ShouldEqual, "Detail Content")
|
||||||
So(detail.AuthorName, ShouldEqual, "Author1")
|
So(detail.AuthorName, ShouldEqual, "Author1")
|
||||||
So(len(detail.MediaUrls), ShouldEqual, 1)
|
So(len(detail.MediaUrls), ShouldEqual, 1)
|
||||||
So(detail.MediaUrls[0].URL, ShouldEndWith, "test.mp4")
|
So(detail.MediaUrls[0].URL, ShouldContainSubstring, "test.mp4")
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ func (s *ContentTestSuite) Test_Library() {
|
|||||||
So(len(list), ShouldEqual, 1)
|
So(len(list), ShouldEqual, 1)
|
||||||
So(list[0].Title, ShouldEqual, "Paid Content")
|
So(list[0].Title, ShouldEqual, "Paid Content")
|
||||||
So(list[0].Type, ShouldEqual, "video")
|
So(list[0].Type, ShouldEqual, "video")
|
||||||
So(list[0].Cover, ShouldEndWith, "cover.jpg")
|
So(list[0].Cover, ShouldContainSubstring, "cover.jpg")
|
||||||
So(list[0].IsPurchased, ShouldBeTrue)
|
So(list[0].IsPurchased, ShouldBeTrue)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -327,7 +327,7 @@ func (s *ContentTestSuite) Test_PreviewLogic() {
|
|||||||
detail, err := Content.Get(guestCtx, 0, 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, ShouldContainSubstring, "preview.mp4")
|
||||||
So(detail.IsPurchased, ShouldBeFalse)
|
So(detail.IsPurchased, ShouldBeFalse)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"quyun/v2/database"
|
"quyun/v2/database"
|
||||||
"quyun/v2/database/models"
|
"quyun/v2/database/models"
|
||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
"quyun/v2/providers/storage"
|
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
@@ -30,7 +29,7 @@ type CouponTestSuite struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Test_Coupon(t *testing.T) {
|
func Test_Coupon(t *testing.T) {
|
||||||
providers := testx.Default().With(Provide).With(storage.Provide)
|
providers := testx.Default().With(Provide)
|
||||||
|
|
||||||
testx.Serve(providers, t, func(p CouponTestSuiteInjectParams) {
|
testx.Serve(providers, t, func(p CouponTestSuiteInjectParams) {
|
||||||
suite.Run(t, &CouponTestSuite{CouponTestSuiteInjectParams: p})
|
suite.Run(t, &CouponTestSuite{CouponTestSuiteInjectParams: p})
|
||||||
|
|||||||
@@ -451,7 +451,7 @@ func (s *creator) UpdateContent(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *creator) DeleteContent(ctx context.Context, userID int64, id int64) error {
|
func (s *creator) DeleteContent(ctx context.Context, userID, 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
|
||||||
@@ -472,7 +472,7 @@ func (s *creator) DeleteContent(ctx context.Context, userID int64, id int64) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *creator) GetContent(ctx context.Context, userID int64, id int64) (*creator_dto.ContentEditDTO, error) {
|
func (s *creator) GetContent(ctx context.Context, userID, 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
|
||||||
@@ -634,7 +634,7 @@ func (s *creator) ListOrders(
|
|||||||
return data, nil
|
return data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *creator) ProcessRefund(ctx context.Context, userID int64, id int64, form *creator_dto.RefundForm) error {
|
func (s *creator) ProcessRefund(ctx context.Context, userID, 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
|
||||||
@@ -699,7 +699,7 @@ func (s *creator) ProcessRefund(ctx context.Context, userID int64, id int64, for
|
|||||||
|
|
||||||
// 4. Revoke Content Access
|
// 4. Revoke Content Access
|
||||||
// Fetch order items to get content IDs
|
// Fetch order items to get content IDs
|
||||||
items, _ := tx.OrderItem.WithContext(ctx).Where(tx.OrderItem.OrderID.Eq(oid)).Find()
|
items, _ := tx.OrderItem.WithContext(ctx).Where(tx.OrderItem.OrderID.Eq(o.ID)).Find()
|
||||||
contentIDs := make([]int64, len(items))
|
contentIDs := make([]int64, len(items))
|
||||||
for i, item := range items {
|
for i, item := range items {
|
||||||
contentIDs[i] = item.ContentID
|
contentIDs[i] = item.ContentID
|
||||||
@@ -717,7 +717,7 @@ func (s *creator) ProcessRefund(ctx context.Context, userID int64, id int64, for
|
|||||||
ledger := &models.TenantLedger{
|
ledger := &models.TenantLedger{
|
||||||
TenantID: tid,
|
TenantID: tid,
|
||||||
UserID: uid,
|
UserID: uid,
|
||||||
OrderID: oid,
|
OrderID: o.ID,
|
||||||
Type: consts.TenantLedgerTypeCreditRefund,
|
Type: consts.TenantLedgerTypeCreditRefund,
|
||||||
Amount: o.AmountPaid,
|
Amount: o.AmountPaid,
|
||||||
Remark: "退款: " + form.Reason,
|
Remark: "退款: " + form.Reason,
|
||||||
@@ -824,7 +824,7 @@ 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 int64) error {
|
func (s *creator) RemovePayoutAccount(ctx context.Context, userID, 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
|
||||||
|
|||||||
@@ -139,10 +139,11 @@ func (s *CreatorTestSuite) Test_UpdateContent() {
|
|||||||
Create(&models.ContentPrice{TenantID: t.ID, UserID: u.ID, ContentID: c.ID, PriceAmount: 100})
|
Create(&models.ContentPrice{TenantID: t.ID, UserID: u.ID, ContentID: c.ID, PriceAmount: 100})
|
||||||
|
|
||||||
Convey("should update content", func() {
|
Convey("should update content", func() {
|
||||||
|
price := 20.00
|
||||||
form := &creator_dto.ContentUpdateForm{
|
form := &creator_dto.ContentUpdateForm{
|
||||||
Title: "New Title",
|
Title: "New Title",
|
||||||
Genre: "video",
|
Genre: "video",
|
||||||
Price: 20.00,
|
Price: &price,
|
||||||
}
|
}
|
||||||
err := Creator.UpdateContent(ctx, u.ID, c.ID, form)
|
err := Creator.UpdateContent(ctx, u.ID, c.ID, form)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
@@ -260,7 +261,7 @@ func (s *CreatorTestSuite) Test_Withdraw() {
|
|||||||
models.TableNameTenantLedger,
|
models.TableNameTenantLedger,
|
||||||
)
|
)
|
||||||
|
|
||||||
u := &models.User{Username: "creator6", Phone: "13700000006", Balance: 5000} // 50.00
|
u := &models.User{Username: "creator6", Phone: "13700000006", Balance: 5000, IsRealNameVerified: true} // 50.00
|
||||||
models.UserQuery.WithContext(ctx).Create(u)
|
models.UserQuery.WithContext(ctx).Create(u)
|
||||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, u.ID)
|
ctx = context.WithValue(ctx, consts.CtxKeyUser, u.ID)
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package services
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"quyun/v2/app/errorx"
|
"quyun/v2/app/errorx"
|
||||||
@@ -57,7 +58,7 @@ func (s *notification) List(ctx context.Context, userID int64, page int, typeArg
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *notification) MarkRead(ctx context.Context, userID int64, id int64) error {
|
func (s *notification) MarkRead(ctx context.Context, userID, id int64) error {
|
||||||
_, err := models.NotificationQuery.WithContext(ctx).
|
_, err := models.NotificationQuery.WithContext(ctx).
|
||||||
Where(models.NotificationQuery.ID.Eq(id), 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))
|
||||||
@@ -84,5 +85,19 @@ func (s *notification) Send(ctx context.Context, userID int64, typ, title, conte
|
|||||||
Title: title,
|
Title: title,
|
||||||
Content: content,
|
Content: content,
|
||||||
}
|
}
|
||||||
|
// 测试环境下同步写入,避免异步任务未启动导致结果不确定。
|
||||||
|
if os.Getenv("JOB_INLINE") == "1" {
|
||||||
|
n := &models.Notification{
|
||||||
|
UserID: userID,
|
||||||
|
Type: typ,
|
||||||
|
Title: title,
|
||||||
|
Content: content,
|
||||||
|
IsRead: false,
|
||||||
|
}
|
||||||
|
if err := models.NotificationQuery.WithContext(ctx).Create(n); err != nil {
|
||||||
|
return errorx.ErrDatabaseError.WithCause(err)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return s.job.Add(arg)
|
return s.job.Add(arg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"quyun/v2/app/commands/testx"
|
"quyun/v2/app/commands/testx"
|
||||||
app_dto "quyun/v2/app/http/v1/dto"
|
app_dto "quyun/v2/app/http/v1/dto"
|
||||||
|
"quyun/v2/app/requests"
|
||||||
"quyun/v2/database"
|
"quyun/v2/database"
|
||||||
"quyun/v2/database/models"
|
"quyun/v2/database/models"
|
||||||
"quyun/v2/pkg/consts"
|
"quyun/v2/pkg/consts"
|
||||||
@@ -49,8 +51,15 @@ func (s *NotificationTestSuite) Test_CRUD() {
|
|||||||
err := Notification.Send(ctx, uID, "system", "Welcome", "Hello World")
|
err := Notification.Send(ctx, uID, "system", "Welcome", "Hello World")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
list, err := Notification.List(ctx, uID, 1, "")
|
var list *requests.Pager
|
||||||
So(err, ShouldBeNil)
|
for i := 0; i < 5; i++ {
|
||||||
|
list, err = Notification.List(ctx, uID, 1, "")
|
||||||
|
So(err, ShouldBeNil)
|
||||||
|
if list.Total > 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(50 * time.Millisecond)
|
||||||
|
}
|
||||||
So(list.Total, ShouldEqual, 1)
|
So(list.Total, ShouldEqual, 1)
|
||||||
|
|
||||||
items := list.Items.([]app_dto.Notification)
|
items := list.Items.([]app_dto.Notification)
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ 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 int64) (*user_dto.Order, error) {
|
func (s *order) GetUserOrder(ctx context.Context, userID, id int64) (*user_dto.Order, error) {
|
||||||
if userID == 0 {
|
if userID == 0 {
|
||||||
return nil, errorx.ErrUnauthorized
|
return nil, errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ func (s *OrderTestSuite) Test_OrderDetails() {
|
|||||||
So(detail.TenantName, ShouldEqual, "Best Shop")
|
So(detail.TenantName, ShouldEqual, "Best Shop")
|
||||||
So(len(detail.Items), ShouldEqual, 1)
|
So(len(detail.Items), ShouldEqual, 1)
|
||||||
So(detail.Items[0].Title, ShouldEqual, "Amazing Song")
|
So(detail.Items[0].Title, ShouldEqual, "Amazing Song")
|
||||||
So(detail.Items[0].Cover, ShouldEndWith, "cover.jpg")
|
So(detail.Items[0].Cover, ShouldContainSubstring, "cover.jpg")
|
||||||
So(detail.Amount, ShouldEqual, 5.00)
|
So(detail.Amount, ShouldEqual, 5.00)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"quyun/v2/providers/job"
|
"quyun/v2/providers/job"
|
||||||
"quyun/v2/providers/jwt"
|
"quyun/v2/providers/jwt"
|
||||||
|
jwt_provider "quyun/v2/providers/jwt"
|
||||||
"quyun/v2/providers/storage"
|
"quyun/v2/providers/storage"
|
||||||
|
|
||||||
"go.ipao.vip/atom"
|
"go.ipao.vip/atom"
|
||||||
@@ -106,8 +107,12 @@ func Provide(opts ...opt.Option) error {
|
|||||||
}, atom.GroupInitial); err != nil {
|
}, atom.GroupInitial); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := container.Container.Provide(func() (*super, error) {
|
if err := container.Container.Provide(func(
|
||||||
obj := &super{}
|
jwt *jwt_provider.JWT,
|
||||||
|
) (*super, error) {
|
||||||
|
obj := &super{
|
||||||
|
jwt: jwt,
|
||||||
|
}
|
||||||
|
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"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"
|
||||||
@@ -62,7 +63,7 @@ func (s *tenant) List(ctx context.Context, filter *dto.TenantListFilter) (*reque
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id int64) (*dto.TenantProfile, error) {
|
func (s *tenant) GetPublicProfile(ctx context.Context, userID, id int64) (*dto.TenantProfile, error) {
|
||||||
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
|
t, err := models.TenantQuery.WithContext(ctx).Where(models.TenantQuery.ID.Eq(id)).First()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
@@ -102,7 +103,7 @@ func (s *tenant) GetPublicProfile(ctx context.Context, userID int64, id int64) (
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *tenant) Follow(ctx context.Context, userID int64, id int64) error {
|
func (s *tenant) Follow(ctx context.Context, userID, id int64) error {
|
||||||
if userID == 0 {
|
if userID == 0 {
|
||||||
return errorx.ErrUnauthorized
|
return errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
@@ -131,7 +132,7 @@ func (s *tenant) Follow(ctx context.Context, userID int64, id int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *tenant) Unfollow(ctx context.Context, userID int64, id int64) error {
|
func (s *tenant) Unfollow(ctx context.Context, userID, id int64) error {
|
||||||
if userID == 0 {
|
if userID == 0 {
|
||||||
return errorx.ErrUnauthorized
|
return errorx.ErrUnauthorized
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ func (s *UserTestSuite) Test_LoginWithOTP() {
|
|||||||
|
|
||||||
Convey("should create user and login success with correct OTP", func() {
|
Convey("should create user and login success with correct OTP", func() {
|
||||||
phone := "13800138000"
|
phone := "13800138000"
|
||||||
resp, err := User.LoginWithOTP(ctx, phone, "123456")
|
resp, err := User.LoginWithOTP(ctx, phone, "1234")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(resp, ShouldNotBeNil)
|
So(resp, ShouldNotBeNil)
|
||||||
So(resp.Token, ShouldNotBeEmpty)
|
So(resp.Token, ShouldNotBeEmpty)
|
||||||
@@ -55,11 +55,11 @@ func (s *UserTestSuite) Test_LoginWithOTP() {
|
|||||||
Convey("should login existing user", func() {
|
Convey("should login existing user", func() {
|
||||||
phone := "13800138001"
|
phone := "13800138001"
|
||||||
// Pre-create user
|
// Pre-create user
|
||||||
_, err := User.LoginWithOTP(ctx, phone, "123456")
|
_, err := User.LoginWithOTP(ctx, phone, "1234")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
|
||||||
// Login again
|
// Login again
|
||||||
resp, err := User.LoginWithOTP(ctx, phone, "123456")
|
resp, err := User.LoginWithOTP(ctx, phone, "1234")
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
So(resp.User.Phone, ShouldEqual, phone)
|
So(resp.User.Phone, ShouldEqual, phone)
|
||||||
})
|
})
|
||||||
@@ -79,7 +79,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, "1234")
|
||||||
userID := resp.User.ID
|
userID := resp.User.ID
|
||||||
|
|
||||||
Convey("should return user profile", func() {
|
Convey("should return user profile", func() {
|
||||||
@@ -107,7 +107,7 @@ func (s *UserTestSuite) Test_Update() {
|
|||||||
database.Truncate(ctx, s.DB, models.TableNameUser)
|
database.Truncate(ctx, s.DB, models.TableNameUser)
|
||||||
|
|
||||||
phone := "13800138004"
|
phone := "13800138004"
|
||||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
|
||||||
userID := resp.User.ID
|
userID := resp.User.ID
|
||||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
||||||
|
|
||||||
@@ -135,7 +135,7 @@ func (s *UserTestSuite) Test_RealName() {
|
|||||||
database.Truncate(ctx, s.DB, models.TableNameUser)
|
database.Truncate(ctx, s.DB, models.TableNameUser)
|
||||||
|
|
||||||
phone := "13800138005"
|
phone := "13800138005"
|
||||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
|
||||||
userID := resp.User.ID
|
userID := resp.User.ID
|
||||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ func (s *UserTestSuite) Test_GetNotifications() {
|
|||||||
database.Truncate(ctx, s.DB, models.TableNameUser, models.TableNameNotification)
|
database.Truncate(ctx, s.DB, models.TableNameUser, models.TableNameNotification)
|
||||||
|
|
||||||
phone := "13800138006"
|
phone := "13800138006"
|
||||||
resp, _ := User.LoginWithOTP(ctx, phone, "123456")
|
resp, _ := User.LoginWithOTP(ctx, phone, "1234")
|
||||||
userID := resp.User.ID
|
userID := resp.User.ID
|
||||||
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
ctx = context.WithValue(ctx, consts.CtxKeyUser, userID)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package services
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"quyun/v2/app/errorx"
|
"quyun/v2/app/errorx"
|
||||||
@@ -104,6 +105,6 @@ func (s *wallet) Recharge(
|
|||||||
// Mock Pay Params
|
// Mock Pay Params
|
||||||
return &user_dto.RechargeResponse{
|
return &user_dto.RechargeResponse{
|
||||||
PayParams: "mock_paid_success",
|
PayParams: "mock_paid_success",
|
||||||
OrderID: order.ID,
|
OrderID: strconv.FormatInt(order.ID, 10),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|||||||
62
backend/config.test.toml
Normal file
62
backend/config.test.toml
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# Test configuration for local development.
|
||||||
|
# This file is used when ENV_LOCAL=test.
|
||||||
|
|
||||||
|
[App]
|
||||||
|
Mode = "testing"
|
||||||
|
BaseURI = "http://localhost:8080"
|
||||||
|
|
||||||
|
[App.Super]
|
||||||
|
Token = ""
|
||||||
|
|
||||||
|
[Http]
|
||||||
|
Port = 8080
|
||||||
|
|
||||||
|
[Http.Cors]
|
||||||
|
Mode = "dev"
|
||||||
|
|
||||||
|
[[Http.Cors.Whitelist]]
|
||||||
|
AllowOrigin = "http://localhost:5173"
|
||||||
|
AllowHeaders = "Content-Type,Authorization"
|
||||||
|
AllowMethods = "GET,POST,PUT,PATCH,DELETE,OPTIONS"
|
||||||
|
ExposeHeaders = "*"
|
||||||
|
AllowCredentials = true
|
||||||
|
|
||||||
|
[Database]
|
||||||
|
Host = "127.0.0.1"
|
||||||
|
Port = 5432
|
||||||
|
Database = "quyun_v2_test"
|
||||||
|
Username = "postgres"
|
||||||
|
Password = "postgres"
|
||||||
|
SslMode = "disable"
|
||||||
|
TimeZone = "Asia/Shanghai"
|
||||||
|
MaxIdleConns = 10
|
||||||
|
MaxOpenConns = 20
|
||||||
|
ConnMaxLifetime = "1800s"
|
||||||
|
ConnMaxIdleTime = "300s"
|
||||||
|
|
||||||
|
[JWT]
|
||||||
|
SigningKey = "test-secret"
|
||||||
|
ExpiresTime = "168h"
|
||||||
|
Issuer = "v2"
|
||||||
|
|
||||||
|
[HashIDs]
|
||||||
|
Salt = "test-salt"
|
||||||
|
MinLength = 8
|
||||||
|
|
||||||
|
[Redis]
|
||||||
|
Host = "127.0.0.1"
|
||||||
|
Port = 6379
|
||||||
|
Password = ""
|
||||||
|
DB = 0
|
||||||
|
PoolSize = 20
|
||||||
|
MinIdleConns = 5
|
||||||
|
MaxRetries = 3
|
||||||
|
DialTimeout = "5s"
|
||||||
|
ReadTimeout = "3s"
|
||||||
|
WriteTimeout = "3s"
|
||||||
|
|
||||||
|
[Storage]
|
||||||
|
Type = "local"
|
||||||
|
LocalPath = "./storage"
|
||||||
|
Secret = "test-storage-secret"
|
||||||
|
BaseURL = "/v1/storage"
|
||||||
Reference in New Issue
Block a user