最新成果

This commit is contained in:
eson
2023-06-01 16:19:24 +08:00
parent 5446c4123a
commit 7ffbce7759
10 changed files with 241 additions and 20 deletions

View 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)
}
}
}

View File

@@ -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),
},
},
)
}

View 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
}

View File

@@ -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),
}
}

View File

@@ -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 {