Update mengyastore
This commit is contained in:
@@ -34,6 +34,15 @@ func (h *WishlistHandler) requireUser(c *gin.Context) (string, bool) {
|
||||
return result.User.Account, true
|
||||
}
|
||||
|
||||
// GetWishlist 当前用户收藏的商品 ID 列表。
|
||||
// @Summary 收藏列表
|
||||
// @Tags 收藏
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Success 200 {object} SwaggerWishlistWrap
|
||||
// @Failure 401 {object} SwaggerErrorBody
|
||||
// @Failure 500 {object} SwaggerErrorBody
|
||||
// @Router /api/wishlist [get]
|
||||
func (h *WishlistHandler) GetWishlist(c *gin.Context) {
|
||||
account, ok := h.requireUser(c)
|
||||
if !ok {
|
||||
@@ -47,16 +56,29 @@ func (h *WishlistHandler) GetWishlist(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"data": gin.H{"items": ids}})
|
||||
}
|
||||
|
||||
type wishlistItemPayload struct {
|
||||
// WishlistItemPayload 添加收藏请求体。
|
||||
type WishlistItemPayload struct {
|
||||
ProductID string `json:"productId"`
|
||||
}
|
||||
|
||||
// AddToWishlist 添加收藏。
|
||||
// @Summary 添加收藏
|
||||
// @Tags 收藏
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param body body WishlistItemPayload true "商品 ID"
|
||||
// @Success 200 {object} SwaggerWishlistWrap
|
||||
// @Failure 400 {object} SwaggerErrorBody
|
||||
// @Failure 401 {object} SwaggerErrorBody
|
||||
// @Failure 500 {object} SwaggerErrorBody
|
||||
// @Router /api/wishlist [post]
|
||||
func (h *WishlistHandler) AddToWishlist(c *gin.Context) {
|
||||
account, ok := h.requireUser(c)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
var payload wishlistItemPayload
|
||||
var payload WishlistItemPayload
|
||||
if err := c.ShouldBindJSON(&payload); err != nil || payload.ProductID == "" {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请求参数有误"})
|
||||
return
|
||||
@@ -69,6 +91,17 @@ func (h *WishlistHandler) AddToWishlist(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"data": gin.H{"items": ids}})
|
||||
}
|
||||
|
||||
// RemoveFromWishlist 按商品 ID 移除收藏。
|
||||
// @Summary 移除收藏
|
||||
// @Tags 收藏
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param id path string true "商品 ID"
|
||||
// @Success 200 {object} SwaggerWishlistWrap
|
||||
// @Failure 400 {object} SwaggerErrorBody
|
||||
// @Failure 401 {object} SwaggerErrorBody
|
||||
// @Failure 500 {object} SwaggerErrorBody
|
||||
// @Router /api/wishlist/{id} [delete]
|
||||
func (h *WishlistHandler) RemoveFromWishlist(c *gin.Context) {
|
||||
account, ok := h.requireUser(c)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user