最新成果

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

@ -42,8 +42,8 @@
#### 使用说明
1. xxxx
2. xxxx
1. goctl api go -api home-user-auth.api -dir home-user-auth
2. goctl model mysql ddl --src ./ddl/fs_canteen_type.sql --dir model/
3. xxxx
#### 参与贡献

10
ddl/fs_canteen_type.sql Normal file
View File

@ -0,0 +1,10 @@
-- fusentest.fs_canteen_type definition
CREATE TABLE `fs_canteen_type` (
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`name` varchar(50) NOT NULL DEFAULT '' COMMENT '餐厅名字',
`sort` smallint(6) NOT NULL DEFAULT '0' COMMENT '排序',
`status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '状态位 1启用0停用',
`ctime` int(11) NOT NULL DEFAULT '0' COMMENT '添加时间',
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=24 DEFAULT CHARSET=utf8 COMMENT='餐厅类型表';

View File

@ -11,17 +11,18 @@ import "basic.api"
type request {
// TODO: add members here and delete this comment
Name string `form:"name"` // parameters are auto validated
// Name string `form:"name"` // parameters are auto validated
}
type GetTypeData {
Id int64 `db:"id" json:"key"` // ID
Name string `db:"name" json:"name"` // 餐厅名字
}
service home-user-auth {
@handler UserFontsHandler
get /user/fonts(request) returns (response);
}
// FsFonts 字体表
type FsFonts {
Title string `json:"title" gorm:"column:title"`
LinuxFontname string `json:"linux_fontname" gorm:"column:linux_fontname"`
Link string `json:"link" gorm:"link"`
@handler GetTypeHandler
get /user/get-type(request) returns (response);
}

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 {

24
model/fscanteentypemodel.go Executable file
View File

@ -0,0 +1,24 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ FsCanteenTypeModel = (*customFsCanteenTypeModel)(nil)
type (
// FsCanteenTypeModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsCanteenTypeModel.
FsCanteenTypeModel interface {
fsCanteenTypeModel
}
customFsCanteenTypeModel struct {
*defaultFsCanteenTypeModel
}
)
// NewFsCanteenTypeModel returns a model for the database table.
func NewFsCanteenTypeModel(conn sqlx.SqlConn) FsCanteenTypeModel {
return &customFsCanteenTypeModel{
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
}
}

112
model/fscanteentypemodel_gen.go Executable file
View File

@ -0,0 +1,112 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlc"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
fsCanteenTypeFieldNames = builder.RawFieldNames(&FsCanteenType{})
fsCanteenTypeRows = strings.Join(fsCanteenTypeFieldNames, ",")
// fsCanteenTypeGetTypeRows = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`name`", "`sort`", "`created_at`", "`status`"), ",")
// fsCanteenTypeGetTypeRows = builder.RawFieldNames(&FsGetTypeCanteenType{})
fsCanteenTypeRowsExpectAutoSet = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsCanteenTypeRowsWithPlaceHolder = strings.Join(stringx.Remove(fsCanteenTypeFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsCanteenTypeModel interface {
Insert(ctx context.Context, data *FsCanteenType) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsCanteenType, error)
Update(ctx context.Context, data *FsCanteenType) error
Delete(ctx context.Context, id int64) error
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
}
defaultFsCanteenTypeModel struct {
conn sqlx.SqlConn
table string
}
FsCanteenType struct {
Id int64 `db:"id"` // ID
Name string `db:"name"` // 餐厅名字
Sort int64 `db:"sort"` // 排序
Status int64 `db:"status"` // 状态位 1启用0停用
Ctime int64 `db:"ctime"` // 添加时间
}
FsGetTypeCanteenType struct {
Id int64 `db:"id" json:"key"` // ID
Name string `db:"name" json:"name"` // 餐厅名字
}
)
func newFsCanteenTypeModel(conn sqlx.SqlConn) *defaultFsCanteenTypeModel {
return &defaultFsCanteenTypeModel{
conn: conn,
table: "`fs_canteen_type`",
}
}
func (m *defaultFsCanteenTypeModel) Delete(ctx context.Context, id int64) error {
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
_, err := m.conn.ExecCtx(ctx, query, id)
return err
}
func (m *defaultFsCanteenTypeModel) FindOne(ctx context.Context, id int64) (*FsCanteenType, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsCanteenTypeRows, m.table)
var resp FsCanteenType
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
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
}
}
func (m *defaultFsCanteenTypeModel) Insert(ctx context.Context, data *FsCanteenType) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsCanteenTypeRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Sort, data.Status, data.Ctime)
return ret, err
}
func (m *defaultFsCanteenTypeModel) Update(ctx context.Context, data *FsCanteenType) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsCanteenTypeRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Name, data.Sort, data.Status, data.Ctime, data.Id)
return err
}
func (m *defaultFsCanteenTypeModel) tableName() string {
return m.table
}