refactor: use DTOs instead of manual maps in post responses

This commit is contained in:
2026-01-10 22:34:20 +01:00
parent 523dac242e
commit 2d58c15031

View File

@@ -64,12 +64,13 @@ func (h *PostHandler) GetPosts(w http.ResponseWriter, r *http.Request) {
} }
postDTOs := dto.ToPostDTOs(posts) postDTOs := dto.ToPostDTOs(posts)
SendSuccessResponse(w, "Posts retrieved successfully", map[string]any{ responseDTO := dto.PostListDTO{
"posts": postDTOs, Posts: postDTOs,
"count": len(postDTOs), Count: len(postDTOs),
"limit": limit, Limit: limit,
"offset": offset, Offset: offset,
}) }
SendSuccessResponse(w, "Posts retrieved successfully", responseDTO)
} }
// @Summary Get a single post // @Summary Get a single post
@@ -230,13 +231,14 @@ func (h *PostHandler) SearchPosts(w http.ResponseWriter, r *http.Request) {
} }
postDTOs := dto.ToPostDTOs(posts) postDTOs := dto.ToPostDTOs(posts)
SendSuccessResponse(w, "Search results retrieved successfully", map[string]any{ responseDTO := dto.SearchPostListDTO{
"posts": postDTOs, Posts: postDTOs,
"count": len(postDTOs), Count: len(postDTOs),
"query": query, Query: query,
"limit": limit, Limit: limit,
"offset": offset, Offset: offset,
}) }
SendSuccessResponse(w, "Search results retrieved successfully", responseDTO)
} }
// @Summary Update a post // @Summary Update a post