fix
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
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)
|
||||
|
||||
@@ -9,6 +15,7 @@ type (
|
||||
// and implement the added methods in customFsCanteenTypeModel.
|
||||
FsCanteenTypeModel interface {
|
||||
fsCanteenTypeModel
|
||||
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
|
||||
}
|
||||
|
||||
customFsCanteenTypeModel struct {
|
||||
@@ -22,3 +29,25 @@ func NewFsCanteenTypeModel(conn sqlx.SqlConn) FsCanteenTypeModel {
|
||||
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
// FsGetTypeCanteenType GetType返回前端的结构
|
||||
type FsGetTypeCanteenType struct {
|
||||
Id int64 `db:"id" json:"key"` // ID
|
||||
Name string `db:"name" json:"name"` // 餐厅名字
|
||||
}
|
||||
|
||||
// FindGetType 根据status = 1查询出所有,fs_canteen_type 的类型,并排序desc
|
||||
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)
|
||||
Update(ctx context.Context, data *FsCanteenType) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
|
||||
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
|
||||
}
|
||||
|
||||
defaultFsCanteenTypeModel struct {
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
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)
|
||||
|
||||
@@ -9,6 +15,7 @@ type (
|
||||
// and implement the added methods in customFsFontModel.
|
||||
FsFontModel interface {
|
||||
fsFontModel
|
||||
FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error)
|
||||
}
|
||||
|
||||
customFsFontModel struct {
|
||||
@@ -22,3 +29,18 @@ func NewFsFontModel(conn sqlx.SqlConn) FsFontModel {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user