作者 yangfu

编辑头像

... ... @@ -34,6 +34,9 @@ service Core {
@doc "用户信息"
@handler miniUserInfo
post /mini/user/info (MiniUserInfoRequest) returns (MiniUserInfoResponse)
@doc "编辑用户信息"
@handler miniEditUserInfo
post /mini/user/info/edit (MiniEditUserInfoRequest) returns (MiniEditUserInfoResponse)
@doc "用户统计"
@handler miniUserStatistics
post /mini/user/statistics (UserStatisticsRequest) returns (UserStatisticsResponse)
... ... @@ -79,6 +82,15 @@ service Core {
}
type(
MiniEditUserInfoRequest{
Avatar *string `json:"avatar"`
}
MiniEditUserInfoResponse{
}
)
type(
MiniUserLoginRequest {
LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
... ...
... ... @@ -212,6 +212,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
},
{
Method: http.MethodPost,
Path: "/mini/user/info/edit",
Handler: user.MiniEditUserInfoHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/mini/user/statistics",
Handler: user.MiniUserStatisticsHandler(serverCtx),
},
... ...
package user
import (
"net/http"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/user"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
)
func MiniEditUserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.MiniEditUserInfoRequest
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
l := user.NewMiniEditUserInfoLogic(r.Context(), svcCtx)
resp, err := l.MiniEditUserInfo(&req)
if err != nil {
httpx.ErrorCtx(r.Context(), w, err)
} else {
httpx.OkJsonCtx(r.Context(), w, resp)
}
}
}
... ...
package user
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/db/transaction"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniEditUserInfoLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniEditUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniEditUserInfoLogic {
return &MiniEditUserInfoLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniEditUserInfoLogic) MiniEditUserInfo(req *types.MiniEditUserInfoRequest) (resp *types.MiniEditUserInfoResponse, err error) {
var (
conn = l.svcCtx.DefaultDBConn()
user *domain.User
userToken = contextdata.GetUserTokenFromCtx(l.ctx)
)
user, err = l.svcCtx.UserRepository.FindOne(l.ctx, conn, userToken.UserId)
if err != nil {
return nil, err
}
if err = transaction.UseTrans(l.ctx, l.svcCtx.DB, func(ctx context.Context, conn transaction.Conn) error {
user.Avatar = *req.Avatar
if user, err = l.svcCtx.UserRepository.UpdateWithVersion(ctx, conn, user); err != nil {
return err
}
return nil
}, true); err != nil {
return nil, xerr.NewErrMsgErr("更新头像失败", err)
}
resp = &types.MiniEditUserInfoResponse{}
return
}
... ...
... ... @@ -402,6 +402,13 @@ type TagOptionValue struct {
Value int64 `json:"value"` // 标签ID
}
type MiniEditUserInfoRequest struct {
Avatar *string `json:"avatar"`
}
type MiniEditUserInfoResponse struct {
}
type MiniUserLoginRequest struct {
LoginType string `json:"loginType"` // 登录类型 wechat-login whchat-phone-login phone-password-login phone-smscode-login
WechatAuthCode string `json:"wechatAuthcode,optional"` // 微信登录 授权码
... ...