最新成果
This commit is contained in:
28
home-user-auth/internal/handler/gettypehandler.go
Normal file
28
home-user-auth/internal/handler/gettypehandler.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"fusenapi/home-user-auth/internal/logic"
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
)
|
||||
|
||||
func GetTypeHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.Request
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := logic.NewGetTypeLogic(r.Context(), svcCtx)
|
||||
resp, err := l.GetType(&req)
|
||||
if err != nil {
|
||||
httpx.ErrorCtx(r.Context(), w, err)
|
||||
} else {
|
||||
httpx.OkJsonCtx(r.Context(), w, resp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||||
Path: "/user/fonts",
|
||||
Handler: UserFontsHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodGet,
|
||||
Path: "/user/get-type",
|
||||
Handler: GetTypeHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
41
home-user-auth/internal/logic/gettypelogic.go
Normal file
41
home-user-auth/internal/logic/gettypelogic.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package logic
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"fusenapi/home-user-auth/internal/svc"
|
||||
"fusenapi/home-user-auth/internal/types"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
)
|
||||
|
||||
type GetTypeLogic struct {
|
||||
logx.Logger
|
||||
ctx context.Context
|
||||
svcCtx *svc.ServiceContext
|
||||
}
|
||||
|
||||
func NewGetTypeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetTypeLogic {
|
||||
return &GetTypeLogic{
|
||||
Logger: logx.WithContext(ctx),
|
||||
ctx: ctx,
|
||||
svcCtx: svcCtx,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *GetTypeLogic) GetType(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
data, err := l.svcCtx.FsCanteenTypeModel.FindGetType(l.ctx)
|
||||
if err != nil {
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
|
||||
// logx.Info(f)
|
||||
resp = &types.Response{
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: data,
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -8,14 +8,16 @@ import (
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config config.Config
|
||||
FsFontModel model.FsFontModel
|
||||
Config config.Config
|
||||
FsFontModel model.FsFontModel
|
||||
FsCanteenTypeModel model.FsCanteenTypeModel
|
||||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
conn := sqlx.NewMysql(c.DataSource)
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
FsFontModel: model.NewFsFontModel(sqlx.NewMysql(c.DataSource)),
|
||||
Config: c,
|
||||
FsFontModel: model.NewFsFontModel(conn),
|
||||
FsCanteenTypeModel: model.NewFsCanteenTypeModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,11 @@
|
||||
package types
|
||||
|
||||
type Request struct {
|
||||
Name string `form:"name"` // parameters are auto validated
|
||||
}
|
||||
|
||||
type FsFonts struct {
|
||||
Title string `json:"title" gorm:"column:title"`
|
||||
LinuxFontname string `json:"linux_fontname" gorm:"column:linux_fontname"`
|
||||
Link string `json:"link" gorm:"link"`
|
||||
type GetTypeData struct {
|
||||
Id int64 `db:"id" json:"key"` // ID
|
||||
Name string `db:"name" json:"name"` // 餐厅名字
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
|
||||
Reference in New Issue
Block a user