最新成果
This commit is contained in:
parent
5446c4123a
commit
7ffbce7759
@ -42,8 +42,8 @@
|
|||||||
|
|
||||||
#### 使用说明
|
#### 使用说明
|
||||||
|
|
||||||
1. xxxx
|
1. goctl api go -api home-user-auth.api -dir home-user-auth
|
||||||
2. xxxx
|
2. goctl model mysql ddl --src ./ddl/fs_canteen_type.sql --dir model/
|
||||||
3. xxxx
|
3. xxxx
|
||||||
|
|
||||||
#### 参与贡献
|
#### 参与贡献
|
||||||
|
10
ddl/fs_canteen_type.sql
Normal file
10
ddl/fs_canteen_type.sql
Normal 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='餐厅类型表';
|
@ -11,17 +11,18 @@ import "basic.api"
|
|||||||
|
|
||||||
type request {
|
type request {
|
||||||
// TODO: add members here and delete this comment
|
// 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 {
|
service home-user-auth {
|
||||||
@handler UserFontsHandler
|
@handler UserFontsHandler
|
||||||
get /user/fonts(request) returns (response);
|
get /user/fonts(request) returns (response);
|
||||||
}
|
|
||||||
|
|
||||||
// FsFonts 字体表
|
@handler GetTypeHandler
|
||||||
type FsFonts {
|
get /user/get-type(request) returns (response);
|
||||||
Title string `json:"title" gorm:"column:title"`
|
|
||||||
LinuxFontname string `json:"linux_fontname" gorm:"column:linux_fontname"`
|
|
||||||
Link string `json:"link" gorm:"link"`
|
|
||||||
}
|
}
|
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",
|
Path: "/user/fonts",
|
||||||
Handler: UserFontsHandler(serverCtx),
|
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 {
|
type ServiceContext struct {
|
||||||
Config config.Config
|
Config config.Config
|
||||||
FsFontModel model.FsFontModel
|
FsFontModel model.FsFontModel
|
||||||
|
FsCanteenTypeModel model.FsCanteenTypeModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServiceContext(c config.Config) *ServiceContext {
|
func NewServiceContext(c config.Config) *ServiceContext {
|
||||||
|
conn := sqlx.NewMysql(c.DataSource)
|
||||||
return &ServiceContext{
|
return &ServiceContext{
|
||||||
Config: c,
|
Config: c,
|
||||||
FsFontModel: model.NewFsFontModel(sqlx.NewMysql(c.DataSource)),
|
FsFontModel: model.NewFsFontModel(conn),
|
||||||
|
FsCanteenTypeModel: model.NewFsCanteenTypeModel(conn),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,13 +2,11 @@
|
|||||||
package types
|
package types
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Name string `form:"name"` // parameters are auto validated
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type FsFonts struct {
|
type GetTypeData struct {
|
||||||
Title string `json:"title" gorm:"column:title"`
|
Id int64 `db:"id" json:"key"` // ID
|
||||||
LinuxFontname string `json:"linux_fontname" gorm:"column:linux_fontname"`
|
Name string `db:"name" json:"name"` // 餐厅名字
|
||||||
Link string `json:"link" gorm:"link"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Response struct {
|
type Response struct {
|
||||||
|
24
model/fscanteentypemodel.go
Executable file
24
model/fscanteentypemodel.go
Executable 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
112
model/fscanteentypemodel_gen.go
Executable 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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user