完成 /user/fonts 功能
This commit is contained in:
parent
e1e0e5ef21
commit
5446c4123a
|
@ -25,15 +25,17 @@ func NewUserFontsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserFon
|
|||
|
||||
func (l *UserFontsLogic) UserFonts(req *types.Request) (resp *types.Response, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
f, err := l.svcCtx.FsFontModel.FindOne(context.TODO(), 10)
|
||||
f, err := l.svcCtx.FsFontModel.FindAllOrderSortByDesc(l.ctx)
|
||||
if err != nil {
|
||||
// panic(err)
|
||||
logx.Error(err)
|
||||
return
|
||||
}
|
||||
logx.Info(f)
|
||||
// logx.Info(f)
|
||||
resp = &types.Response{
|
||||
Data: f,
|
||||
Code: 200,
|
||||
Message: "success",
|
||||
Data: f,
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ type ServiceContext struct {
|
|||
}
|
||||
|
||||
func NewServiceContext(c config.Config) *ServiceContext {
|
||||
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
FsFontModel: model.NewFsFontModel(sqlx.NewMysql(c.DataSource)),
|
||||
|
|
|
@ -27,6 +27,7 @@ type (
|
|||
FindOne(ctx context.Context, id int64) (*FsFont, error)
|
||||
Update(ctx context.Context, data *FsFont) error
|
||||
Delete(ctx context.Context, id int64) error
|
||||
FindAllOrderSortByDesc(ctx context.Context) ([]*FsFont, error)
|
||||
}
|
||||
|
||||
defaultFsFontModel struct {
|
||||
|
@ -70,6 +71,20 @@ func (m *defaultFsFontModel) FindOne(ctx context.Context, id int64) (*FsFont, er
|
|||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFsFontModel) Insert(ctx context.Context, data *FsFont) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsFontRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Title, data.LinuxFontname, data.FilePath, data.Sort)
|
||||
|
|
Loading…
Reference in New Issue
Block a user