feat: 更新用户上下文处理,服务方法显式接受用户参数,简化上下文调用
This commit is contained in:
@@ -3,10 +3,9 @@ package v1
|
||||
import (
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
// @provider
|
||||
@@ -22,9 +21,13 @@ type Tenant struct{}
|
||||
// @Produce json
|
||||
// @Param id path string true "Tenant ID"
|
||||
// @Success 200 {object} dto.TenantProfile
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
func (t *Tenant) Get(ctx fiber.Ctx, id string) (*dto.TenantProfile, error) {
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
func (t *Tenant) Get(ctx fiber.Ctx, user *models.User, id string) (*dto.TenantProfile, error) {
|
||||
uid := int64(0)
|
||||
if user != nil {
|
||||
uid = user.ID
|
||||
}
|
||||
return services.Tenant.GetPublicProfile(ctx.Context(), uid, id)
|
||||
}
|
||||
|
||||
@@ -38,10 +41,10 @@ func (t *Tenant) Get(ctx fiber.Ctx, id string) (*dto.TenantProfile, error) {
|
||||
// @Produce json
|
||||
// @Param id path string true "Tenant ID"
|
||||
// @Success 200 {string} string "Followed"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
func (t *Tenant) Follow(ctx fiber.Ctx, id string) error {
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Tenant.Follow(ctx.Context(), uid, id)
|
||||
func (t *Tenant) Follow(ctx fiber.Ctx, user *models.User, id string) error {
|
||||
return services.Tenant.Follow(ctx.Context(), user.ID, id)
|
||||
}
|
||||
|
||||
// Unfollow a tenant
|
||||
@@ -54,8 +57,8 @@ func (t *Tenant) Follow(ctx fiber.Ctx, id string) error {
|
||||
// @Produce json
|
||||
// @Param id path string true "Tenant ID"
|
||||
// @Success 200 {string} string "Unfollowed"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
func (t *Tenant) Unfollow(ctx fiber.Ctx, id string) error {
|
||||
uid := cast.ToInt64(ctx.Locals(consts.CtxKeyUser))
|
||||
return services.Tenant.Unfollow(ctx.Context(), uid, id)
|
||||
func (t *Tenant) Unfollow(ctx fiber.Ctx, user *models.User, id string) error {
|
||||
return services.Tenant.Unfollow(ctx.Context(), user.ID, id)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user