正在显示
5 个修改的文件
包含
102 行增加
和
0 行删除
@@ -34,6 +34,9 @@ service Core { | @@ -34,6 +34,9 @@ service Core { | ||
34 | @doc "用户信息" | 34 | @doc "用户信息" |
35 | @handler miniUserInfo | 35 | @handler miniUserInfo |
36 | post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse) | 36 | post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse) |
37 | + @doc "编辑用户信息" | ||
38 | + @handler miniEditUserInfo | ||
39 | + post /mini/user/info/edit (MiniEditUserInfoRequest) returns (MiniEditUserInfoResponse) | ||
37 | @doc "用户统计" | 40 | @doc "用户统计" |
38 | @handler miniUserStatistics | 41 | @handler miniUserStatistics |
39 | post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse) | 42 | post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse) |
@@ -79,6 +82,15 @@ service Core { | @@ -79,6 +82,15 @@ service Core { | ||
79 | } | 82 | } |
80 | 83 | ||
81 | type( | 84 | type( |
85 | + MiniEditUserInfoRequest{ | ||
86 | + Avatar *string `json:"avatar"` | ||
87 | + } | ||
88 | + MiniEditUserInfoResponse{ | ||
89 | + | ||
90 | + } | ||
91 | +) | ||
92 | + | ||
93 | +type( | ||
82 | MiniUserLoginRequest { | 94 | MiniUserLoginRequest { |
83 | LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login | 95 | LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login |
84 | WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 | 96 | WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 |
@@ -212,6 +212,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -212,6 +212,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
212 | }, | 212 | }, |
213 | { | 213 | { |
214 | Method: http.MethodPost, | 214 | Method: http.MethodPost, |
215 | + Path: "/mini/user/info/edit", | ||
216 | + Handler: user.MiniEditUserInfoHandler(serverCtx), | ||
217 | + }, | ||
218 | + { | ||
219 | + Method: http.MethodPost, | ||
215 | Path: "/mini/user/statistics", | 220 | Path: "/mini/user/statistics", |
216 | Handler: user.MiniUserStatisticsHandler(serverCtx), | 221 | Handler: user.MiniUserStatisticsHandler(serverCtx), |
217 | }, | 222 | }, |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | +) | ||
11 | + | ||
12 | +func MiniEditUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
13 | + return func(w http.ResponseWriter, r *http.Request) { | ||
14 | + var req types.MiniEditUserInfoRequest | ||
15 | + if err := httpx.Parse(r, &req); err != nil { | ||
16 | + httpx.ErrorCtx(r.Context(), w, err) | ||
17 | + return | ||
18 | + } | ||
19 | + | ||
20 | + l := user.NewMiniEditUserInfoLogic(r.Context(), svcCtx) | ||
21 | + resp, err := l.MiniEditUserInfo(&req) | ||
22 | + if err != nil { | ||
23 | + httpx.ErrorCtx(r.Context(), w, err) | ||
24 | + } else { | ||
25 | + httpx.OkJsonCtx(r.Context(), w, resp) | ||
26 | + } | ||
27 | + } | ||
28 | +} |
1 | +package user | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
11 | + | ||
12 | + "github.com/zeromicro/go-zero/core/logx" | ||
13 | +) | ||
14 | + | ||
15 | +type MiniEditUserInfoLogic struct { | ||
16 | + logx.Logger | ||
17 | + ctx context.Context | ||
18 | + svcCtx *svc.ServiceContext | ||
19 | +} | ||
20 | + | ||
21 | +func NewMiniEditUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniEditUserInfoLogic { | ||
22 | + return &MiniEditUserInfoLogic{ | ||
23 | + Logger: logx.WithContext(ctx), | ||
24 | + ctx: ctx, | ||
25 | + svcCtx: svcCtx, | ||
26 | + } | ||
27 | +} | ||
28 | + | ||
29 | +func (l *MiniEditUserInfoLogic) MiniEditUserInfo(req *types.MiniEditUserInfoRequest) (resp *types.MiniEditUserInfoResponse, err error) { | ||
30 | + var ( | ||
31 | + conn = l.svcCtx.DefaultDBConn() | ||
32 | + user *domain.User | ||
33 | + userToken = contextdata.GetUserTokenFromCtx(l.ctx) | ||
34 | + ) | ||
35 | + user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId) | ||
36 | + if err != nil { | ||
37 | + return nil, err | ||
38 | + } | ||
39 | + if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error { | ||
40 | + user.Avatar = *req.Avatar | ||
41 | + if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil { | ||
42 | + return err | ||
43 | + } | ||
44 | + return nil | ||
45 | + }, true); err != nil { | ||
46 | + return nil, xerr.NewErrMsgErr("更新头像失败", err) | ||
47 | + } | ||
48 | + resp = &types.MiniEditUserInfoResponse{} | ||
49 | + return | ||
50 | +} |
@@ -402,6 +402,13 @@ type TagOptionValue struct { | @@ -402,6 +402,13 @@ type TagOptionValue struct { | ||
402 | Value int64 `json:"value"` // 标签ID | 402 | Value int64 `json:"value"` // 标签ID |
403 | } | 403 | } |
404 | 404 | ||
405 | +type MiniEditUserInfoRequest struct { | ||
406 | + Avatar *string `json:"avatar"` | ||
407 | +} | ||
408 | + | ||
409 | +type MiniEditUserInfoResponse struct { | ||
410 | +} | ||
411 | + | ||
405 | type MiniUserLoginRequest struct { | 412 | type MiniUserLoginRequest struct { |
406 | LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login | 413 | LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login |
407 | WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 | 414 | WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码 |
-
请 注册 或 登录 后发表评论