获取接口
This commit is contained in:
parent
7dc241c37d
commit
283d8bee5f
|
|
@ -40,14 +40,18 @@ type ModifyInfo struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query struct {
|
type Query struct {
|
||||||
Page int `json:"page" binding:"required"`
|
Page int `form:"page" json:"page" binding:"required"`
|
||||||
PageSize int `json:"page_size" binding:"required"`
|
PageSize int `form:"page_size" json:"page_size" binding:"required"`
|
||||||
Keyword string `Json:"keyword"`
|
Keyword string `form:"keyword" Json:"keyword"`
|
||||||
Sort string `json:"sort" binding:"sql_sort"`
|
Sort string `form:"sort" json:"sort" binding:"sql_sort"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResetPwdReq struct {
|
type ResetPwdReq struct {
|
||||||
Id uint `json:"id" binging:"required"`
|
Id uint `json:"id" binding:"required"`
|
||||||
OldPwd string `json:"old_pwd" binding:"required"`
|
OldPwd string `json:"old_pwd" binding:"required"`
|
||||||
Pwd string `json:"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
|
Disable(ctx context.Context) error
|
||||||
Enable(ctx context.Context) error
|
Enable(ctx context.Context) error
|
||||||
Search(ctx context.Context, query *models.Query) ([]models.User, 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func convertUserList(users []repo.User) []models.User {
|
func (u *userService) GetUser(ctx context.Context, req *models.GetUserReq) (user models.User, err error) {
|
||||||
list := make([]models.User, len(users))
|
rUser, err := u.repo.GetUserByAccount(ctx, req.Account)
|
||||||
for _, item := range users {
|
if err != nil {
|
||||||
list = append(list, convertUser(item))
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
return list
|
user = convertUser(rUser)
|
||||||
}
|
return
|
||||||
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"busniess-user-center/internal/models"
|
||||||
"busniess-user-center/internal/repo"
|
"busniess-user-center/internal/repo"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"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))
|
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("/login", ginUtil.WrapNoRsp(server.Login))
|
||||||
api.POST("/logout", ginUtil.WrapNo(server.Logout))
|
api.POST("/logout", ginUtil.WrapNo(server.Logout))
|
||||||
api.POST("/modify", ginUtil.WrapNoRsp(server.Modify))
|
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) {
|
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) {
|
func (u *UserServer) Search(ctx context.Context, query *models.Query) ([]models.User, error) {
|
||||||
return u.userService.Search(ctx, query)
|
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