chore: stabilize lint and verify builds
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
|
||||
@@ -22,7 +23,11 @@ type Auth struct{}
|
||||
// @Success 200 {object} string "OTP sent"
|
||||
// @Bind form body
|
||||
func (a *Auth) SendOTP(ctx fiber.Ctx, form *dto.SendOTPForm) error {
|
||||
return services.User.SendOTP(ctx, form.Phone)
|
||||
if err := services.User.SendOTP(ctx, form.Phone); err != nil {
|
||||
return errorx.ErrOperationFailed.WithCause(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// @Router /v1/auth/login [post]
|
||||
@@ -35,5 +40,10 @@ func (a *Auth) SendOTP(ctx fiber.Ctx, form *dto.SendOTPForm) error {
|
||||
// @Success 200 {object} dto.LoginResponse
|
||||
// @Bind form body
|
||||
func (a *Auth) Login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
||||
return services.User.LoginWithOTP(ctx, 0, form.Phone, form.OTP)
|
||||
resp, err := services.User.LoginWithOTP(ctx, 0, form.Phone, form.OTP)
|
||||
if err != nil {
|
||||
return nil, errorx.ErrOperationFailed.WithCause(err)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package v1
|
||||
import (
|
||||
"mime/multipart"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/v1/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
@@ -36,6 +37,7 @@ func (c *Common) Upload(
|
||||
if form != nil {
|
||||
val = form.Type
|
||||
}
|
||||
|
||||
return services.Common.Upload(ctx, tenantID, user.ID, file, val)
|
||||
}
|
||||
|
||||
@@ -49,7 +51,12 @@ func (c *Common) Upload(
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.OptionsResponse
|
||||
func (c *Common) GetOptions(ctx fiber.Ctx) (*dto.OptionsResponse, error) {
|
||||
return services.Common.Options(ctx)
|
||||
resp, err := services.Common.Options(ctx)
|
||||
if err != nil {
|
||||
return nil, errorx.ErrOperationFailed.WithCause(err)
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// Check file hash for deduplication
|
||||
@@ -66,6 +73,7 @@ func (c *Common) GetOptions(ctx fiber.Ctx) (*dto.OptionsResponse, error) {
|
||||
// @Bind hash query
|
||||
func (c *Common) CheckHash(ctx fiber.Ctx, user *models.User, hash string) (*dto.UploadResult, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Common.CheckHash(ctx, tenantID, user.ID, hash)
|
||||
}
|
||||
|
||||
@@ -81,6 +89,7 @@ func (c *Common) CheckHash(ctx fiber.Ctx, user *models.User, hash string) (*dto.
|
||||
// @Bind form body
|
||||
func (c *Common) InitUpload(ctx fiber.Ctx, user *models.User, form *dto.UploadInitForm) (*dto.UploadInitResponse, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Common.InitUpload(ctx.Context(), tenantID, user.ID, form)
|
||||
}
|
||||
|
||||
@@ -98,6 +107,7 @@ func (c *Common) InitUpload(ctx fiber.Ctx, user *models.User, form *dto.UploadIn
|
||||
// @Bind form body
|
||||
func (c *Common) UploadPart(ctx fiber.Ctx, user *models.User, file *multipart.FileHeader, form *dto.UploadPartForm) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Common.UploadPart(ctx.Context(), tenantID, user.ID, file, form)
|
||||
}
|
||||
|
||||
@@ -113,6 +123,7 @@ func (c *Common) UploadPart(ctx fiber.Ctx, user *models.User, file *multipart.Fi
|
||||
// @Bind form body
|
||||
func (c *Common) CompleteUpload(ctx fiber.Ctx, user *models.User, form *dto.UploadCompleteForm) (*dto.UploadResult, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Common.CompleteUpload(ctx.Context(), tenantID, user.ID, form)
|
||||
}
|
||||
|
||||
@@ -126,9 +137,10 @@ func (c *Common) CompleteUpload(ctx fiber.Ctx, user *models.User, form *dto.Uplo
|
||||
// @Success 200 {string} string "OK"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind uploadId path
|
||||
func (c *Common) AbortUpload(ctx fiber.Ctx, user *models.User, uploadId string) error {
|
||||
func (c *Common) AbortUpload(ctx fiber.Ctx, user *models.User, uploadID string) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Common.AbortUpload(ctx.Context(), tenantID, user.ID, uploadId)
|
||||
|
||||
return services.Common.AbortUpload(ctx.Context(), tenantID, user.ID, uploadID)
|
||||
}
|
||||
|
||||
// @Router /v1/t/:tenantCode/media-assets/:id<int> [delete]
|
||||
@@ -143,6 +155,7 @@ func (c *Common) AbortUpload(ctx fiber.Ctx, user *models.User, uploadId string)
|
||||
// @Bind id path
|
||||
func (c *Common) DeleteMediaAsset(ctx fiber.Ctx, user *models.User, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Common.DeleteMediaAsset(ctx.Context(), tenantID, user.ID, id)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ func (c *Content) List(
|
||||
}
|
||||
filter.TenantID = &tenantID
|
||||
}
|
||||
|
||||
return services.Content.List(ctx, tenantID, filter)
|
||||
}
|
||||
|
||||
@@ -56,6 +57,7 @@ func (c *Content) List(
|
||||
func (c *Content) Get(ctx fiber.Ctx, id int64) (*dto.ContentDetail, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.Get(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
@@ -75,6 +77,7 @@ func (c *Content) Get(ctx fiber.Ctx, id int64) (*dto.ContentDetail, error) {
|
||||
func (c *Content) ListComments(ctx fiber.Ctx, id int64, page int) (*requests.Pager, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.ListComments(ctx, tenantID, uid, id, page)
|
||||
}
|
||||
|
||||
@@ -94,6 +97,7 @@ func (c *Content) ListComments(ctx fiber.Ctx, id int64, page int) (*requests.Pag
|
||||
func (c *Content) CreateComment(ctx fiber.Ctx, id int64, form *dto.CommentCreateForm) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.CreateComment(ctx, tenantID, uid, id, form)
|
||||
}
|
||||
|
||||
@@ -111,6 +115,7 @@ func (c *Content) CreateComment(ctx fiber.Ctx, id int64, form *dto.CommentCreate
|
||||
func (c *Content) LikeComment(ctx fiber.Ctx, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.LikeComment(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
@@ -125,6 +130,7 @@ func (c *Content) LikeComment(ctx fiber.Ctx, id int64) error {
|
||||
func (c *Content) AddLike(ctx fiber.Ctx, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.AddLike(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
@@ -139,6 +145,7 @@ func (c *Content) AddLike(ctx fiber.Ctx, id int64) error {
|
||||
func (c *Content) RemoveLike(ctx fiber.Ctx, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.RemoveLike(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
@@ -153,6 +160,7 @@ func (c *Content) RemoveLike(ctx fiber.Ctx, id int64) error {
|
||||
func (c *Content) AddFavorite(ctx fiber.Ctx, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.AddFavorite(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
@@ -167,6 +175,7 @@ func (c *Content) AddFavorite(ctx fiber.Ctx, id int64) error {
|
||||
func (c *Content) RemoveFavorite(ctx fiber.Ctx, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Content.RemoveFavorite(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
@@ -181,5 +190,6 @@ func (c *Content) RemoveFavorite(ctx fiber.Ctx, id int64) error {
|
||||
// @Success 200 {array} dto.Topic
|
||||
func (c *Content) ListTopics(ctx fiber.Ctx) ([]dto.Topic, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Content.ListTopics(ctx, tenantID)
|
||||
}
|
||||
|
||||
@@ -55,14 +55,15 @@ type Creator struct{}
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind id path
|
||||
// @Bind form body
|
||||
func (c *Creator) GrantCoupon(ctx fiber.Ctx, user *models.User, id int64, form *dto.CouponGrantForm) (string, error) {
|
||||
func (c *Creator) GrantCoupon(ctx fiber.Ctx, _ *models.User, id int64, form *dto.CouponGrantForm) (string, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
if form == nil {
|
||||
return "", errorx.ErrInvalidParameter.WithMsg("参数无效")
|
||||
}
|
||||
_, err := services.Coupon.Grant(ctx, tenantID, id, form.UserIDs)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errorx.ErrOperationFailed.WithCause(err)
|
||||
}
|
||||
|
||||
return "Granted", nil
|
||||
}
|
||||
|
||||
@@ -19,24 +19,14 @@ type OrderCreateResponse struct {
|
||||
}
|
||||
|
||||
type OrderPayForm struct {
|
||||
// Method 支付方式(alipay/balance)。
|
||||
Method string `json:"method"`
|
||||
}
|
||||
|
||||
type OrderPayResponse struct {
|
||||
// PayParams 支付参数(透传给前端)。
|
||||
PayParams string `json:"pay_params"`
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
type OrderStatusResponse struct {
|
||||
// Status 订单状态(unpaid/paid/completed 等)。
|
||||
Status string `json:"status"`
|
||||
}
|
||||
|
||||
// PaymentWebhookForm 支付回调参数。
|
||||
type PaymentWebhookForm struct {
|
||||
// OrderID 订单ID。
|
||||
OrderID int64 `json:"order_id"`
|
||||
// ExternalID 第三方支付流水号。
|
||||
ExternalID string `json:"external_id"`
|
||||
}
|
||||
|
||||
@@ -45,17 +45,15 @@ type Transaction struct {
|
||||
}
|
||||
|
||||
type RechargeForm struct {
|
||||
// Amount 充值金额(单位元)。
|
||||
Amount float64 `json:"amount"`
|
||||
// Method 充值方式(alipay)。
|
||||
Method string `json:"method"`
|
||||
// Code 充值码字符串(用于兑换余额)。
|
||||
Code string `json:"code"`
|
||||
}
|
||||
|
||||
type RechargeResponse struct {
|
||||
// PayParams 支付参数(透传给前端)。
|
||||
PayParams string `json:"pay_params"`
|
||||
// OrderID 充值订单ID。
|
||||
OrderID int64 `json:"order_id"`
|
||||
// Amount 充值金额(单位元)。
|
||||
Amount float64 `json:"amount"`
|
||||
}
|
||||
|
||||
type Order struct {
|
||||
|
||||
@@ -13,6 +13,7 @@ func getUserID(ctx fiber.Ctx) int64 {
|
||||
return user.ID
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -22,5 +23,6 @@ func getTenantID(ctx fiber.Ctx) int64 {
|
||||
return tenant.ID
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -180,11 +180,6 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
PathParam[int64]("id"),
|
||||
Body[dto.OrderPayForm]("form"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /v1/t/:tenantCode/webhook/payment/notify -> transaction.Webhook")
|
||||
router.Post("/v1/t/:tenantCode/webhook/payment/notify"[len(r.Path()):], DataFunc1(
|
||||
r.transaction.Webhook,
|
||||
Body[dto.PaymentWebhookForm]("form"),
|
||||
))
|
||||
// Register routes for controller: User
|
||||
r.log.Debugf("Registering route: Delete /v1/t/:tenantCode/me/favorites/:contentId<int> -> user.RemoveFavorite")
|
||||
router.Delete("/v1/t/:tenantCode/me/favorites/:contentId<int>"[len(r.Path()):], Func2(
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/providers/storage"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
@@ -27,30 +28,30 @@ type Storage struct {
|
||||
// @Success 200 {string} string "success"
|
||||
// @Bind expires query
|
||||
// @Bind sign query
|
||||
func (s *Storage) Upload(ctx fiber.Ctx, expires, sign string) (string, error) {
|
||||
func (storageHandler *Storage) Upload(ctx fiber.Ctx, expires, sign string) (string, error) {
|
||||
key := ctx.Params("*")
|
||||
if err := s.storage.Verify("PUT", key, expires, sign); err != nil {
|
||||
if err := storageHandler.storage.Verify("PUT", key, expires, sign); err != nil {
|
||||
return "", fiber.NewError(fiber.StatusForbidden, err.Error())
|
||||
}
|
||||
|
||||
// Save file
|
||||
localPath := s.storage.Config.LocalPath
|
||||
localPath := storageHandler.storage.Config.LocalPath
|
||||
if localPath == "" {
|
||||
localPath = "./storage"
|
||||
}
|
||||
fullPath := filepath.Join(localPath, key)
|
||||
if err := os.MkdirAll(filepath.Dir(fullPath), 0o755); err != nil {
|
||||
return "", err
|
||||
return "", errorx.ErrFileSystemError.WithCause(err)
|
||||
}
|
||||
|
||||
f, err := os.Create(fullPath)
|
||||
file, err := os.Create(fullPath)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errorx.ErrFileSystemError.WithCause(err)
|
||||
}
|
||||
defer f.Close()
|
||||
defer file.Close()
|
||||
|
||||
if _, err := io.Copy(f, ctx.Request().BodyStream()); err != nil {
|
||||
return "", err
|
||||
if _, err := io.Copy(file, ctx.Request().BodyStream()); err != nil {
|
||||
return "", errorx.ErrFileSystemError.WithCause(err)
|
||||
}
|
||||
|
||||
return "success", nil
|
||||
@@ -68,17 +69,21 @@ func (s *Storage) Upload(ctx fiber.Ctx, expires, sign string) (string, error) {
|
||||
// @Success 200 {file} file
|
||||
// @Bind expires query
|
||||
// @Bind sign query
|
||||
func (s *Storage) Download(ctx fiber.Ctx, expires, sign string) error {
|
||||
func (storageHandler *Storage) Download(ctx fiber.Ctx, expires, sign string) error {
|
||||
key := ctx.Params("*")
|
||||
if err := s.storage.Verify("GET", key, expires, sign); err != nil {
|
||||
if err := storageHandler.storage.Verify("GET", key, expires, sign); err != nil {
|
||||
return fiber.NewError(fiber.StatusForbidden, err.Error())
|
||||
}
|
||||
|
||||
localPath := s.storage.Config.LocalPath
|
||||
localPath := storageHandler.storage.Config.LocalPath
|
||||
if localPath == "" {
|
||||
localPath = "./storage"
|
||||
}
|
||||
fullPath := filepath.Join(localPath, key)
|
||||
|
||||
return ctx.SendFile(fullPath)
|
||||
if err := ctx.SendFile(fullPath); err != nil {
|
||||
return errorx.ErrFileSystemError.WithCause(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -38,5 +38,6 @@ func (t *Tenant) AcceptInvite(ctx fiber.Ctx, id int64, form *dto.TenantInviteAcc
|
||||
return errorx.ErrForbidden.WithMsg("租户不匹配")
|
||||
}
|
||||
userID := getUserID(ctx)
|
||||
|
||||
return services.Tenant.AcceptInvite(ctx, id, userID, form)
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ type Transaction struct{}
|
||||
func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.OrderCreateResponse, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Order.Create(ctx, tenantID, uid, form)
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ func (t *Transaction) Create(ctx fiber.Ctx, form *dto.OrderCreateForm) (*dto.Ord
|
||||
func (t *Transaction) Pay(ctx fiber.Ctx, id int64, form *dto.OrderPayForm) (*dto.OrderPayResponse, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Order.Pay(ctx, tenantID, uid, id, form)
|
||||
}
|
||||
|
||||
@@ -60,23 +62,6 @@ func (t *Transaction) Pay(ctx fiber.Ctx, id int64, form *dto.OrderPayForm) (*dto
|
||||
func (t *Transaction) Status(ctx fiber.Ctx, id int64) (*dto.OrderStatusResponse, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
uid := getUserID(ctx)
|
||||
|
||||
return services.Order.Status(ctx, tenantID, uid, id)
|
||||
}
|
||||
|
||||
// @Summary Payment Webhook
|
||||
// @Description Payment Webhook
|
||||
// @Tags Transaction
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param form body dto.PaymentWebhookForm true "Webhook Data"
|
||||
// @Success 200 {string} string "success"
|
||||
// @Router /v1/t/:tenantCode/webhook/payment/notify [post]
|
||||
// @Bind form body
|
||||
func (t *Transaction) Webhook(ctx fiber.Ctx, form *dto.PaymentWebhookForm) (string, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
err := services.Order.ProcessExternalPayment(ctx, tenantID, form.OrderID, form.ExternalID)
|
||||
if err != nil {
|
||||
return "fail", err
|
||||
}
|
||||
return "success", nil
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ type User struct{}
|
||||
// @Produce json
|
||||
// @Success 200 {object} auth_dto.User
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Me(ctx fiber.Ctx, user *models.User) (*auth_dto.User, error) {
|
||||
func (u *User) Me(_ fiber.Ctx, user *models.User) (*auth_dto.User, error) {
|
||||
return services.User.ToAuthUserDTO(user), nil
|
||||
}
|
||||
|
||||
@@ -41,7 +41,11 @@ func (u *User) Me(ctx fiber.Ctx, user *models.User) (*auth_dto.User, error) {
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind form body
|
||||
func (u *User) Update(ctx fiber.Ctx, user *models.User, form *dto.UserUpdate) error {
|
||||
return services.User.Update(ctx, user.ID, form)
|
||||
if err := services.User.Update(ctx, user.ID, form); err != nil {
|
||||
return errorx.ErrOperationFailed.WithCause(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Submit real-name authentication
|
||||
@@ -57,7 +61,11 @@ func (u *User) Update(ctx fiber.Ctx, user *models.User, form *dto.UserUpdate) er
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind form body
|
||||
func (u *User) RealName(ctx fiber.Ctx, user *models.User, form *dto.RealNameForm) error {
|
||||
return services.User.RealName(ctx, user.ID, form)
|
||||
if err := services.User.RealName(ctx, user.ID, form); err != nil {
|
||||
return errorx.ErrOperationFailed.WithCause(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get wallet balance and transactions
|
||||
@@ -72,6 +80,7 @@ func (u *User) RealName(ctx fiber.Ctx, user *models.User, form *dto.RealNameForm
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Wallet(ctx fiber.Ctx, user *models.User) (*dto.WalletResponse, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Wallet.GetWallet(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
@@ -89,6 +98,7 @@ func (u *User) Wallet(ctx fiber.Ctx, user *models.User) (*dto.WalletResponse, er
|
||||
// @Bind form body
|
||||
func (u *User) Recharge(ctx fiber.Ctx, user *models.User, form *dto.RechargeForm) (*dto.RechargeResponse, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Wallet.Recharge(ctx, tenantID, user.ID, form)
|
||||
}
|
||||
|
||||
@@ -106,6 +116,7 @@ func (u *User) Recharge(ctx fiber.Ctx, user *models.User, form *dto.RechargeForm
|
||||
// @Bind status query
|
||||
func (u *User) ListOrders(ctx fiber.Ctx, user *models.User, status string) ([]dto.Order, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Order.ListUserOrders(ctx, tenantID, user.ID, status)
|
||||
}
|
||||
|
||||
@@ -123,6 +134,7 @@ func (u *User) ListOrders(ctx fiber.Ctx, user *models.User, status string) ([]dt
|
||||
// @Bind id path
|
||||
func (u *User) GetOrder(ctx fiber.Ctx, user *models.User, id int64) (*dto.Order, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Order.GetUserOrder(ctx, tenantID, user.ID, id)
|
||||
}
|
||||
|
||||
@@ -138,6 +150,7 @@ func (u *User) GetOrder(ctx fiber.Ctx, user *models.User, id int64) (*dto.Order,
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Library(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Content.GetLibrary(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
@@ -153,6 +166,7 @@ func (u *User) Library(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, err
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Favorites(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Content.GetFavorites(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
@@ -168,9 +182,10 @@ func (u *User) Favorites(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, e
|
||||
// @Success 200 {string} string "Added"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind contentId query key(content_id)
|
||||
func (u *User) AddFavorite(ctx fiber.Ctx, user *models.User, contentId int64) error {
|
||||
func (u *User) AddFavorite(ctx fiber.Ctx, user *models.User, contentID int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Content.AddFavorite(ctx, tenantID, user.ID, contentId)
|
||||
|
||||
return services.Content.AddFavorite(ctx, tenantID, user.ID, contentID)
|
||||
}
|
||||
|
||||
// Remove from favorites
|
||||
@@ -185,9 +200,10 @@ func (u *User) AddFavorite(ctx fiber.Ctx, user *models.User, contentId int64) er
|
||||
// @Success 200 {string} string "Removed"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind contentId path
|
||||
func (u *User) RemoveFavorite(ctx fiber.Ctx, user *models.User, contentId int64) error {
|
||||
func (u *User) RemoveFavorite(ctx fiber.Ctx, user *models.User, contentID int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Content.RemoveFavorite(ctx, tenantID, user.ID, contentId)
|
||||
|
||||
return services.Content.RemoveFavorite(ctx, tenantID, user.ID, contentID)
|
||||
}
|
||||
|
||||
// Get liked contents
|
||||
@@ -202,6 +218,7 @@ func (u *User) RemoveFavorite(ctx fiber.Ctx, user *models.User, contentId int64)
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Likes(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Content.GetLikes(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
@@ -217,9 +234,10 @@ func (u *User) Likes(ctx fiber.Ctx, user *models.User) ([]dto.ContentItem, error
|
||||
// @Success 200 {string} string "Liked"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind contentId query key(content_id)
|
||||
func (u *User) AddLike(ctx fiber.Ctx, user *models.User, contentId int64) error {
|
||||
func (u *User) AddLike(ctx fiber.Ctx, user *models.User, contentID int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Content.AddLike(ctx, tenantID, user.ID, contentId)
|
||||
|
||||
return services.Content.AddLike(ctx, tenantID, user.ID, contentID)
|
||||
}
|
||||
|
||||
// Unlike content
|
||||
@@ -234,9 +252,10 @@ func (u *User) AddLike(ctx fiber.Ctx, user *models.User, contentId int64) error
|
||||
// @Success 200 {string} string "Unliked"
|
||||
// @Bind user local key(__ctx_user)
|
||||
// @Bind contentId path
|
||||
func (u *User) RemoveLike(ctx fiber.Ctx, user *models.User, contentId int64) error {
|
||||
func (u *User) RemoveLike(ctx fiber.Ctx, user *models.User, contentID int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
return services.Content.RemoveLike(ctx, tenantID, user.ID, contentId)
|
||||
|
||||
return services.Content.RemoveLike(ctx, tenantID, user.ID, contentID)
|
||||
}
|
||||
|
||||
// Get following tenants
|
||||
@@ -251,6 +270,7 @@ func (u *User) RemoveLike(ctx fiber.Ctx, user *models.User, contentId int64) err
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) Following(ctx fiber.Ctx, user *models.User) ([]dto.TenantProfile, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Tenant.ListFollowed(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
@@ -270,6 +290,7 @@ func (u *User) Following(ctx fiber.Ctx, user *models.User) ([]dto.TenantProfile,
|
||||
// @Bind page query
|
||||
func (u *User) Notifications(ctx fiber.Ctx, user *models.User, typeArg string, page int) (*requests.Pager, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Notification.List(ctx, tenantID, user.ID, page, typeArg)
|
||||
}
|
||||
|
||||
@@ -286,6 +307,7 @@ func (u *User) Notifications(ctx fiber.Ctx, user *models.User, typeArg string, p
|
||||
// @Bind id path
|
||||
func (u *User) MarkNotificationRead(ctx fiber.Ctx, user *models.User, id int64) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Notification.MarkRead(ctx, tenantID, user.ID, id)
|
||||
}
|
||||
|
||||
@@ -300,6 +322,7 @@ func (u *User) MarkNotificationRead(ctx fiber.Ctx, user *models.User, id int64)
|
||||
// @Bind user local key(__ctx_user)
|
||||
func (u *User) MarkAllNotificationsRead(ctx fiber.Ctx, user *models.User) error {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Notification.MarkAllRead(ctx, tenantID, user.ID)
|
||||
}
|
||||
|
||||
@@ -317,6 +340,7 @@ func (u *User) MarkAllNotificationsRead(ctx fiber.Ctx, user *models.User) error
|
||||
// @Bind status query
|
||||
func (u *User) MyCoupons(ctx fiber.Ctx, user *models.User, status string) ([]dto.UserCouponItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Coupon.ListUserCoupons(ctx, tenantID, user.ID, status)
|
||||
}
|
||||
|
||||
@@ -334,6 +358,7 @@ func (u *User) MyCoupons(ctx fiber.Ctx, user *models.User, status string) ([]dto
|
||||
// @Bind amount query
|
||||
func (u *User) AvailableCoupons(ctx fiber.Ctx, user *models.User, amount int64) ([]dto.UserCouponItem, error) {
|
||||
tenantID := getTenantID(ctx)
|
||||
|
||||
return services.Coupon.ListAvailable(ctx, tenantID, user.ID, amount)
|
||||
}
|
||||
|
||||
@@ -354,5 +379,6 @@ func (u *User) ReceiveCoupon(ctx fiber.Ctx, user *models.User, form *dto.CouponR
|
||||
if form == nil {
|
||||
return nil, errorx.ErrInvalidParameter.WithMsg("参数无效")
|
||||
}
|
||||
|
||||
return services.Coupon.Receive(ctx, tenantID, user.ID, form.CouponID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user