获取接口
This commit is contained in:
parent
7dc241c37d
commit
283d8bee5f
|
|
@ -40,14 +40,18 @@ type ModifyInfo struct {
|
|||
}
|
||||
|
||||
type Query struct {
|
||||
Page int `json:"page" binding:"required"`
|
||||
PageSize int `json:"page_size" binding:"required"`
|
||||
Keyword string `Json:"keyword"`
|
||||
Sort string `json:"sort" binding:"sql_sort"`
|
||||
Page int `form:"page" json:"page" binding:"required"`
|
||||
PageSize int `form:"page_size" json:"page_size" binding:"required"`
|
||||
Keyword string `form:"keyword" Json:"keyword"`
|
||||
Sort string `form:"sort" json:"sort" binding:"sql_sort"`
|
||||
}
|
||||
|
||||
type ResetPwdReq struct {
|
||||
Id uint `json:"id" binging:"required"`
|
||||
Id uint `json:"id" binding:"required"`
|
||||
OldPwd string `json:"old_pwd" binding:"required"`
|
||||
Pwd string `json:"pwd" binding:"required"`
|
||||
}
|
||||
|
||||
type GetUserReq struct {
|
||||
Account string `form:"account" json:"account" binding:"required"`
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,4 +13,6 @@ type UserService interface {
|
|||
Disable(ctx context.Context) error
|
||||
Enable(ctx context.Context) error
|
||||
Search(ctx context.Context, query *models.Query) ([]models.User, error)
|
||||
ResetPwd(ctx context.Context, req *models.ResetPwdReq) error
|
||||
GetUser(ctx context.Context, req *models.GetUserReq) (user models.User, err error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,24 +243,12 @@ func (u *userService) ResetPwd(ctx context.Context, req *models.ResetPwdReq) err
|
|||
return nil
|
||||
}
|
||||
|
||||
func convertUserList(users []repo.User) []models.User {
|
||||
list := make([]models.User, len(users))
|
||||
for _, item := range users {
|
||||
list = append(list, convertUser(item))
|
||||
func (u *userService) GetUser(ctx context.Context, req *models.GetUserReq) (user models.User, err error) {
|
||||
rUser, err := u.repo.GetUserByAccount(ctx, req.Account)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
func convertUser(user repo.User) models.User {
|
||||
return models.User{
|
||||
Id: user.ID,
|
||||
UserInfo: models.UserInfo{
|
||||
Name: user.Name,
|
||||
Account: user.Account,
|
||||
Mobile: user.Mobile,
|
||||
Email: user.Email,
|
||||
Sex: user.Sex,
|
||||
},
|
||||
}
|
||||
user = convertUser(rUser)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
"busniess-user-center/internal/models"
|
||||
"busniess-user-center/internal/repo"
|
||||
"context"
|
||||
"fmt"
|
||||
|
|
@ -66,3 +67,25 @@ func (u *userService) removeCookie(ctx context.Context) {
|
|||
c.Writer.Header().Add("Set-Cookie", fmt.Sprintf("%s=; Max-Age=0; Path=/;Domain=%s", COOKIE_KEY_ID, domain))
|
||||
}
|
||||
}
|
||||
|
||||
func convertUserList(users []repo.User) []models.User {
|
||||
list := make([]models.User, len(users))
|
||||
for _, item := range users {
|
||||
list = append(list, convertUser(item))
|
||||
}
|
||||
|
||||
return list
|
||||
}
|
||||
|
||||
func convertUser(user repo.User) models.User {
|
||||
return models.User{
|
||||
Id: user.ID,
|
||||
UserInfo: models.UserInfo{
|
||||
Name: user.Name,
|
||||
Account: user.Account,
|
||||
Mobile: user.Mobile,
|
||||
Email: user.Email,
|
||||
Sex: user.Sex,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,9 @@ func RegisterRoute(api *gin.RouterGroup) {
|
|||
api.POST("/login", ginUtil.WrapNoRsp(server.Login))
|
||||
api.POST("/logout", ginUtil.WrapNo(server.Logout))
|
||||
api.POST("/modify", ginUtil.WrapNoRsp(server.Modify))
|
||||
api.GET("/search", ginUtil.WrapNoRsp(server.Modify))
|
||||
api.GET("/search", ginUtil.Wrap(server.Search))
|
||||
api.GET("/user", ginUtil.Wrap(server.GetUser))
|
||||
api.POST("/reset", ginUtil.Wrap(server.GetUser))
|
||||
}
|
||||
|
||||
func (u *UserServer) Add(ctx context.Context, req *models.AddInfo) (rsp proto.AddResponse, err error) {
|
||||
|
|
@ -82,3 +84,11 @@ func (u *UserServer) Enable(ctx context.Context) error {
|
|||
func (u *UserServer) Search(ctx context.Context, query *models.Query) ([]models.User, error) {
|
||||
return u.userService.Search(ctx, query)
|
||||
}
|
||||
|
||||
func (u *UserServer) GetUser(ctx context.Context, req *models.GetUserReq) (models.User, error) {
|
||||
return u.userService.GetUser(ctx, req)
|
||||
}
|
||||
|
||||
func (u *UserServer) ResetPwd(ctx context.Context, req *models.ResetPwdReq) error {
|
||||
return u.userService.ResetPwd(ctx, req)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue