info get profile
This commit is contained in:
parent
31b712784f
commit
d92c77766c
|
@ -38,9 +38,15 @@ func FsBool(v bool) *bool {
|
|||
|
||||
// SubscriptionStatus 订阅状态
|
||||
type SubscriptionStatus struct {
|
||||
SubEmail bool `json:"all_emails"`
|
||||
ItemMap *struct {
|
||||
} `json:"item_map"`
|
||||
NotificationEmail *struct {
|
||||
OrderUpdate bool `json:"order_update"`
|
||||
Newseleter bool `json:"newseleter"`
|
||||
} `json:"notification_email"`
|
||||
|
||||
NotificationPhone *struct {
|
||||
OrderUpdate bool `json:"order_update"`
|
||||
Newseleter bool `json:"newseleter"`
|
||||
} `json:"notification_phone"`
|
||||
}
|
||||
|
||||
type UserProfile struct {
|
||||
|
@ -50,9 +56,9 @@ type UserProfile struct {
|
|||
|
||||
// UserProfileBase 个人信息
|
||||
type UserProfileBase struct {
|
||||
FirstName string `json:"first_name"` // 首名
|
||||
LastName string `json:"last_name"` // 后名
|
||||
UserName string `json:"user_name"` // 用户名
|
||||
FirstName string `json:"first_name"` // 首名
|
||||
LastName string `json:"last_name"` // 后名
|
||||
// UserName string `json:"user_name"` // 用户名
|
||||
Mobile string `json:"mobile"` // 电话
|
||||
Resetaurant string `json:"resetaurant"` // 不知道干什么
|
||||
Company string `json:"company"` // 公司
|
||||
|
|
|
@ -17,36 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/api/user/fonts",
|
||||
Handler: UserFontsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/get-type",
|
||||
Handler: UserGetTypeHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/user/basic-info",
|
||||
Handler: UserSaveBasicInfoHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/status-config",
|
||||
Handler: UserStatusConfigHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/basic-info",
|
||||
Handler: UserBasicInfoHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/api/user/address-list",
|
||||
Handler: UserAddressListHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/user/add-address",
|
||||
Handler: UserAddAddressHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/api/user/contact-service",
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/logic"
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
)
|
||||
|
||||
func UserAddAddressHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.RequestAddAddress
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUserAddAddressLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.UserAddAddress(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"reflect"
|
||||
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"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
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// 创建一个业务逻辑层实例
|
||||
l := logic.NewUserAddressListLogic(r.Context(), svcCtx)
|
||||
|
||||
rl := reflect.ValueOf(l)
|
||||
basic.BeforeLogic(w, r, rl)
|
||||
|
||||
resp := l.UserAddressList(&req, userinfo)
|
||||
|
||||
if !basic.AfterLogic(w, r, rl, resp) {
|
||||
basic.NormalAfterLogic(w, r, resp)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"fusenapi/model/gmodel"
|
||||
"fusenapi/utils/auth"
|
||||
"fusenapi/utils/basic"
|
||||
|
||||
"context"
|
||||
|
||||
"fusenapi/server/home-user-auth/internal/svc"
|
||||
"fusenapi/server/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type UserAddAddressLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewUserAddAddressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserAddAddressLogic {
|
||||
return &UserAddAddressLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *UserAddAddressLogic) UserAddAddress(req *types.RequestAddAddress, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth) // 如果不是用户信息, 返回未授权错误
|
||||
}
|
||||
|
||||
// 确认这个IsDefault的值范围
|
||||
if !auth.CheckValueRange(req.IsDefault, 0, 1) {
|
||||
return resp.SetStatus(basic.CodeSafeValueRangeErr) // IsDefault值超出范围, 返回安全值范围错误
|
||||
}
|
||||
|
||||
m := l.svcCtx.AllModels.FsAddress // 创建地址模型
|
||||
var status int64 = 1 // 默认地址状态为1(正常)
|
||||
|
||||
// 如果ID为0, 表示新增地址
|
||||
if req.Id == 0 {
|
||||
var (
|
||||
country string = "USA" // 国家默认为美国
|
||||
)
|
||||
createOne := &gmodel.FsAddress{ // 构建FsAddress结构体
|
||||
FirstName: &req.FirstName,
|
||||
LastName: &req.LastName,
|
||||
Mobile: &req.Mobile,
|
||||
Street: &req.Street,
|
||||
Suite: &req.Suite,
|
||||
City: &req.City,
|
||||
State: &req.State,
|
||||
Country: &country,
|
||||
Status: &status,
|
||||
UserId: &userinfo.UserId,
|
||||
ZipCode: &req.ZipCode,
|
||||
}
|
||||
created, err := m.CreateOne(l.ctx, createOne) // 新增地址
|
||||
if err != nil {
|
||||
logx.Error(err) // 日志记录错误
|
||||
return resp.SetStatus(basic.CodeDbCreateErr) // 返回数据库创建错误
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, map[string]int64{"id": created.AddressId}) // 返回成功并返回地址ID
|
||||
}
|
||||
|
||||
address := &gmodel.FsAddress{
|
||||
AddressId: req.Id,
|
||||
FirstName: &req.FirstName,
|
||||
LastName: &req.LastName,
|
||||
Mobile: &req.Mobile,
|
||||
Street: &req.Street,
|
||||
Suite: &req.Suite,
|
||||
City: &req.City,
|
||||
State: &req.State,
|
||||
Status: &status,
|
||||
UserId: &userinfo.UserId,
|
||||
ZipCode: &req.ZipCode,
|
||||
}
|
||||
|
||||
// 插入数据库 更新地址
|
||||
err := m.UpdateAddress(l.ctx, address)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatus(basic.CodeDbUpdateErr)
|
||||
}
|
||||
|
||||
return resp.SetStatus(basic.CodeOK, map[string]int64{"id": address.AddressId})
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"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, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
if !userinfo.IsUser() {
|
||||
return resp.SetStatus(basic.CodeUnAuth)
|
||||
}
|
||||
|
||||
m := l.svcCtx.AllModels.FsAddress
|
||||
|
||||
data, err := m.GetUserAllAddress(l.ctx, userinfo.UserId)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return resp.SetStatusWithMessage(basic.CodeServiceErr, err.Error())
|
||||
}
|
||||
return resp.SetStatus(basic.CodeOK, data)
|
||||
}
|
|
@ -14,7 +14,7 @@ import (
|
|||
func UpdateProfileBaseHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
var req types.ProfileBaseRequest
|
||||
var req types.ProfileRequest
|
||||
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
|
||||
if err != nil {
|
||||
return
|
||||
|
|
|
@ -30,7 +30,7 @@ func NewUpdateProfileBaseLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||
// func (l *UpdateProfileBaseLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
|
||||
// }
|
||||
|
||||
func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileBaseRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
func (l *UpdateProfileBaseLogic) UpdateProfileBase(req *types.ProfileRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
|
||||
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
|
||||
// userinfo 传入值时, 一定不为null
|
||||
if !userinfo.IsUser() {
|
||||
|
|
|
@ -31,13 +31,31 @@ type AddressRequest struct {
|
|||
State string `json:"state"` //州
|
||||
}
|
||||
|
||||
type ProfileBaseRequest struct {
|
||||
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||
UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
||||
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||
Company *string `json:"company,optional,omitempty"` // 公司
|
||||
type ProfileRequest struct {
|
||||
ProfileBase *ProfileBase `json:"base,optional,omitempty"` // 基础的个人消息, 姓名 公司等
|
||||
SubscriptionStatus *SubscriptionStatus `json:"sub_status,optional,omitempty"` // 订阅的通知状态
|
||||
}
|
||||
|
||||
type ProfileBase struct {
|
||||
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||
Company *string `json:"company,optional,omitempty"` // 公司
|
||||
}
|
||||
|
||||
type SubscriptionStatus struct {
|
||||
NotificationEmail NotificationEmail `json:"notification_email,optional,omitempty"`
|
||||
NotificationPhone NotificationPhone `json:"notification_phone,optional,omitempty"`
|
||||
}
|
||||
|
||||
type NotificationEmail struct {
|
||||
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||
}
|
||||
|
||||
type NotificationPhone struct {
|
||||
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||
}
|
||||
|
||||
type QueryProfileRequest struct {
|
||||
|
|
|
@ -10,68 +10,55 @@ info (
|
|||
import "basic.api"
|
||||
|
||||
service home-user-auth {
|
||||
|
||||
|
||||
// @handler UserRegisterHandler
|
||||
// post /api/user/register(RequestUserRegister) returns (response);
|
||||
//用户字体
|
||||
@handler UserFontsHandler
|
||||
get /api/user/fonts(request) returns (response);
|
||||
//获取用户类型
|
||||
@handler UserGetTypeHandler
|
||||
get /api/user/get-type(request) returns (response);
|
||||
//保存用户基础信息
|
||||
@handler UserSaveBasicInfoHandler
|
||||
post /api/user/basic-info(RequestBasicInfoForm) returns (response);
|
||||
|
||||
//状态配置
|
||||
@handler UserStatusConfigHandler
|
||||
get /api/user/status-config(request) returns (response);
|
||||
//基础信息
|
||||
@handler UserBasicInfoHandler
|
||||
get /api/user/basic-info(request) returns (response);
|
||||
//地址列表
|
||||
@handler UserAddressListHandler
|
||||
get /api/user/address-list(request) returns (response);
|
||||
//添加地址
|
||||
@handler UserAddAddressHandler
|
||||
post /api/user/add-address(RequestAddAddress) returns (response);
|
||||
|
||||
//联系服务
|
||||
@handler UserContactServiceHandler
|
||||
post /api/user/contact-service (RequestContactService) returns (response);
|
||||
|
||||
|
||||
// @handler UserOderListHandler
|
||||
// get /api/user/order-list(RequestOrderId) returns (response);
|
||||
//删除订单
|
||||
@handler UserOderDeleteHandler
|
||||
post /api/user/order-delete(RequestOrderId) returns (response);
|
||||
|
||||
|
||||
//订单列表
|
||||
@handler UserOrderListHandler
|
||||
get /api/user/order-list (UserOrderListReq) returns (response);
|
||||
|
||||
|
||||
//删除订单
|
||||
@handler UserOrderDeleteHandler
|
||||
get /api/user/order-delete (UserOrderDeleteReq) returns (response);
|
||||
|
||||
|
||||
//取消订单
|
||||
@handler UserOrderCancelHandler
|
||||
get /api/user/order-cancel (UserOrderCancelReq) returns (response);
|
||||
|
||||
|
||||
// 用户logo列表
|
||||
@handler UserLogoListHandler
|
||||
get /api/user/logo-list (UserLogoListReq) returns (response);
|
||||
|
||||
|
||||
// 再来一单
|
||||
@handler UserAgainOrderHandler
|
||||
get /api/user/one-more-order (UserAgainOrderReq) returns (response);
|
||||
|
||||
|
||||
// 保存商户信息
|
||||
@handler UserInfoSetHandler
|
||||
post /api/user/set_user_info (UserInfoSetReq) returns (response);
|
||||
|
||||
|
||||
// 用户logo设置当前
|
||||
@handler UserLogoSetHandler
|
||||
post /api/user/logo-set (UserLogoSetReq) returns (response);
|
||||
|
||||
|
||||
// 用户logo模版信息
|
||||
@handler UserLogoTemplateTagSetHandler
|
||||
post /api/user/logo-templatetag-set (UserLogoTemplateTagSetReq) returns (response);
|
||||
|
|
|
@ -17,7 +17,7 @@ service info {
|
|||
post /api/info/user/profile(QueryProfileRequest) returns (response);
|
||||
|
||||
@handler UpdateProfileBaseHandler
|
||||
post /api/info/user/profile/base/update(ProfileBaseRequest) returns (response);
|
||||
post /api/info/user/profile/base/update(ProfileRequest) returns (response);
|
||||
|
||||
@handler AddressDefaultHandler
|
||||
post /api/info/address/default(AddressIdRequest) returns (response);
|
||||
|
@ -62,15 +62,37 @@ type (
|
|||
State string `json:"state"` //州
|
||||
}
|
||||
|
||||
ProfileBaseRequest {
|
||||
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||
UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
||||
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||
Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||
Company *string `json:"company,optional,omitempty"` // 公司
|
||||
ProfileRequest {
|
||||
ProfileBase *ProfileBase `json:"base,optional,omitempty"` // 基础的个人消息, 姓名 公司等
|
||||
SubscriptionStatus *SubscriptionStatus `json:"sub_status,optional,omitempty"` // 订阅的通知状态
|
||||
|
||||
}
|
||||
|
||||
ProfileBase {
|
||||
FirstName *string `json:"first_name,optional,omitempty"` // 首名
|
||||
LastName *string `json:"last_name,optional,omitempty"` // 后名
|
||||
// UserName *string `json:"user_name,optional,omitempty"` // 用户名
|
||||
Mobile *string `json:"mobile,optional,omitempty"` // 电话
|
||||
// Resetaurant *string `json:"resetaurant,optional,omitempty"` // 不知道干什么
|
||||
Company *string `json:"company,optional,omitempty"` // 公司
|
||||
|
||||
}
|
||||
|
||||
SubscriptionStatus {
|
||||
NotificationEmail NotificationEmail `json:"notification_email,optional,omitempty"`
|
||||
NotificationPhone NotificationPhone `json:"notification_phone,optional,omitempty"`
|
||||
} // 订阅的通知状态
|
||||
|
||||
NotificationEmail {
|
||||
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||
} // 邮件通知设置
|
||||
|
||||
NotificationPhone {
|
||||
OrderUpdate bool `json:"order_update,optional,omitempty"`
|
||||
Newseleter bool `json:"newseleter,optional,omitempty"`
|
||||
} // 电话通知设置
|
||||
|
||||
QueryProfileRequest {
|
||||
TopKey string `json:"top_key"` // 首名
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user