info get profile

This commit is contained in:
eson
2023-09-26 17:16:10 +08:00
parent 4dfeebeaed
commit f387e46977
10 changed files with 159 additions and 29 deletions

View File

@@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
Path: "/api/info/user",
Handler: InfoHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/api/info/user/profile",
Handler: UserGetProfileHandler(serverCtx),
},
{
Method: http.MethodPost,
Path: "/api/info/user/profile/update",

View File

@@ -0,0 +1,35 @@
package handler
import (
"net/http"
"reflect"
"fusenapi/utils/basic"
"fusenapi/server/info/internal/logic"
"fusenapi/server/info/internal/svc"
"fusenapi/server/info/internal/types"
)
func UserGetProfileHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req types.QueryProfileRequest
userinfo, err := basic.RequestParse(w, r, svcCtx, &req)
if err != nil {
return
}
// 创建一个业务逻辑层实例
l := logic.NewUserGetProfileLogic(r.Context(), svcCtx)
rl := reflect.ValueOf(l)
basic.BeforeLogic(w, r, rl)
resp := l.UserGetProfile(&req, userinfo)
if !basic.AfterLogic(w, r, rl, resp) {
basic.NormalAfterLogic(w, r, resp)
}
}
}

View File

@@ -5,8 +5,8 @@ import (
"fmt"
"fusenapi/initalize"
"fusenapi/model/gmodel"
"fusenapi/server/info/internal/types"
"fusenapi/utils/check"
"fusenapi/utils/fssql"
"log"
"strings"
"testing"
@@ -176,24 +176,14 @@ func TestCaseJSON_EXTRACT(t *testing.T) {
conn := initalize.InitMysql("fsreaderwriter:XErSYmLELKMnf3Dh@tcp(fusen.cdmigcvz3rle.us-east-2.rds.amazonaws.com:3306)/fusen")
// err = conn.Exec(updatesql, 6).Error
fname := "asd"
r := &types.ProfileRequest{
FirstName: &fname,
}
info := gmodel.UserProfileBase{}
m := map[string]any{
"base": r,
}
var baseinfo map[string]any
tname := fssql.GetGormTableName(conn, gmodel.FsUserInfo{})
rawsql := fmt.Sprintf("select JSON_EXTRACT(metadata,'$.base') as base from %s where user_id = ? and module = ? order by ctime DESC limit 1", tname)
tx := conn.Raw(rawsql, 162, "profile").Take(&baseinfo)
log.Println(tx.Error)
json.Unmarshal([]byte(baseinfo["base"].(string)), &info)
data, err := json.Marshal(m)
if err != nil {
panic(err)
}
log.Println(string(data))
var result []gmodel.FsAddress
conn.Model(&gmodel.FsAddress{}).Find(&result)
log.Println(conn.Model(&gmodel.FsChangeCode{}).Select("id").Where("id = 5").Take(nil).Error)
log.Println(err)
}

View File

@@ -0,0 +1,52 @@
package logic
import (
"fusenapi/utils/auth"
"fusenapi/utils/basic"
"context"
"fusenapi/server/info/internal/svc"
"fusenapi/server/info/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type UserGetProfileLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewUserGetProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserGetProfileLogic {
return &UserGetProfileLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
// 处理进入前逻辑w,r
// func (l *UserGetProfileLogic) BeforeLogic(w http.ResponseWriter, r *http.Request) {
// }
func (l *UserGetProfileLogic) UserGetProfile(req *types.QueryProfileRequest, userinfo *auth.UserInfo) (resp *basic.Response) {
// 返回值必须调用Set重新返回, resp可以空指针调用 resp.SetStatus(basic.CodeOK, data)
// userinfo 传入值时, 一定不为null
if !userinfo.IsUser() {
return resp.SetStatus(basic.CodeUnAuth)
}
profileBase, err := l.svcCtx.AllModels.FsUserInfo.GetProfile(l.ctx, req.TopKey, userinfo.UserId)
if err != nil {
return resp.SetStatusWithMessage(basic.CodeApiErr, err.Error())
}
return resp.SetStatus(basic.CodeOK, profileBase)
}
// 处理逻辑后 w,r 如:重定向, resp 必须重新处理
// func (l *UserGetProfileLogic) AfterLogic(w http.ResponseWriter, r *http.Request, resp *basic.Response) {
// // httpx.OkJsonCtx(r.Context(), w, resp)
// }

View File

@@ -45,6 +45,10 @@ type ProfileRequest struct {
Company *string `json:"company,optional,omitempty"` // 公司
}
type QueryProfileRequest struct {
TopKey string `json:"top_key"` // 首名
}
type Request struct {
}