From 7714046de23b908e6013cbc5ff21f78724af51b9 Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Wed, 13 Oct 2021 15:11:27 -0400 Subject: [PATCH] responses --- internal/api/watcher.go | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/internal/api/watcher.go b/internal/api/watcher.go index 3d0fcab..4700e82 100644 --- a/internal/api/watcher.go +++ b/internal/api/watcher.go @@ -28,6 +28,10 @@ type createWatcherRequest struct { Criteria watcherCriteria } +type watcherCreatedResponse struct { + ID int64 `json:"id"` +} + func (a *api) createWatcherHandler(w http.ResponseWriter, r *http.Request) { ctx := context.Background() @@ -144,6 +148,8 @@ func (a *api) createWatcherHandler(w http.ResponseWriter, r *http.Request) { } w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(watcherCreatedResponse{ID: watcher.ID}) } func (a *api) editWatcherHandler(w http.ResponseWriter, r *http.Request) { @@ -208,15 +214,15 @@ func (a *api) deleteWatcherHandler(w http.ResponseWriter, r *http.Request) { } type watcherItem struct { - ID int64 - CreatedAt float64 - Type string - Label string - Upvotes int64 - Keyword string - Flair string - Domain string - Hits int64 + ID int64 `json:"id"` + CreatedAt float64 `json:"created_at"` + Type string `json:"type"` + Label string `json:"label"` + Upvotes int64 `json:"upvotes"` + Keyword string `json:"keyword"` + Flair string `json:"flair"` + Domain string `json:"domain"` + Hits int64 `json:"hits"` } func (a *api) listWatchersHandler(w http.ResponseWriter, r *http.Request) {