Skip to content

Commit f3064b3

Browse files
update post summaries to be club specific
1 parent ec43caa commit f3064b3

File tree

5 files changed

+16
-7
lines changed

5 files changed

+16
-7
lines changed

internal/handlers/post.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,22 +253,30 @@ func (h *PostHandler) ListAllPosts(c *gin.Context) {
253253
}
254254

255255
// @Summary List post summaries
256-
// @Description Retrieve summaries of posts with pagination
256+
// @Description Retrieve summarized information about posts in a specific club
257257
// @Tags Posts
258258
// @Accept json
259259
// @Produce json
260+
// @Param id path int true "Club ID"
260261
// @Param limit query int false "Number of posts to retrieve" default(20)
261262
// @Param offset query int false "Number of posts to skip" default(0)
262263
// @Success 200 {array} models.PostSummary "Post summaries retrieved successfully"
263264
// @Failure 500 {object} models.ErrorResponse
264265
// @Router /posts/summaries [get]
265266
func (h *PostHandler) ListPostSummaries(c *gin.Context) {
267+
clubIDParam := c.Param("id")
268+
clubID, err := strconv.ParseUint(clubIDParam, 10, 32)
269+
if err != nil {
270+
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid club ID"})
271+
return
272+
}
273+
266274
limitStr := c.DefaultQuery("limit", "20")
267275
offsetStr := c.DefaultQuery("offset", "0")
268276
limit, _ := strconv.Atoi(limitStr)
269277
offset, _ := strconv.Atoi(offsetStr)
270278

271-
posts, err := h.postService.ListPostSummaries(limit, offset)
279+
posts, err := h.postService.ListPostSummaries(uint(clubID), limit, offset)
272280
if err != nil {
273281
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
274282
return

internal/handlers/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (s *Server) setupRoutes() {
128128

129129
api.GET("/posts/:id/likes", postHandler.ListLikesByPostID)
130130
api.GET("/posts", postHandler.ListAllPosts)
131-
api.GET("/posts/summaries", postHandler.ListPostSummaries)
131+
api.GET("/posts/:id/summaries", postHandler.ListPostSummaries)
132132
api.GET("/posts/:id", postHandler.GetPostByID)
133133

134134
api.GET("/posts/:id/comments", commentHandler.ListCommentsByPostID)

internal/repository/interfaces.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ type PostRepository interface {
8080
GetPostsByType(postType string, limit, offset int) ([]models.Post, error)
8181
GetReviewPostsByBookID(bookID uint) ([]models.Post, error)
8282
GetPollPostsByClubID(clubID uint, includeExpired bool) ([]models.Post, error)
83-
ListPostSummaries(limit, offset int) ([]models.PostSummary, error)
83+
ListPostSummaries(clubID uint, limit, offset int) ([]models.PostSummary, error)
8484
}
8585

8686
type CommentRepository interface {

internal/repository/post.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (r *postRepository) ListAll() ([]models.Post, error) {
8181
return posts, nil
8282
}
8383

84-
func (r *postRepository) ListPostSummaries(limit, offset int) ([]models.PostSummary, error) {
84+
func (r *postRepository) ListPostSummaries(clubID uint, limit, offset int) ([]models.PostSummary, error) {
8585
type row struct {
8686
ID uint `gorm:"column:id"`
8787
Title string `gorm:"column:title"`
@@ -112,6 +112,7 @@ func (r *postRepository) ListPostSummaries(limit, offset int) ([]models.PostSumm
112112
clubs.id as club_id, clubs.name as club_name`).
113113
Joins("LEFT JOIN users ON users.id = posts.user_id").
114114
Joins("LEFT JOIN clubs ON clubs.id = posts.club_id").
115+
Where("posts.club_id = ?", clubID).
115116
Limit(limit).
116117
Offset(offset).
117118
Order("posts.created_at DESC").

internal/services/post.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ func (s *PostService) ListAllPosts() ([]models.PostResponse, error) {
236236
return responses, nil
237237
}
238238

239-
func (s *PostService) ListPostSummaries(limit, offset int) ([]models.PostSummary, error) {
240-
posts, err := s.postRepo.ListPostSummaries(limit, offset)
239+
func (s *PostService) ListPostSummaries(clubID uint, limit, offset int) ([]models.PostSummary, error) {
240+
posts, err := s.postRepo.ListPostSummaries(clubID, limit, offset)
241241
if err != nil {
242242
return nil, err
243243
}

0 commit comments

Comments
 (0)