From ab49f533da7b2ba77a8e8d7b20c968009de7f8e5 Mon Sep 17 00:00:00 2001 From: JonasHiltl Date: Sun, 24 Nov 2024 13:01:34 +0100 Subject: [PATCH] fix get full changelog endpoint --- internal/handler/rest/changelog.go | 37 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/internal/handler/rest/changelog.go b/internal/handler/rest/changelog.go index d8bce12..da311b6 100644 --- a/internal/handler/rest/changelog.go +++ b/internal/handler/rest/changelog.go @@ -259,30 +259,29 @@ func getFullChangelog(e *env, w http.ResponseWriter, r *http.Request) error { return errs.NewBadRequest(err) } + res := apitypes.FullChangelog{ + Changelog: changelogToApiType(cl), + } + page, pageSize := handler.ParsePagination(r.URL.Query()) pagination := internal.NewPagination(pageSize, page) loaded, err := e.loader.LoadAndParseReleaseNotes(r.Context(), cl, pagination) - if err != nil { - return errs.NewBadRequest(err) - } - - articles := make([]apitypes.Article, len(loaded.Notes)) - for i, a := range loaded.Notes { - content, _ := io.ReadAll(a.Content) - articles[i] = apitypes.Article{ - ID: a.Meta.ID, - Title: a.Meta.Title, - Description: a.Meta.Description, - PublishedAt: a.Meta.PublishedAt, - Tags: a.Meta.Tags, - HTMLContent: string(content), + if err == nil { + articles := make([]apitypes.Article, len(loaded.Notes)) + for i, a := range loaded.Notes { + content, _ := io.ReadAll(a.Content) + articles[i] = apitypes.Article{ + ID: a.Meta.ID, + Title: a.Meta.Title, + Description: a.Meta.Description, + PublishedAt: a.Meta.PublishedAt, + Tags: a.Meta.Tags, + HTMLContent: string(content), + } } - } - res := apitypes.FullChangelog{ - Changelog: changelogToApiType(loaded.CL), - Articles: articles, - HasMoreArticles: loaded.HasMore, + res.Articles = articles + res.HasMoreArticles = loaded.HasMore } w.Header().Set("Content-Type", "application/json")