finish address-list 接口
This commit is contained in:
@@ -22,10 +22,15 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/user/fonts",
|
||||
Handler: UserFontsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/address-list",
|
||||
Handler: UserAddressListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/get-type",
|
||||
Handler: GetTypeHandler(serverCtx),
|
||||
Handler: UserGetTypeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserAddressListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, &types.Response{
|
||||
Code: 510,
|
||||
Message: "parameter error",
|
||||
})
|
||||
logx.Info(err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewUserAddressListLogic(r.Context(), svcCtx)
|
||||
resp := l.UserAddressList(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
err := errors.New("server logic is error, resp must not be nil")
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
logx.Error(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func GetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
func UserGetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
@@ -24,8 +24,8 @@ func GetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetTypeLogic(r.Context(), svcCtx)
|
||||
resp := l.GetType(&req)
|
||||
l := logic.NewUserGetTypeLogic(r.Context(), svcCtx)
|
||||
resp := l.UserGetType(&req)
|
||||
if resp != nil {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
} else {
|
||||
40
server/home-user-auth/internal/logic/useraddresslistlogic.go
Normal file
40
server/home-user-auth/internal/logic/useraddresslistlogic.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/model"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserAddressListLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserAddressListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddressListLogic {
|
||||
return &UserAddressListLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserAddressListLogic) UserAddressList(req *types.Request) (resp *types.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
m := model.NewFsAddressModel(l.svcCtx.MysqlConn)
|
||||
user := auth.GetUserInfoFormCtx(l.ctx)
|
||||
// model里设置了 返回值. 和 types 里的一至可以直接返回
|
||||
data, err := m.FindDataAddressList(l.ctx, user.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, data)
|
||||
}
|
||||
@@ -11,21 +11,22 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetTypeLogic struct {
|
||||
type UserGetTypeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTypeLogic {
|
||||
return &GetTypeLogic{
|
||||
func NewUserGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserGetTypeLogic {
|
||||
return &UserGetTypeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response) {
|
||||
func (l *UserGetTypeLogic) UserGetType(req *types.Request) (resp *types.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
data, err := model.NewFsCanteenTypeModel(l.svcCtx.MysqlConn).FindGetType(l.ctx)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
@@ -91,6 +91,21 @@ type DataStatusConfig struct {
|
||||
LogisticsStatus []KeyNameButton `json:"logistics_status"` //物流状态筛选项
|
||||
}
|
||||
|
||||
type DataAddressList struct {
|
||||
Id int64 `db:"id"`
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
Name string `db:"name"` // 地址名称
|
||||
FirstName string `db:"first_name"` // FirstName
|
||||
LastName string `db:"last_name"` // LastName
|
||||
Mobile string `db:"mobile"` // 手机号码
|
||||
Street string `db:"street"` // 街道
|
||||
Suite string `db:"suite"` // 房号
|
||||
City string `db:"city"` // 城市
|
||||
State string `db:"state"` // 州名
|
||||
ZipCode string `db:"zip_code"` // 邮编
|
||||
IsDefault int64 `db:"is_default"` // 1默认地址,0非默认地址
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"`
|
||||
Message string `json:"msg"`
|
||||
|
||||
Reference in New Issue
Block a user