diff --git a/home-user-auth/internal/logic/userfontslogic.go b/home-user-auth/internal/logic/userfontslogic.go index 22bb6eb5..495beb78 100644 --- a/home-user-auth/internal/logic/userfontslogic.go +++ b/home-user-auth/internal/logic/userfontslogic.go @@ -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 } diff --git a/home-user-auth/internal/svc/servicecontext.go b/home-user-auth/internal/svc/servicecontext.go index 0fc08171..a46c275b 100644 --- a/home-user-auth/internal/svc/servicecontext.go +++ b/home-user-auth/internal/svc/servicecontext.go @@ -13,6 +13,7 @@ type ServiceContext struct { } func NewServiceContext(c config.Config) *ServiceContext { + return &ServiceContext{ Config: c, FsFontModel: model.NewFsFontModel(sqlx.NewMysql(c.DataSource)), diff --git a/model/fsfontmodel_gen.go b/model/fsfontmodel_gen.go index 69ddeaec..be14369e 100755 --- a/model/fsfontmodel_gen.go +++ b/model/fsfontmodel_gen.go @@ -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)