refac: article reads, story delete, no leaks, stored SEO status, rate limit, cleanup (%site%, article repo split, old lang repos, one default per site rule to domain)
This commit is contained in:
1 parent
9d284e65a9
commit
7c15206170
85 files changed
+1788
-593
No files matched your search
@@ -97,6 +97,26 @@ type articleResponse struct {
|
||||
Capabilities []string `json:"capabilities"`
|
||||
Translations []domain.Translation `json:"translations"`
|
||||
Source *domain.Source `json:"source"`
|
||||
*editorialContext
|
||||
}
|
||||
|
||||
type editorialContext struct {
|
||||
SourceUnavailable bool `json:"source_unavailable"`
|
||||
MissingLangs []string `json:"missing_langs"`
|
||||
ExcludedFromPublic bool `json:"excluded_from_public"`
|
||||
PartialView bool `json:"partial_view"`
|
||||
}
|
||||
|
||||
func editorialContextFor(viewer access.Caller, described useCases.ArticleContext) *editorialContext {
|
||||
if viewer.UserID == 0 {
|
||||
return nil
|
||||
}
|
||||
return &editorialContext{
|
||||
SourceUnavailable: described.SourceUnavailable,
|
||||
MissingLangs: described.MissingLangs,
|
||||
ExcludedFromPublic: described.ExcludedFromPublic,
|
||||
PartialView: described.PartialView,
|
||||
}
|
||||
}
|
||||
|
||||
type listItemResponse struct {
|
||||
@@ -171,6 +191,7 @@ func toArticleResponse(article domain.Article, format domain.BodyFormat, viewer
|
||||
Capabilities: described.Capabilities,
|
||||
Translations: described.Translations,
|
||||
Source: described.Source,
|
||||
editorialContext: editorialContextFor(viewer, described),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -584,11 +605,12 @@ const groupByStory = "story"
|
||||
|
||||
type storyItemResponse struct {
|
||||
listItemResponse
|
||||
StoryUpdatedAt time.Time `json:"story_updated_at"`
|
||||
StoryAuthors []author.Byline `json:"story_authors"`
|
||||
Coverage []domain.Translation `json:"coverage"`
|
||||
MissingLangs []string `json:"missing_langs"`
|
||||
Capabilities []string `json:"capabilities"`
|
||||
StoryUpdatedAt time.Time `json:"story_updated_at"`
|
||||
StoryAuthors []author.Byline `json:"story_authors"`
|
||||
Coverage []domain.Translation `json:"coverage"`
|
||||
MissingLangs []string `json:"missing_langs"`
|
||||
ExcludedFromPublic bool `json:"excluded_from_public"`
|
||||
Capabilities []string `json:"capabilities"`
|
||||
}
|
||||
|
||||
type storyListResponse struct {
|
||||
@@ -704,7 +726,7 @@ func (h *Handler) ListArticles(w http.ResponseWriter, r *http.Request) {
|
||||
page, err := h.listUseCase.ListArticlesPage(useCases.ListArticlesCommand{
|
||||
Format: format,
|
||||
Caller: access.CallerOf(r),
|
||||
Lang: query.Lang,
|
||||
Lang: stringOrEmpty(query.Lang),
|
||||
Author: query.Author,
|
||||
Page: query.Page,
|
||||
Size: query.Size,
|
||||
@@ -771,12 +793,13 @@ func (h *Handler) listStories(w http.ResponseWriter, r *http.Request, format dom
|
||||
return
|
||||
}
|
||||
responses = append(responses, storyItemResponse{
|
||||
listItemResponse: item,
|
||||
StoryUpdatedAt: row.UpdatedAt,
|
||||
StoryAuthors: row.Authors,
|
||||
Coverage: row.Coverage,
|
||||
MissingLangs: row.MissingLangs,
|
||||
Capabilities: row.Capabilities,
|
||||
listItemResponse: item,
|
||||
StoryUpdatedAt: row.UpdatedAt,
|
||||
StoryAuthors: row.Authors,
|
||||
Coverage: row.Coverage,
|
||||
MissingLangs: row.MissingLangs,
|
||||
ExcludedFromPublic: row.ExcludedFromPublic,
|
||||
Capabilities: row.Capabilities,
|
||||
})
|
||||
}
|
||||
writeListJSON(w, storyListResponse{Items: responses, Total: page.Total, Page: page.Page, Size: page.Size, Counts: page.Counts})
|
||||
@@ -798,7 +821,7 @@ func (h *Handler) DeleteArticle(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if err := h.deleteUseCase.DeleteArticle(r.Context(), id, access.CallerOf(r)); err != nil {
|
||||
if !writeKnownArticleError(w, err) {
|
||||
http.Error(w, "Failed to delete article", http.StatusInternalServerError)
|
||||
http.Error(w, apperr.DeleteArticleFailedErrorMessage, http.StatusInternalServerError)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user