wip(lyra): 补充链接模型并注入分类缓存依赖
This commit is contained in:
@@ -26,9 +26,10 @@ func buildHandlers(dpd *Dependencies) router.Handlers {
|
||||
}
|
||||
|
||||
func buildDependencies(cfg *config.Config, db *sqlx.DB, cacheClient *redis.Client) *Dependencies {
|
||||
cache := cache.NewCache(cacheClient, time.Duration(cfg.Cache.Timeout)*time.Millisecond)
|
||||
return &Dependencies{
|
||||
Config: cfg,
|
||||
Cache: cache.NewCache(cacheClient, time.Duration(cfg.Cache.Timeout)*time.Millisecond),
|
||||
CategoryModel: model.NewCategoryModel(db),
|
||||
Cache: cache,
|
||||
CategoryModel: model.NewCategoryModel(db, cache),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package model
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"lyra/internal/cache"
|
||||
|
||||
sq "github.com/Masterminds/squirrel"
|
||||
"github.com/jmoiron/sqlx"
|
||||
@@ -19,13 +20,15 @@ type CategoryModel interface {
|
||||
FindAll(ctx context.Context) ([]*Category, error)
|
||||
}
|
||||
type defaultCategoryModel struct {
|
||||
db *sqlx.DB
|
||||
db *sqlx.DB
|
||||
cache *cache.Cache
|
||||
}
|
||||
|
||||
func NewCategoryModel(db *sqlx.DB) CategoryModel {
|
||||
return &defaultCategoryModel{db: db}
|
||||
func NewCategoryModel(db *sqlx.DB, cache *cache.Cache) CategoryModel {
|
||||
return &defaultCategoryModel{db: db, cache: cache}
|
||||
}
|
||||
func (m *defaultCategoryModel) FindAll(ctx context.Context) ([]*Category, error) {
|
||||
|
||||
query, args, err := sq.
|
||||
Select("id", "slug", "title", "sort").
|
||||
From("public.categories").
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"lyra/internal/cache"
|
||||
"time"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
)
|
||||
|
||||
type Link struct {
|
||||
ID int64 `db:"id"`
|
||||
CategoryID int64 `db:"category_id"`
|
||||
Title string `db:"title"`
|
||||
Description string `db:"description"`
|
||||
URL string `db:"url"`
|
||||
Icon *string `db:"icon"`
|
||||
Keywords []string `db:"keywords"`
|
||||
Sort int `db:"sort"`
|
||||
Pinned bool `db:"pinned"`
|
||||
PinnedSort *int `db:"pinned_sort"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}
|
||||
|
||||
type LinkModel interface {
|
||||
}
|
||||
type defaultLinkModel struct {
|
||||
db *sqlx.DB
|
||||
cache *cache.Cache
|
||||
}
|
||||
|
||||
func NewLinkModel(db *sqlx.DB, cache *cache.Cache) CategoryModel {
|
||||
return &defaultCategoryModel{db: db, cache: cache}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
package constant
|
||||
|
||||
Reference in New Issue
Block a user