You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
package article
|
|
|
|
|
|
|
|
import (
|
|
|
|
"cls/internal/domain/article"
|
|
|
|
"cls/pkg/logger"
|
|
|
|
"cls/pkg/util/page"
|
|
|
|
"cls/pkg/xorm_engine"
|
|
|
|
"errors"
|
|
|
|
"xorm.io/builder"
|
|
|
|
)
|
|
|
|
|
|
|
|
type ArticleRepositoryORM struct {
|
|
|
|
engine *xorm_engine.Engine
|
|
|
|
log logger.Logger
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ article.ArticleRepository = (*ArticleRepositoryORM)(nil)
|
|
|
|
|
|
|
|
func NewArticleRepositoryORM(db *xorm_engine.Engine, log logger.New) article.ArticleRepository {
|
|
|
|
return &ArticleRepositoryORM{db, log("cls:persistence:article")}
|
|
|
|
}
|
|
|
|
func (a ArticleRepositoryORM) Find(page *page.Page, conds []builder.Cond) error {
|
|
|
|
page.Desc = append(page.Desc, "ctime")
|
|
|
|
//err := a.engine.Cls.Desc("ctime").Limit(page.PageSize, page.PageNumber*page.PageSize).
|
|
|
|
// Find(page.Content, &article.LianV1Article{})
|
|
|
|
|
|
|
|
err := a.engine.FindAllCls(page, &article.LianV1Article{}, builder.And(conds...))
|
|
|
|
if err != nil {
|
|
|
|
a.log.Error(err.Error())
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a ArticleRepositoryORM) GetArticleById(id uint64) (*article.LianV1Article, error) {
|
|
|
|
article := &article.LianV1Article{}
|
|
|
|
has, err := a.engine.Cls.Where(builder.Eq{"id": id}).Get(article)
|
|
|
|
if err != nil {
|
|
|
|
a.log.Error(err)
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if !has {
|
|
|
|
a.log.Errorf("未查询到文章【%d】", id)
|
|
|
|
return nil, errors.New("")
|
|
|
|
}
|
|
|
|
return article, nil
|
|
|
|
}
|