feat: Refactor user context handling and service methods
- Updated middleware to fetch user and tenant models by ID and set them in context. - Refactored common service methods to accept userID as a parameter instead of extracting from context. - Modified content service methods to include userID as a parameter for better clarity and performance. - Adjusted coupon, creator, notification, order, tenant, user, and wallet services to utilize userID directly. - Enhanced context key constants for improved readability and maintainability.
This commit is contained in:
@@ -5,8 +5,10 @@ import (
|
||||
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -30,5 +32,6 @@ func (c *Common) Upload(ctx fiber.Ctx, file *multipart.FileHeader, typeArg *stri
|
||||
if typeArg != nil {
|
||||
val = *typeArg
|
||||
}
|
||||
return services.Common.Upload(ctx, file, val)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Common.Upload(ctx.Context(), uid, file, val)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -45,7 +47,8 @@ func (c *Content) List(
|
||||
// @Success 200 {object} dto.ContentDetail
|
||||
// @Bind id path
|
||||
func (c *Content) Get(ctx fiber.Ctx, id string) (*dto.ContentDetail, error) {
|
||||
return services.Content.Get(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.Get(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// Get comments for a content
|
||||
@@ -62,7 +65,8 @@ func (c *Content) Get(ctx fiber.Ctx, id string) (*dto.ContentDetail, error) {
|
||||
// @Bind id path
|
||||
// @Bind page query
|
||||
func (c *Content) ListComments(ctx fiber.Ctx, id string, page int) (*requests.Pager, error) {
|
||||
return services.Content.ListComments(ctx, id, page)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.ListComments(ctx.Context(), uid, id, page)
|
||||
}
|
||||
|
||||
// Post a comment
|
||||
@@ -79,7 +83,8 @@ func (c *Content) ListComments(ctx fiber.Ctx, id string, page int) (*requests.Pa
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (c *Content) CreateComment(ctx fiber.Ctx, id string, form *dto.CommentCreateForm) error {
|
||||
return services.Content.CreateComment(ctx, id, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.CreateComment(ctx.Context(), uid, id, form)
|
||||
}
|
||||
|
||||
// Like a comment
|
||||
@@ -94,7 +99,8 @@ func (c *Content) CreateComment(ctx fiber.Ctx, id string, form *dto.CommentCreat
|
||||
// @Success 200 {string} string "Liked"
|
||||
// @Bind id path
|
||||
func (c *Content) LikeComment(ctx fiber.Ctx, id string) error {
|
||||
return services.Content.LikeComment(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.LikeComment(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// List curated topics
|
||||
|
||||
@@ -3,8 +3,10 @@ package v1
|
||||
import (
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -22,7 +24,8 @@ type Creator struct{}
|
||||
// @Success 200 {string} string "Application submitted"
|
||||
// @Bind form body
|
||||
func (c *Creator) Apply(ctx fiber.Ctx, form *dto.ApplyForm) error {
|
||||
return services.Creator.Apply(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.Apply(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// Get creator dashboard stats
|
||||
@@ -35,7 +38,8 @@ func (c *Creator) Apply(ctx fiber.Ctx, form *dto.ApplyForm) error {
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.DashboardStats
|
||||
func (c *Creator) Dashboard(ctx fiber.Ctx) (*dto.DashboardStats, error) {
|
||||
return services.Creator.Dashboard(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.Dashboard(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// List creator contents
|
||||
@@ -52,7 +56,8 @@ func (c *Creator) Dashboard(ctx fiber.Ctx) (*dto.DashboardStats, error) {
|
||||
// @Success 200 {array} dto.ContentItem
|
||||
// @Bind filter query
|
||||
func (c *Creator) ListContents(ctx fiber.Ctx, filter *dto.CreatorContentListFilter) ([]dto.ContentItem, error) {
|
||||
return services.Creator.ListContents(ctx, filter)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.ListContents(ctx.Context(), uid, filter)
|
||||
}
|
||||
|
||||
// Create/Publish content
|
||||
@@ -67,7 +72,8 @@ func (c *Creator) ListContents(ctx fiber.Ctx, filter *dto.CreatorContentListFilt
|
||||
// @Success 200 {string} string "Created"
|
||||
// @Bind form body
|
||||
func (c *Creator) CreateContent(ctx fiber.Ctx, form *dto.ContentCreateForm) error {
|
||||
return services.Creator.CreateContent(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.CreateContent(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// Update content
|
||||
@@ -84,7 +90,8 @@ func (c *Creator) CreateContent(ctx fiber.Ctx, form *dto.ContentCreateForm) erro
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (c *Creator) UpdateContent(ctx fiber.Ctx, id string, form *dto.ContentUpdateForm) error {
|
||||
return services.Creator.UpdateContent(ctx, id, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.UpdateContent(ctx.Context(), uid, id, form)
|
||||
}
|
||||
|
||||
// Delete content
|
||||
@@ -99,7 +106,8 @@ func (c *Creator) UpdateContent(ctx fiber.Ctx, id string, form *dto.ContentUpdat
|
||||
// @Success 200 {string} string "Deleted"
|
||||
// @Bind id path
|
||||
func (c *Creator) DeleteContent(ctx fiber.Ctx, id string) error {
|
||||
return services.Creator.DeleteContent(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.DeleteContent(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// List sales orders
|
||||
@@ -115,7 +123,8 @@ func (c *Creator) DeleteContent(ctx fiber.Ctx, id string) error {
|
||||
// @Success 200 {array} dto.Order
|
||||
// @Bind filter query
|
||||
func (c *Creator) ListOrders(ctx fiber.Ctx, filter *dto.CreatorOrderListFilter) ([]dto.Order, error) {
|
||||
return services.Creator.ListOrders(ctx, filter)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.ListOrders(ctx.Context(), uid, filter)
|
||||
}
|
||||
|
||||
// Process refund
|
||||
@@ -132,7 +141,8 @@ func (c *Creator) ListOrders(ctx fiber.Ctx, filter *dto.CreatorOrderListFilter)
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (c *Creator) Refund(ctx fiber.Ctx, id string, form *dto.RefundForm) error {
|
||||
return services.Creator.ProcessRefund(ctx, id, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.ProcessRefund(ctx.Context(), uid, id, form)
|
||||
}
|
||||
|
||||
// Get channel settings
|
||||
@@ -145,7 +155,8 @@ func (c *Creator) Refund(ctx fiber.Ctx, id string, form *dto.RefundForm) error {
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.Settings
|
||||
func (c *Creator) GetSettings(ctx fiber.Ctx) (*dto.Settings, error) {
|
||||
return services.Creator.GetSettings(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.GetSettings(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Update channel settings
|
||||
@@ -160,7 +171,8 @@ func (c *Creator) GetSettings(ctx fiber.Ctx) (*dto.Settings, error) {
|
||||
// @Success 200 {string} string "Updated"
|
||||
// @Bind form body
|
||||
func (c *Creator) UpdateSettings(ctx fiber.Ctx, form *dto.Settings) error {
|
||||
return services.Creator.UpdateSettings(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.UpdateSettings(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// List payout accounts
|
||||
@@ -173,7 +185,8 @@ func (c *Creator) UpdateSettings(ctx fiber.Ctx, form *dto.Settings) error {
|
||||
// @Produce json
|
||||
// @Success 200 {array} dto.PayoutAccount
|
||||
func (c *Creator) ListPayoutAccounts(ctx fiber.Ctx) ([]dto.PayoutAccount, error) {
|
||||
return services.Creator.ListPayoutAccounts(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.ListPayoutAccounts(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Add payout account
|
||||
@@ -188,7 +201,8 @@ func (c *Creator) ListPayoutAccounts(ctx fiber.Ctx) ([]dto.PayoutAccount, error)
|
||||
// @Success 200 {string} string "Added"
|
||||
// @Bind form body
|
||||
func (c *Creator) AddPayoutAccount(ctx fiber.Ctx, form *dto.PayoutAccount) error {
|
||||
return services.Creator.AddPayoutAccount(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.AddPayoutAccount(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// Remove payout account
|
||||
@@ -203,7 +217,8 @@ func (c *Creator) AddPayoutAccount(ctx fiber.Ctx, form *dto.PayoutAccount) error
|
||||
// @Success 200 {string} string "Removed"
|
||||
// @Bind id query
|
||||
func (c *Creator) RemovePayoutAccount(ctx fiber.Ctx, id string) error {
|
||||
return services.Creator.RemovePayoutAccount(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.RemovePayoutAccount(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// Request withdrawal
|
||||
@@ -218,5 +233,6 @@ func (c *Creator) RemovePayoutAccount(ctx fiber.Ctx, id string) error {
|
||||
// @Success 200 {string} string "Withdrawal requested"
|
||||
// @Bind form body
|
||||
func (c *Creator) Withdraw(ctx fiber.Ctx, form *dto.WithdrawForm) error {
|
||||
return services.Creator.Withdraw(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Creator.Withdraw(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"mime/multipart"
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/middlewares"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
@@ -222,8 +223,9 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
PathParam[string]("contentId"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /v1/me -> user.Me")
|
||||
router.Get("/v1/me"[len(r.Path()):], DataFunc0(
|
||||
router.Get("/v1/me"[len(r.Path()):], DataFunc1(
|
||||
r.user.Me,
|
||||
Local[*models.User]("__ctx_user"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /v1/me/coupons -> user.MyCoupons")
|
||||
router.Get("/v1/me/coupons"[len(r.Path()):], DataFunc1(
|
||||
|
||||
@@ -3,8 +3,10 @@ package v1
|
||||
import (
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -22,7 +24,8 @@ type Tenant struct{}
|
||||
// @Success 200 {object} dto.TenantProfile
|
||||
// @Bind id path
|
||||
func (t *Tenant) Get(ctx fiber.Ctx, id string) (*dto.TenantProfile, error) {
|
||||
return services.Tenant.GetPublicProfile(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Tenant.GetPublicProfile(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// Follow a tenant
|
||||
@@ -37,7 +40,8 @@ func (t *Tenant) Get(ctx fiber.Ctx, id string) (*dto.TenantProfile, error) {
|
||||
// @Success 200 {string} string "Followed"
|
||||
// @Bind id path
|
||||
func (t *Tenant) Follow(ctx fiber.Ctx, id string) error {
|
||||
return services.Tenant.Follow(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Tenant.Follow(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// Unfollow a tenant
|
||||
@@ -52,5 +56,6 @@ func (t *Tenant) Follow(ctx fiber.Ctx, id string) error {
|
||||
// @Success 200 {string} string "Unfollowed"
|
||||
// @Bind id path
|
||||
func (t *Tenant) Unfollow(ctx fiber.Ctx, id string) error {
|
||||
return services.Tenant.Unfollow(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Tenant.Unfollow(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package v1
|
||||
import (
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -22,7 +24,8 @@ type Transaction struct{}
|
||||
// @Success 200 {object} dto.OrderCreateResponse
|
||||
// @Bind form body
|
||||
func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.OrderCreateResponse, error) {
|
||||
return services.Order.Create(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Order.Create(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// Pay for order
|
||||
@@ -39,7 +42,8 @@ func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.Ord
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (t *Transaction) Pay(ctx fiber.Ctx, id string, form *dto.OrderPayForm) (*dto.OrderPayResponse, error) {
|
||||
return services.Order.Pay(ctx, id, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Order.Pay(ctx.Context(), uid, id, form)
|
||||
}
|
||||
|
||||
// Check order payment status
|
||||
|
||||
@@ -5,8 +5,11 @@ import (
|
||||
auth_dto "quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -21,8 +24,10 @@ type User struct{}
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} auth_dto.User
|
||||
func (u *User) Me(ctx fiber.Ctx) (*auth_dto.User, error) {
|
||||
return services.User.Me(ctx)
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Me(ctx fiber.Ctx, user *models.User) (*auth_dto.User, error) {
|
||||
// uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.User.ToAuthUserDTO(user), nil
|
||||
}
|
||||
|
||||
// Update user profile
|
||||
@@ -37,7 +42,8 @@ func (u *User) Me(ctx fiber.Ctx) (*auth_dto.User, error) {
|
||||
// @Success 200 {string} string "Updated"
|
||||
// @Bind form body
|
||||
func (u *User) Update(ctx fiber.Ctx, form *dto.UserUpdate) error {
|
||||
return services.User.Update(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.User.Update(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// Submit real-name authentication
|
||||
@@ -52,7 +58,8 @@ func (u *User) Update(ctx fiber.Ctx, form *dto.UserUpdate) error {
|
||||
// @Success 200 {string} string "Submitted"
|
||||
// @Bind form body
|
||||
func (u *User) RealName(ctx fiber.Ctx, form *dto.RealNameForm) error {
|
||||
return services.User.RealName(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.User.RealName(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// Get wallet balance and transactions
|
||||
@@ -65,7 +72,8 @@ func (u *User) RealName(ctx fiber.Ctx, form *dto.RealNameForm) error {
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.WalletResponse
|
||||
func (u *User) Wallet(ctx fiber.Ctx) (*dto.WalletResponse, error) {
|
||||
return services.Wallet.GetWallet(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Wallet.GetWallet(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Recharge wallet
|
||||
@@ -80,7 +88,8 @@ func (u *User) Wallet(ctx fiber.Ctx) (*dto.WalletResponse, error) {
|
||||
// @Success 200 {object} dto.RechargeResponse
|
||||
// @Bind form body
|
||||
func (u *User) Recharge(ctx fiber.Ctx, form *dto.RechargeForm) (*dto.RechargeResponse, error) {
|
||||
return services.Wallet.Recharge(ctx, form)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Wallet.Recharge(ctx.Context(), uid, form)
|
||||
}
|
||||
|
||||
// List user orders
|
||||
@@ -95,7 +104,8 @@ func (u *User) Recharge(ctx fiber.Ctx, form *dto.RechargeForm) (*dto.RechargeRes
|
||||
// @Success 200 {array} dto.Order
|
||||
// @Bind status query
|
||||
func (u *User) ListOrders(ctx fiber.Ctx, status string) ([]dto.Order, error) {
|
||||
return services.Order.ListUserOrders(ctx, status)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Order.ListUserOrders(ctx.Context(), uid, status)
|
||||
}
|
||||
|
||||
// Get user order detail
|
||||
@@ -110,7 +120,8 @@ func (u *User) ListOrders(ctx fiber.Ctx, status string) ([]dto.Order, error) {
|
||||
// @Success 200 {object} dto.Order
|
||||
// @Bind id path
|
||||
func (u *User) GetOrder(ctx fiber.Ctx, id string) (*dto.Order, error) {
|
||||
return services.Order.GetUserOrder(ctx, id)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Order.GetUserOrder(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
// Get purchased content
|
||||
@@ -123,7 +134,8 @@ func (u *User) GetOrder(ctx fiber.Ctx, id string) (*dto.Order, error) {
|
||||
// @Produce json
|
||||
// @Success 200 {array} dto.ContentItem
|
||||
func (u *User) Library(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
||||
return services.Content.GetLibrary(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.GetLibrary(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Get favorites
|
||||
@@ -136,7 +148,8 @@ func (u *User) Library(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
||||
// @Produce json
|
||||
// @Success 200 {array} dto.ContentItem
|
||||
func (u *User) Favorites(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
||||
return services.Content.GetFavorites(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.GetFavorites(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Add to favorites
|
||||
@@ -151,7 +164,8 @@ func (u *User) Favorites(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
||||
// @Success 200 {string} string "Added"
|
||||
// @Bind contentId query
|
||||
func (u *User) AddFavorite(ctx fiber.Ctx, contentId string) error {
|
||||
return services.Content.AddFavorite(ctx, contentId)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.AddFavorite(ctx.Context(), uid, contentId)
|
||||
}
|
||||
|
||||
// Remove from favorites
|
||||
@@ -166,7 +180,8 @@ func (u *User) AddFavorite(ctx fiber.Ctx, contentId string) error {
|
||||
// @Success 200 {string} string "Removed"
|
||||
// @Bind contentId path
|
||||
func (u *User) RemoveFavorite(ctx fiber.Ctx, contentId string) error {
|
||||
return services.Content.RemoveFavorite(ctx, contentId)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.RemoveFavorite(ctx.Context(), uid, contentId)
|
||||
}
|
||||
|
||||
// Get liked contents
|
||||
@@ -179,7 +194,8 @@ func (u *User) RemoveFavorite(ctx fiber.Ctx, contentId string) error {
|
||||
// @Produce json
|
||||
// @Success 200 {array} dto.ContentItem
|
||||
func (u *User) Likes(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
||||
return services.Content.GetLikes(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.GetLikes(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Like content
|
||||
@@ -194,7 +210,8 @@ func (u *User) Likes(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
||||
// @Success 200 {string} string "Liked"
|
||||
// @Bind contentId query
|
||||
func (u *User) AddLike(ctx fiber.Ctx, contentId string) error {
|
||||
return services.Content.AddLike(ctx, contentId)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.AddLike(ctx.Context(), uid, contentId)
|
||||
}
|
||||
|
||||
// Unlike content
|
||||
@@ -209,7 +226,8 @@ func (u *User) AddLike(ctx fiber.Ctx, contentId string) error {
|
||||
// @Success 200 {string} string "Unliked"
|
||||
// @Bind contentId path
|
||||
func (u *User) RemoveLike(ctx fiber.Ctx, contentId string) error {
|
||||
return services.Content.RemoveLike(ctx, contentId)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Content.RemoveLike(ctx.Context(), uid, contentId)
|
||||
}
|
||||
|
||||
// Get following tenants
|
||||
@@ -222,7 +240,8 @@ func (u *User) RemoveLike(ctx fiber.Ctx, contentId string) error {
|
||||
// @Produce json
|
||||
// @Success 200 {array} dto.TenantProfile
|
||||
func (u *User) Following(ctx fiber.Ctx) ([]dto.TenantProfile, error) {
|
||||
return services.Tenant.ListFollowed(ctx)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Tenant.ListFollowed(ctx.Context(), uid)
|
||||
}
|
||||
|
||||
// Get notifications
|
||||
@@ -239,7 +258,8 @@ func (u *User) Following(ctx fiber.Ctx) ([]dto.TenantProfile, error) {
|
||||
// @Bind typeArg query key(type)
|
||||
// @Bind page query
|
||||
func (u *User) Notifications(ctx fiber.Ctx, typeArg string, page int) (*requests.Pager, error) {
|
||||
return services.Notification.List(ctx, page, typeArg)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Notification.List(ctx.Context(), uid, page, typeArg)
|
||||
}
|
||||
|
||||
// List my coupons
|
||||
@@ -254,5 +274,6 @@ func (u *User) Notifications(ctx fiber.Ctx, typeArg string, page int) (*requests
|
||||
// @Success 200 {array} dto.UserCouponItem
|
||||
// @Bind status query
|
||||
func (u *User) MyCoupons(ctx fiber.Ctx, status string) ([]dto.UserCouponItem, error) {
|
||||
return services.Coupon.ListUserCoupons(ctx, status)
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Coupon.ListUserCoupons(ctx.Context(), uid, status)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user