diff --git a/internal/api/handler/list.go b/internal/api/handler/list.go index 740f431..3afd0c4 100644 --- a/internal/api/handler/list.go +++ b/internal/api/handler/list.go @@ -95,7 +95,7 @@ func (h *ListHandler) DeleteList(w http.ResponseWriter, r *http.Request) { } slog.InfoContext(ctx, "deleted list successfully", slog.Any("list_id", listID)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } // GetLists handles fetching lists for the current user @@ -175,7 +175,7 @@ func (h *ListHandler) AddUserToList(w http.ResponseWriter, r *http.Request) { } slog.InfoContext(ctx, "added user to list successfully", slog.Any("list_id", payload.ListID), slog.Any("email", user.Email)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } // RemoveUserFromList handles the removal of a user association to a list @@ -223,7 +223,7 @@ func (h *ListHandler) RemoveUserFromList(w http.ResponseWriter, r *http.Request) } slog.InfoContext(ctx, "removed user from list successfully", slog.Any("list_id", payload.ListID), slog.Any("email", user.Email)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } // CreateListItem handles creation of a new list item on a given list @@ -303,7 +303,7 @@ func (h *ListHandler) DeleteListItem(w http.ResponseWriter, r *http.Request) { } slog.InfoContext(ctx, "deleted list item successfully", slog.Any("list_item_id", listItemID)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } // UpdateListItem handles updating of a list item @@ -344,7 +344,7 @@ func (h *ListHandler) UpdateListItem(w http.ResponseWriter, r *http.Request) { } slog.InfoContext(ctx, "updated list item successfully", slog.Any("list_item_id", payload.ListItemID)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } // SetListItemCompleted handles updating "is_completed" of a list item @@ -394,7 +394,7 @@ func (h *ListHandler) SetListItemCompleted(w http.ResponseWriter, r *http.Reques } slog.InfoContext(ctx, "updated list item completed successful", slog.Any("list_item_id", listItemID)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } // GetListItems handles return all list items of a list diff --git a/internal/api/handler/user.go b/internal/api/handler/user.go index 8b49bb2..cc29fa6 100644 --- a/internal/api/handler/user.go +++ b/internal/api/handler/user.go @@ -102,5 +102,5 @@ func (h *UserHandler) ChangePassword(w http.ResponseWriter, r *http.Request) { } slog.InfoContext(ctx, "password changed successfully", slog.Any("user_id", authContext.UserID)) - response.Status(ctx, w, http.StatusNoContent) + response.Status(w, http.StatusNoContent) } diff --git a/internal/api/response/header_only.go b/internal/api/response/header_only.go new file mode 100644 index 0000000..ef31e58 --- /dev/null +++ b/internal/api/response/header_only.go @@ -0,0 +1,9 @@ +package response + +import ( + "net/http" +) + +func Status(w http.ResponseWriter, status int) { + w.WriteHeader(status) +} diff --git a/internal/api/response/json.go b/internal/api/response/json.go index a189d4d..9e69078 100644 --- a/internal/api/response/json.go +++ b/internal/api/response/json.go @@ -2,16 +2,11 @@ package response import ( "context" - "encoding/json" + "encoding/json/v2" "log/slog" "net/http" ) -// TODO: Move to own file -func Status(ctx context.Context, w http.ResponseWriter, status int) { - w.WriteHeader(status) -} - func JSON(ctx context.Context, w http.ResponseWriter, status int, data any) { payload, err := json.Marshal(data) if err != nil {