You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
3.4 KiB

package global
import (
"shop-api/api/sys"
"shop-api/dto"
"shop-api/global"
"shop-api/model/request"
"shop-api/model/response"
"shop-api/service"
"github.com/gin-gonic/gin"
)
// @Summary 获取用户收货地址列表 [v1.0]
// @Security Bearer
// @Description
// @Tags 公用-收货地址
// @Success 200 {object} []model.Address "{"code": 0, "data": [...]}"
// @Success 200 {string} string "{"code": 1, "message": ""}"
// @Router /global/address [get]
func GetAddressList(c *gin.Context) {
var (
err error
userID string
req request.ReqAddress
data interface{}
)
c.ShouldBind(&req)
userID = sys.GetUserUuid(c)
err, data = service.GetUserAddressList(userID, &req)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(data, c)
}
// @Summary 添加收货地址 [v1.0]
// @Security Bearer
// @Description
// @Tags 公用-收货地址
// @Param data body dto.CreateAddressRequest false "data..."
// @Success 200 {string} string "{"code": 0, "data": [...]}"
// @Success 200 {string} string "{"code": 1, "message": ""}"
// @Router /global/address [post]
func AddAddress(c *gin.Context) {
var (
err error
userID string
data dto.CreateAddressRequest
)
err = c.ShouldBindJSON(&data)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
userID = sys.GetUserUuid(c)
err = service.AddUserAddressList(userID, &data)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("添加成功", c)
}
// @Summary 修改收货地址 [v1.0]
// @Security Bearer
// @Description
// @Tags 公用-收货地址
// @Param data body model.Address false "data..."
// @Success 200 {string} string "{"code": 0, "data": [...]}"
// @Success 200 {string} string "{"code": 1, "message": ""}"
// @Router /global/address [put]
func UpdateAddress(c *gin.Context) {
var (
err error
userID string
data dto.UpdateAddressRequest
)
err = c.ShouldBindJSON(&data)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
userID = sys.GetUserUuid(c)
err = service.UpdateAddress(userID, &data)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("修改成功", c)
}
// @Summary 删除收货地址 [v1.0]
// @Security Bearer
// @Description
// @Tags 公用-收货地址
// @Param data body global.BASE_ID false "data..."
// @Success 200 {string} string "{"code": 0, "data": [...]}"
// @Success 200 {string} string "{"code": 1, "message": ""}"
// @Router /global/address [delete]
func DeleteAddress(c *gin.Context) {
var (
err error
userID string
data global.BASE_ID
)
err = c.ShouldBindJSON(&data)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
userID = sys.GetUserUuid(c)
err = service.DeleteAddress(userID, &data)
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("删除成功", c)
}
// @Summary 美国地区选择器 [v1.0]
// @Security Bearer
// @Description
// @Tags 公用-收货地址
// @Success 200 {object} []model.UsSelect "{"code": 0, "data": [...]}"
// @Success 200 {string} string "{"code": 1, "message": ""}"
// @Router /global/usSelect [get]
func GetUsSelect(c *gin.Context) {
var (
err error
data interface{}
)
err, data = service.GetUsSelect()
if err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithData(data, c)
}