fix: moved to encoding/json/v2

This commit is contained in:
2026-08-31 18:44:22 +02:00
parent 73df97548b
commit eaf676f8b4
4 changed files with 17 additions and 13 deletions
+6 -6
View File
@@ -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)) 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 // 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)) 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 // 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)) 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 // 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)) 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 // 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)) 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 // 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)) 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 // GetListItems handles return all list items of a list
+1 -1
View File
@@ -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)) slog.InfoContext(ctx, "password changed successfully", slog.Any("user_id", authContext.UserID))
response.Status(ctx, w, http.StatusNoContent) response.Status(w, http.StatusNoContent)
} }
+9
View File
@@ -0,0 +1,9 @@
package response
import (
"net/http"
)
func Status(w http.ResponseWriter, status int) {
w.WriteHeader(status)
}
+1 -6
View File
@@ -2,16 +2,11 @@ package response
import ( import (
"context" "context"
"encoding/json" "encoding/json/v2"
"log/slog" "log/slog"
"net/http" "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) { func JSON(ctx context.Context, w http.ResponseWriter, status int, data any) {
payload, err := json.Marshal(data) payload, err := json.Marshal(data)
if err != nil { if err != nil {