fix: stabilize backend tests

This commit is contained in:
2026-01-08 14:07:58 +08:00
parent 7f1d2e7cb3
commit edbb62449b
18 changed files with 281 additions and 147 deletions

View File

@@ -50,8 +50,8 @@ func (r *Routes) Register(router fiber.Router) {
r.contents.List,
Query[dto.SuperContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID/contents/:contentID/status -> contents.UpdateStatus")
router.Patch("/super/v1/tenants/:tenantID/contents/:contentID/status"[len(r.Path()):], Func3(
r.log.Debugf("Registering route: Patch /super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status -> contents.UpdateStatus")
router.Patch("/super/v1/tenants/:tenantID<int>/contents/:contentID<int>/status"[len(r.Path()):], Func3(
r.contents.UpdateStatus,
PathParam[int64]("tenantID"),
PathParam[int64]("contentID"),
@@ -63,8 +63,8 @@ func (r *Routes) Register(router fiber.Router) {
r.orders.List,
Query[dto.SuperOrderListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /super/v1/orders/:id -> orders.Get")
router.Get("/super/v1/orders/:id"[len(r.Path()):], DataFunc1(
r.log.Debugf("Registering route: Get /super/v1/orders/:id<int> -> orders.Get")
router.Get("/super/v1/orders/:id<int>"[len(r.Path()):], DataFunc1(
r.orders.Get,
PathParam[int64]("id"),
))
@@ -72,8 +72,8 @@ func (r *Routes) Register(router fiber.Router) {
router.Get("/super/v1/orders/statistics"[len(r.Path()):], DataFunc0(
r.orders.Statistics,
))
r.log.Debugf("Registering route: Post /super/v1/orders/:id/refund -> orders.Refund")
router.Post("/super/v1/orders/:id/refund"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Post /super/v1/orders/:id<int>/refund -> orders.Refund")
router.Post("/super/v1/orders/:id<int>/refund"[len(r.Path()):], Func2(
r.orders.Refund,
PathParam[int64]("id"),
Body[dto.SuperOrderRefundForm]("form"),
@@ -84,8 +84,8 @@ func (r *Routes) Register(router fiber.Router) {
r.tenants.List,
Query[dto.TenantListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /super/v1/tenants/:id -> tenants.Get")
router.Get("/super/v1/tenants/:id"[len(r.Path()):], DataFunc1(
r.log.Debugf("Registering route: Get /super/v1/tenants/:id<int> -> tenants.Get")
router.Get("/super/v1/tenants/:id<int>"[len(r.Path()):], DataFunc1(
r.tenants.Get,
PathParam[int64]("id"),
))
@@ -93,14 +93,14 @@ func (r *Routes) Register(router fiber.Router) {
router.Get("/super/v1/tenants/statuses"[len(r.Path()):], DataFunc0(
r.tenants.Statuses,
))
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id -> tenants.UpdateExpire")
router.Patch("/super/v1/tenants/:id"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id<int> -> tenants.UpdateExpire")
router.Patch("/super/v1/tenants/:id<int>"[len(r.Path()):], Func2(
r.tenants.UpdateExpire,
PathParam[int64]("id"),
Body[dto.TenantExpireUpdateForm]("form"),
))
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id/status -> tenants.UpdateStatus")
router.Patch("/super/v1/tenants/:id/status"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Patch /super/v1/tenants/:id<int>/status -> tenants.UpdateStatus")
router.Patch("/super/v1/tenants/:id<int>/status"[len(r.Path()):], Func2(
r.tenants.UpdateStatus,
PathParam[int64]("id"),
Body[dto.TenantStatusUpdateForm]("form"),
@@ -116,8 +116,8 @@ func (r *Routes) Register(router fiber.Router) {
r.users.List,
Query[dto.UserListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /super/v1/users/:id -> users.Get")
router.Get("/super/v1/users/:id"[len(r.Path()):], DataFunc1(
r.log.Debugf("Registering route: Get /super/v1/users/:id<int> -> users.Get")
router.Get("/super/v1/users/:id<int>"[len(r.Path()):], DataFunc1(
r.users.Get,
PathParam[int64]("id"),
))
@@ -129,14 +129,14 @@ func (r *Routes) Register(router fiber.Router) {
router.Get("/super/v1/users/statuses"[len(r.Path()):], DataFunc0(
r.users.Statuses,
))
r.log.Debugf("Registering route: Patch /super/v1/users/:id/roles -> users.UpdateRoles")
router.Patch("/super/v1/users/:id/roles"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Patch /super/v1/users/:id<int>/roles -> users.UpdateRoles")
router.Patch("/super/v1/users/:id<int>/roles"[len(r.Path()):], Func2(
r.users.UpdateRoles,
PathParam[int64]("id"),
Body[dto.UserRolesUpdateForm]("form"),
))
r.log.Debugf("Registering route: Patch /super/v1/users/:id/status -> users.UpdateStatus")
router.Patch("/super/v1/users/:id/status"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Patch /super/v1/users/:id<int>/status -> users.UpdateStatus")
router.Patch("/super/v1/users/:id<int>/status"[len(r.Path()):], Func2(
r.users.UpdateStatus,
PathParam[int64]("id"),
Body[dto.UserStatusUpdateForm]("form"),

View File

@@ -50,11 +50,11 @@ func (r *Routes) Name() string {
// Each route is registered with its corresponding controller action and parameter bindings.
func (r *Routes) Register(router fiber.Router) {
// Register routes for controller: Common
r.log.Debugf("Registering route: Delete /v1/media-assets/:id -> common.DeleteMediaAsset")
router.Delete("/v1/media-assets/:id"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Delete /v1/media-assets/:id<int> -> common.DeleteMediaAsset")
router.Delete("/v1/media-assets/:id<int>"[len(r.Path()):], Func2(
r.common.DeleteMediaAsset,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Delete /v1/upload/:uploadId -> common.AbortUpload")
router.Delete("/v1/upload/:uploadId"[len(r.Path()):], Func2(
@@ -99,69 +99,69 @@ func (r *Routes) Register(router fiber.Router) {
Body[dto.UploadPartForm]("form"),
))
// Register routes for controller: Content
r.log.Debugf("Registering route: Delete /v1/contents/:id/favorite -> content.RemoveFavorite")
router.Delete("/v1/contents/:id/favorite"[len(r.Path()):], Func1(
r.log.Debugf("Registering route: Delete /v1/contents/:id<int>/favorite -> content.RemoveFavorite")
router.Delete("/v1/contents/:id<int>/favorite"[len(r.Path()):], Func1(
r.content.RemoveFavorite,
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Delete /v1/contents/:id/like -> content.RemoveLike")
router.Delete("/v1/contents/:id/like"[len(r.Path()):], Func1(
r.log.Debugf("Registering route: Delete /v1/contents/:id<int>/like -> content.RemoveLike")
router.Delete("/v1/contents/:id<int>/like"[len(r.Path()):], Func1(
r.content.RemoveLike,
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /v1/contents -> content.List")
router.Get("/v1/contents"[len(r.Path()):], DataFunc1(
r.content.List,
Query[dto.ContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/contents/:id -> content.Get")
router.Get("/v1/contents/:id"[len(r.Path()):], DataFunc1(
r.log.Debugf("Registering route: Get /v1/contents/:id<int> -> content.Get")
router.Get("/v1/contents/:id<int>"[len(r.Path()):], DataFunc1(
r.content.Get,
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /v1/contents/:id/comments -> content.ListComments")
router.Get("/v1/contents/:id/comments"[len(r.Path()):], DataFunc2(
r.log.Debugf("Registering route: Get /v1/contents/:id<int>/comments -> content.ListComments")
router.Get("/v1/contents/:id<int>/comments"[len(r.Path()):], DataFunc2(
r.content.ListComments,
PathParam[string]("id"),
PathParam[int64]("id"),
QueryParam[int]("page"),
))
r.log.Debugf("Registering route: Get /v1/topics -> content.ListTopics")
router.Get("/v1/topics"[len(r.Path()):], DataFunc0(
r.content.ListTopics,
))
r.log.Debugf("Registering route: Post /v1/comments/:id/like -> content.LikeComment")
router.Post("/v1/comments/:id/like"[len(r.Path()):], Func1(
r.log.Debugf("Registering route: Post /v1/comments/:id<int>/like -> content.LikeComment")
router.Post("/v1/comments/:id<int>/like"[len(r.Path()):], Func1(
r.content.LikeComment,
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Post /v1/contents/:id/comments -> content.CreateComment")
router.Post("/v1/contents/:id/comments"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Post /v1/contents/:id<int>/comments -> content.CreateComment")
router.Post("/v1/contents/:id<int>/comments"[len(r.Path()):], Func2(
r.content.CreateComment,
PathParam[string]("id"),
PathParam[int64]("id"),
Body[dto.CommentCreateForm]("form"),
))
r.log.Debugf("Registering route: Post /v1/contents/:id/favorite -> content.AddFavorite")
router.Post("/v1/contents/:id/favorite"[len(r.Path()):], Func1(
r.log.Debugf("Registering route: Post /v1/contents/:id<int>/favorite -> content.AddFavorite")
router.Post("/v1/contents/:id<int>/favorite"[len(r.Path()):], Func1(
r.content.AddFavorite,
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Post /v1/contents/:id/like -> content.AddLike")
router.Post("/v1/contents/:id/like"[len(r.Path()):], Func1(
r.log.Debugf("Registering route: Post /v1/contents/:id<int>/like -> content.AddLike")
router.Post("/v1/contents/:id<int>/like"[len(r.Path()):], Func1(
r.content.AddLike,
PathParam[string]("id"),
PathParam[int64]("id"),
))
// Register routes for controller: Creator
r.log.Debugf("Registering route: Delete /v1/creator/contents/:id -> creator.DeleteContent")
router.Delete("/v1/creator/contents/:id"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Delete /v1/creator/contents/:id<int> -> creator.DeleteContent")
router.Delete("/v1/creator/contents/:id<int>"[len(r.Path()):], Func2(
r.creator.DeleteContent,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Delete /v1/creator/payout-accounts -> creator.RemovePayoutAccount")
router.Delete("/v1/creator/payout-accounts"[len(r.Path()):], Func2(
r.creator.RemovePayoutAccount,
Local[*models.User]("__ctx_user"),
QueryParam[string]("id"),
QueryParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /v1/creator/contents -> creator.ListContents")
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"),
Query[dto.CreatorContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/creator/contents/:id -> creator.GetContent")
router.Get("/v1/creator/contents/:id"[len(r.Path()):], DataFunc2(
r.log.Debugf("Registering route: Get /v1/creator/contents/:id<int> -> creator.GetContent")
router.Get("/v1/creator/contents/:id<int>"[len(r.Path()):], DataFunc2(
r.creator.GetContent,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /v1/creator/dashboard -> creator.Dashboard")
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"),
Body[dto.ContentCreateForm]("form"),
))
r.log.Debugf("Registering route: Post /v1/creator/orders/:id/refund -> creator.Refund")
router.Post("/v1/creator/orders/:id/refund"[len(r.Path()):], Func3(
r.log.Debugf("Registering route: Post /v1/creator/orders/:id<int>/refund -> creator.Refund")
router.Post("/v1/creator/orders/:id<int>/refund"[len(r.Path()):], Func3(
r.creator.Refund,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
Body[dto.RefundForm]("form"),
))
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"),
Body[dto.WithdrawForm]("form"),
))
r.log.Debugf("Registering route: Put /v1/creator/contents/:id -> creator.UpdateContent")
router.Put("/v1/creator/contents/:id"[len(r.Path()):], Func3(
r.log.Debugf("Registering route: Put /v1/creator/contents/:id<int> -> creator.UpdateContent")
router.Put("/v1/creator/contents/:id<int>"[len(r.Path()):], Func3(
r.creator.UpdateContent,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
Body[dto.ContentUpdateForm]("form"),
))
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"),
))
// Register routes for controller: Tenant
r.log.Debugf("Registering route: Delete /v1/tenants/:id/follow -> tenant.Unfollow")
router.Delete("/v1/tenants/:id/follow"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Delete /v1/tenants/:id<int>/follow -> tenant.Unfollow")
router.Delete("/v1/tenants/:id<int>/follow"[len(r.Path()):], Func2(
r.tenant.Unfollow,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /v1/creators/:id/contents -> tenant.ListContents")
router.Get("/v1/creators/:id/contents"[len(r.Path()):], DataFunc2(
r.log.Debugf("Registering route: Get /v1/creators/:id<int>/contents -> tenant.ListContents")
router.Get("/v1/creators/:id<int>/contents"[len(r.Path()):], DataFunc2(
r.tenant.ListContents,
PathParam[string]("id"),
PathParam[int64]("id"),
Query[dto.ContentListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/tenants -> tenant.List")
@@ -271,23 +271,23 @@ func (r *Routes) Register(router fiber.Router) {
r.tenant.List,
Query[dto.TenantListFilter]("filter"),
))
r.log.Debugf("Registering route: Get /v1/tenants/:id -> tenant.Get")
router.Get("/v1/tenants/:id"[len(r.Path()):], DataFunc2(
r.log.Debugf("Registering route: Get /v1/tenants/:id<int> -> tenant.Get")
router.Get("/v1/tenants/:id<int>"[len(r.Path()):], DataFunc2(
r.tenant.Get,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Post /v1/tenants/:id/follow -> tenant.Follow")
router.Post("/v1/tenants/:id/follow"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Post /v1/tenants/:id<int>/follow -> tenant.Follow")
router.Post("/v1/tenants/:id<int>/follow"[len(r.Path()):], Func2(
r.tenant.Follow,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
// Register routes for controller: Transaction
r.log.Debugf("Registering route: Get /v1/orders/:id/status -> transaction.Status")
router.Get("/v1/orders/:id/status"[len(r.Path()):], DataFunc1(
r.log.Debugf("Registering route: Get /v1/orders/:id<int>/status -> transaction.Status")
router.Get("/v1/orders/:id<int>/status"[len(r.Path()):], DataFunc1(
r.transaction.Status,
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Post /v1/orders -> transaction.Create")
router.Post("/v1/orders"[len(r.Path()):], DataFunc2(
@@ -295,11 +295,11 @@ func (r *Routes) Register(router fiber.Router) {
Local[*models.User]("__ctx_user"),
Body[dto.OrderCreateForm]("form"),
))
r.log.Debugf("Registering route: Post /v1/orders/:id/pay -> transaction.Pay")
router.Post("/v1/orders/:id/pay"[len(r.Path()):], DataFunc3(
r.log.Debugf("Registering route: Post /v1/orders/:id<int>/pay -> transaction.Pay")
router.Post("/v1/orders/:id<int>/pay"[len(r.Path()):], DataFunc3(
r.transaction.Pay,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
Body[dto.OrderPayForm]("form"),
))
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"),
))
// Register routes for controller: User
r.log.Debugf("Registering route: Delete /v1/me/favorites/:contentId -> user.RemoveFavorite")
router.Delete("/v1/me/favorites/:contentId"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Delete /v1/me/favorites/:contentId<int> -> user.RemoveFavorite")
router.Delete("/v1/me/favorites/:contentId<int>"[len(r.Path()):], Func2(
r.user.RemoveFavorite,
Local[*models.User]("__ctx_user"),
PathParam[string]("contentId"),
PathParam[int64]("contentId"),
))
r.log.Debugf("Registering route: Delete /v1/me/likes/:contentId -> user.RemoveLike")
router.Delete("/v1/me/likes/:contentId"[len(r.Path()):], Func2(
r.log.Debugf("Registering route: Delete /v1/me/likes/:contentId<int> -> user.RemoveLike")
router.Delete("/v1/me/likes/:contentId<int>"[len(r.Path()):], Func2(
r.user.RemoveLike,
Local[*models.User]("__ctx_user"),
PathParam[string]("contentId"),
PathParam[int64]("contentId"),
))
r.log.Debugf("Registering route: Get /v1/me -> user.Me")
router.Get("/v1/me"[len(r.Path()):], DataFunc1(
@@ -351,17 +351,6 @@ func (r *Routes) Register(router fiber.Router) {
r.user.Likes,
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")
router.Get("/v1/me/notifications"[len(r.Path()):], DataFunc3(
r.user.Notifications,
@@ -375,11 +364,11 @@ func (r *Routes) Register(router fiber.Router) {
Local[*models.User]("__ctx_user"),
QueryParam[string]("status"),
))
r.log.Debugf("Registering route: Get /v1/me/orders/:id -> user.GetOrder")
router.Get("/v1/me/orders/:id"[len(r.Path()):], DataFunc2(
r.log.Debugf("Registering route: Get /v1/me/orders/:id<int> -> user.GetOrder")
router.Get("/v1/me/orders/:id<int>"[len(r.Path()):], DataFunc2(
r.user.GetOrder,
Local[*models.User]("__ctx_user"),
PathParam[string]("id"),
PathParam[int64]("id"),
))
r.log.Debugf("Registering route: Get /v1/me/wallet -> user.Wallet")
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(
r.user.AddFavorite,
Local[*models.User]("__ctx_user"),
QueryParam[string]("contentId"),
QueryParam[int64]("contentId"),
))
r.log.Debugf("Registering route: Post /v1/me/likes -> user.AddLike")
router.Post("/v1/me/likes"[len(r.Path()):], Func2(
r.user.AddLike,
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")
router.Post("/v1/me/realname"[len(r.Path()):], Func2(