feat: public API, SEO and existing surfaces
This commit is contained in:
1 parent
45fbbc33b1
commit
c390fcfe8d
103 files changed
+4476
-231
No files matched your search
@@ -64,12 +64,22 @@ func (a *ArticleRepository) scoped(filters domain.Filters) *gorm.DB {
|
||||
if filters.Lang != nil {
|
||||
query = query.Where("lang = ?", *filters.Lang)
|
||||
}
|
||||
if filters.Langs != nil {
|
||||
query = restrictToLangs(query, *filters.Langs)
|
||||
}
|
||||
if filters.AuthorID != nil {
|
||||
query = query.Where("id IN (SELECT article_id FROM article_authors WHERE author_id = ?)", *filters.AuthorID)
|
||||
}
|
||||
return query
|
||||
}
|
||||
|
||||
func restrictToLangs(query *gorm.DB, langs []string) *gorm.DB {
|
||||
if len(langs) == 0 {
|
||||
return query.Where("1 = 0")
|
||||
}
|
||||
return query.Where("lang IN ?", langs)
|
||||
}
|
||||
|
||||
var sortColumns = map[domain.SortField]string{
|
||||
domain.SortByTitle: "LOWER(title)",
|
||||
domain.SortByStatus: "is_online",
|
||||
@@ -348,6 +358,15 @@ func (a *ArticleRepository) GetByName(name string) (domain.Article, error) {
|
||||
return a.withAuthorsOne(a.db, mappers.ArticleToDomain(article))
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) GetByLangSlug(siteID uint32, lang string, slug string) (domain.Article, error) {
|
||||
var found entity.Article
|
||||
err := a.db.Model(&entity.Article{}).Where("site_id = ? AND lang = ? AND slug = ?", siteID, lang, slug).First(&found).Error
|
||||
if err != nil {
|
||||
return domain.Article{}, mapNotFoundErr(err, domain.ErrArticleNotFound)
|
||||
}
|
||||
return a.withAuthorsOne(a.db, mappers.ArticleToDomain(found))
|
||||
}
|
||||
|
||||
func (a *ArticleRepository) Create(article domain.Article) (domain.Article, error) {
|
||||
created := mappers.ArticleToModel(article.Opened())
|
||||
err := a.db.Transaction(func(tx *gorm.DB) error {
|
||||
|
||||
Reference in new issue
Block a user