From 275d8eaaa6becbdf3b82d3fcad8123eafc302e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Thu, 5 Oct 2023 21:18:00 -0700 Subject: [PATCH] Make the feed category optional for API clients who don't support categories --- internal/api/feed.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/internal/api/feed.go b/internal/api/feed.go index a6ddb77ab4c..982a6bf8e0a 100644 --- a/internal/api/feed.go +++ b/internal/api/feed.go @@ -24,6 +24,16 @@ func (h *handler) createFeed(w http.ResponseWriter, r *http.Request) { return } + // Make the feed category optional for clients who don't support categories. + if feedCreationRequest.CategoryID == 0 { + category, err := h.store.FirstCategory(userID) + if err != nil { + json.ServerError(w, r, err) + return + } + feedCreationRequest.CategoryID = category.ID + } + if validationErr := validator.ValidateFeedCreation(h.store, userID, &feedCreationRequest); validationErr != nil { json.BadRequest(w, r, validationErr.Error()) return