model 格式改变
This commit is contained in:
parent
834a560451
commit
54cbe017b9
16
.gitignore
vendored
16
.gitignore
vendored
|
@ -13,3 +13,19 @@
|
||||||
|
|
||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
|
|
||||||
|
#vscode
|
||||||
|
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/settings.json
|
||||||
|
!.vscode/tasks.json
|
||||||
|
!.vscode/launch.json
|
||||||
|
!.vscode/extensions.json
|
||||||
|
!.vscode/*.code-snippets
|
||||||
|
|
||||||
|
# Local History for Visual Studio Code
|
||||||
|
.history/
|
||||||
|
|
||||||
|
# Built Visual Studio Code Extensions
|
||||||
|
*.vsix
|
|
@ -5,4 +5,4 @@ SourceMysql: fusentest:XErSYmLELKMnf3Dh@tcp(110.41.19.98:3306)/fusentest
|
||||||
|
|
||||||
Auth:
|
Auth:
|
||||||
AccessSecret: fusen2023
|
AccessSecret: fusen2023
|
||||||
AccessExpire: 604800
|
AccessExpire: 60
|
||||||
|
|
|
@ -35,6 +35,8 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
server.AddRoutes(
|
server.AddRoutes(
|
||||||
[]rest.Route{
|
[]rest.Route{
|
||||||
{
|
{
|
||||||
|
@ -44,5 +46,6 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
"fusenapi/home-user-auth/internal/logic"
|
"fusenapi/home-user-auth/internal/logic"
|
||||||
"fusenapi/home-user-auth/internal/svc"
|
"fusenapi/home-user-auth/internal/svc"
|
||||||
"fusenapi/home-user-auth/internal/types"
|
"fusenapi/home-user-auth/internal/types"
|
||||||
"fusenapi/utils/auth"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
@ -26,8 +25,7 @@ func UserSaveBasicInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
}
|
}
|
||||||
|
|
||||||
l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx)
|
l := logic.NewUserSaveBasicInfoLogic(r.Context(), svcCtx)
|
||||||
userinfo := auth.CheckAuth(r)
|
resp := l.UserSaveBasicInfo(&req)
|
||||||
resp := l.UserSaveBasicInfo(&req, &userinfo)
|
|
||||||
if resp != nil {
|
if resp != nil {
|
||||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"fusenapi/model"
|
"fusenapi/model"
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -25,12 +26,21 @@ func NewUserLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserLog
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *UserLoginLogic) getJwtToken(secretKey string, iat, seconds, userId int64) (string, error) {
|
||||||
|
claims := make(jwt.MapClaims)
|
||||||
|
claims["exp"] = iat + seconds
|
||||||
|
claims["iat"] = iat
|
||||||
|
claims["userId"] = userId
|
||||||
|
token := jwt.New(jwt.SigningMethodHS256)
|
||||||
|
token.Claims = claims
|
||||||
|
return token.SignedString([]byte(secretKey))
|
||||||
|
}
|
||||||
|
|
||||||
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response) {
|
func (l *UserLoginLogic) UserLogin(req *types.RequestUserLogin) (resp *types.Response) {
|
||||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||||
resp = &types.Response{}
|
resp = &types.Response{}
|
||||||
|
|
||||||
userModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOneByEmail(l.ctx, req.Name)
|
userModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOneByEmail(l.ctx, req.Name)
|
||||||
|
|
||||||
// log.Printf("%t %t %v", err, model.ErrNotFound, err == model.ErrNotFound)
|
// log.Printf("%t %t %v", err, model.ErrNotFound, err == model.ErrNotFound)
|
||||||
if err == model.ErrNotFound {
|
if err == model.ErrNotFound {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"fusenapi/home-user-auth/internal/svc"
|
"fusenapi/home-user-auth/internal/svc"
|
||||||
"fusenapi/home-user-auth/internal/types"
|
"fusenapi/home-user-auth/internal/types"
|
||||||
"fusenapi/model"
|
"fusenapi/model"
|
||||||
"fusenapi/utils/auth"
|
|
||||||
"fusenapi/utils/basic"
|
"fusenapi/utils/basic"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
@ -26,16 +25,18 @@ func NewUserSaveBasicInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm, userinfo *auth.UserInfo) (resp *types.Response) {
|
func (l *UserSaveBasicInfoLogic) UserSaveBasicInfo(req *types.RequestBasicInfoForm) (resp *types.Response) {
|
||||||
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
// 必须返回response, 前端需要的是内部约定的Code码, 处理相关的逻辑. 例子(eg): resp.Set(501, "error")
|
||||||
resp = &types.Response{}
|
resp = &types.Response{}
|
||||||
// logx.Info(req)
|
// logx.Info(req)
|
||||||
if userinfo.UserId == 0 {
|
// if userinfo.UserId == 0 {
|
||||||
resp.SetStatusWithMessage(basic.DefaultError, "user is not exists")
|
// resp.SetStatusWithMessage(basic.DefaultError, "user is not exists")
|
||||||
return resp
|
// return resp
|
||||||
}
|
// }
|
||||||
|
|
||||||
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userinfo.UserId)
|
userid := l.ctx.Value("userid").(int64)
|
||||||
|
|
||||||
|
fsUserModel, err := model.NewFsUserModel(l.svcCtx.MysqlConn).FindOne(l.ctx, userid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logx.Error(err)
|
logx.Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
var _ FsCanteenTypeModel = (*customFsCanteenTypeModel)(nil)
|
var _ FsCanteenTypeModel = (*customFsCanteenTypeModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +15,7 @@ type (
|
||||||
// and implement the added methods in customFsCanteenTypeModel.
|
// and implement the added methods in customFsCanteenTypeModel.
|
||||||
FsCanteenTypeModel interface {
|
FsCanteenTypeModel interface {
|
||||||
fsCanteenTypeModel
|
fsCanteenTypeModel
|
||||||
|
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsCanteenTypeModel struct {
|
customFsCanteenTypeModel struct {
|
||||||
|
@ -22,3 +29,24 @@ func NewFsCanteenTypeModel(conn sqlx.SqlConn) FsCanteenTypeModel {
|
||||||
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
|
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FsGetTypeCanteenType struct {
|
||||||
|
Id int64 `db:"id" json:"key"` // ID
|
||||||
|
Name string `db:"name" json:"name"` // 餐厅名字
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) {
|
||||||
|
|
||||||
|
query := fmt.Sprintf("select X.id,X.name from (select %s from %s where status = 1 order by sort desc) X", fsCanteenTypeRows, m.table)
|
||||||
|
var resp []*FsGetTypeCanteenType
|
||||||
|
err := m.conn.QueryRows(&resp, query)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -27,8 +27,6 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsCanteenType, error)
|
FindOne(ctx context.Context, id int64) (*FsCanteenType, error)
|
||||||
Update(ctx context.Context, data *FsCanteenType) error
|
Update(ctx context.Context, data *FsCanteenType) error
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
|
|
||||||
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFsCanteenTypeModel struct {
|
defaultFsCanteenTypeModel struct {
|
||||||
|
|
|
@ -1,6 +1,12 @@
|
||||||
package model
|
package model
|
||||||
|
|
||||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
var _ FsFontModel = (*customFsFontModel)(nil)
|
var _ FsFontModel = (*customFsFontModel)(nil)
|
||||||
|
|
||||||
|
@ -9,6 +15,7 @@ type (
|
||||||
// and implement the added methods in customFsFontModel.
|
// and implement the added methods in customFsFontModel.
|
||||||
FsFontModel interface {
|
FsFontModel interface {
|
||||||
fsFontModel
|
fsFontModel
|
||||||
|
FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
customFsFontModel struct {
|
customFsFontModel struct {
|
||||||
|
@ -22,3 +29,18 @@ func NewFsFontModel(conn sqlx.SqlConn) FsFontModel {
|
||||||
defaultFsFontModel: newFsFontModel(conn),
|
defaultFsFontModel: newFsFontModel(conn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *defaultFsFontModel) FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error) {
|
||||||
|
|
||||||
|
query := fmt.Sprintf("select %s from %s order by sort desc", fsFontRows, m.table)
|
||||||
|
var resp []*FsFont
|
||||||
|
err := m.conn.QueryRows(&resp, query)
|
||||||
|
switch err {
|
||||||
|
case nil:
|
||||||
|
return resp, nil
|
||||||
|
case sqlc.ErrNotFound:
|
||||||
|
return nil, ErrNotFound
|
||||||
|
default:
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ type (
|
||||||
FindOne(ctx context.Context, id int64) (*FsFont, error)
|
FindOne(ctx context.Context, id int64) (*FsFont, error)
|
||||||
Update(ctx context.Context, data *FsFont) error
|
Update(ctx context.Context, data *FsFont) error
|
||||||
Delete(ctx context.Context, id int64) error
|
Delete(ctx context.Context, id int64) error
|
||||||
FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defaultFsFontModel struct {
|
defaultFsFontModel struct {
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
||||||
)
|
|
||||||
|
|
||||||
type FsGetTypeCanteenType struct {
|
|
||||||
Id int64 `db:"id" json:"key"` // ID
|
|
||||||
Name string `db:"name" json:"name"` // 餐厅名字
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) {
|
|
||||||
|
|
||||||
query := fmt.Sprintf("select X.id,X.name from (select %s from %s where status = 1 order by sort desc) X", fsCanteenTypeRows, m.table)
|
|
||||||
var resp []*FsGetTypeCanteenType
|
|
||||||
err := m.conn.QueryRows(&resp, query)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
||||||
)
|
|
||||||
|
|
||||||
func (m *defaultFsFontModel) FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error) {
|
|
||||||
|
|
||||||
query := fmt.Sprintf("select %s from %s order by sort desc", fsFontRows, m.table)
|
|
||||||
var resp []*FsFont
|
|
||||||
err := m.conn.QueryRows(&resp, query)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user