259 lines
6.8 KiB
Go
259 lines
6.8 KiB
Go
package v1
|
|
|
|
import (
|
|
"quyun/v2/app/http/v1/dto"
|
|
auth_dto "quyun/v2/app/http/v1/dto"
|
|
"quyun/v2/app/requests"
|
|
"quyun/v2/app/services"
|
|
|
|
"github.com/gofiber/fiber/v3"
|
|
)
|
|
|
|
// @provider
|
|
type User struct{}
|
|
|
|
// Get current user profile
|
|
//
|
|
// @Router /v1/me [get]
|
|
// @Summary Get user profile
|
|
// @Description Get current user profile
|
|
// @Tags UserCenter
|
|
// @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)
|
|
}
|
|
|
|
// Update user profile
|
|
//
|
|
// @Router /v1/me [put]
|
|
// @Summary Update user profile
|
|
// @Description Update user profile
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.UserUpdate true "Update form"
|
|
// @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)
|
|
}
|
|
|
|
// Submit real-name authentication
|
|
//
|
|
// @Router /v1/me/realname [post]
|
|
// @Summary Realname auth
|
|
// @Description Submit real-name authentication
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.RealNameForm true "Realname form"
|
|
// @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)
|
|
}
|
|
|
|
// Get wallet balance and transactions
|
|
//
|
|
// @Router /v1/me/wallet [get]
|
|
// @Summary Get wallet
|
|
// @Description Get wallet balance and transactions
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} dto.WalletResponse
|
|
func (u *User) Wallet(ctx fiber.Ctx) (*dto.WalletResponse, error) {
|
|
return services.Wallet.GetWallet(ctx)
|
|
}
|
|
|
|
// Recharge wallet
|
|
//
|
|
// @Router /v1/me/wallet/recharge [post]
|
|
// @Summary Recharge wallet
|
|
// @Description Recharge wallet
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param form body dto.RechargeForm true "Recharge form"
|
|
// @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)
|
|
}
|
|
|
|
// List user orders
|
|
//
|
|
// @Router /v1/me/orders [get]
|
|
// @Summary List orders
|
|
// @Description List user orders
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param status query string false "Status enum(all, unpaid, completed, refund)"
|
|
// @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)
|
|
}
|
|
|
|
// Get user order detail
|
|
//
|
|
// @Router /v1/me/orders/:id [get]
|
|
// @Summary Get order detail
|
|
// @Description Get user order detail
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "Order ID"
|
|
// @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)
|
|
}
|
|
|
|
// Get purchased content
|
|
//
|
|
// @Router /v1/me/library [get]
|
|
// @Summary Get library
|
|
// @Description Get purchased content
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} dto.ContentItem
|
|
func (u *User) Library(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
|
return services.Content.GetLibrary(ctx)
|
|
}
|
|
|
|
// Get favorites
|
|
//
|
|
// @Router /v1/me/favorites [get]
|
|
// @Summary Get favorites
|
|
// @Description Get favorites
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} dto.ContentItem
|
|
func (u *User) Favorites(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
|
return services.Content.GetFavorites(ctx)
|
|
}
|
|
|
|
// Add to favorites
|
|
//
|
|
// @Router /v1/me/favorites [post]
|
|
// @Summary Add favorite
|
|
// @Description Add to favorites
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param contentId query string true "Content ID"
|
|
// @Success 200 {string} string "Added"
|
|
// @Bind contentId query
|
|
func (u *User) AddFavorite(ctx fiber.Ctx, contentId string) error {
|
|
return services.Content.AddFavorite(ctx, contentId)
|
|
}
|
|
|
|
// Remove from favorites
|
|
//
|
|
// @Router /v1/me/favorites/:contentId [delete]
|
|
// @Summary Remove favorite
|
|
// @Description Remove from favorites
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param contentId path string true "Content ID"
|
|
// @Success 200 {string} string "Removed"
|
|
// @Bind contentId path
|
|
func (u *User) RemoveFavorite(ctx fiber.Ctx, contentId string) error {
|
|
return services.Content.RemoveFavorite(ctx, contentId)
|
|
}
|
|
|
|
// Get liked contents
|
|
//
|
|
// @Router /v1/me/likes [get]
|
|
// @Summary Get likes
|
|
// @Description Get liked contents
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} dto.ContentItem
|
|
func (u *User) Likes(ctx fiber.Ctx) ([]dto.ContentItem, error) {
|
|
return services.Content.GetLikes(ctx)
|
|
}
|
|
|
|
// Like content
|
|
//
|
|
// @Router /v1/me/likes [post]
|
|
// @Summary Like content
|
|
// @Description Like content
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param contentId query string true "Content ID"
|
|
// @Success 200 {string} string "Liked"
|
|
// @Bind contentId query
|
|
func (u *User) AddLike(ctx fiber.Ctx, contentId string) error {
|
|
return services.Content.AddLike(ctx, contentId)
|
|
}
|
|
|
|
// Unlike content
|
|
//
|
|
// @Router /v1/me/likes/:contentId [delete]
|
|
// @Summary Unlike content
|
|
// @Description Unlike content
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param contentId path string true "Content ID"
|
|
// @Success 200 {string} string "Unliked"
|
|
// @Bind contentId path
|
|
func (u *User) RemoveLike(ctx fiber.Ctx, contentId string) error {
|
|
return services.Content.RemoveLike(ctx, contentId)
|
|
}
|
|
|
|
// Get following tenants
|
|
//
|
|
// @Router /v1/me/following [get]
|
|
// @Summary Get following
|
|
// @Description Get following tenants
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {array} dto.TenantProfile
|
|
func (u *User) Following(ctx fiber.Ctx) ([]dto.TenantProfile, error) {
|
|
return services.Tenant.ListFollowed(ctx)
|
|
}
|
|
|
|
// Get notifications
|
|
//
|
|
// @Router /v1/me/notifications [get]
|
|
// @Summary Get notifications
|
|
// @Description Get notifications
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param type query string false "Type enum(all, system, order, audit, interaction)"
|
|
// @Param page query int false "Page number"
|
|
// @Success 200 {object} requests.Pager{items=[]dto.Notification}
|
|
// @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)
|
|
}
|
|
|
|
// List my coupons
|
|
//
|
|
// @Router /v1/me/coupons [get]
|
|
// @Summary List coupons
|
|
// @Description List my coupons
|
|
// @Tags UserCenter
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param status query string false "Status (unused, used, expired)"
|
|
// @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)
|
|
}
|