@@ -23,6 +23,17 @@ func NewPostHandler(postService *services.PostService) *PostHandler {
2323 }
2424}
2525
26+ // @Summary Create a new post
27+ // @Description Create a new post associated with the authenticated user
28+ // @Tags Posts
29+ // @Accept json
30+ // @Produce json
31+ // @Param post body models.CreatePostRequest true "Post data"
32+ // @Success 201 {object} models.Post "Post created successfully"
33+ // @Failure 400 {object} gin.H "Bad request"
34+ // @Failure 401 {object} gin.H "Unauthorized"
35+ // @Failure 500 {object} gin.H "Internal server error"
36+ // @Router /posts [post]
2637func (h * PostHandler ) CreatePost (c * gin.Context ) {
2738 useridRaw , exists := c .Get ("user_id" )
2839 if ! exists {
@@ -59,6 +70,17 @@ func (h *PostHandler) CreatePost(c *gin.Context) {
5970 })
6071}
6172
73+ // @Summary Get a post by ID
74+ // @Description Retrieve a post by its ID
75+ // @Tags Posts
76+ // @Accept json
77+ // @Produce json
78+ // @Param id path int true "Post ID"
79+ // @Success 200 {object} models.Post "Post retrieved successfully"
80+ // @Failure 400 {object} gin.H "Bad request"
81+ // @Failure 404 {object} gin.H "Post not found"
82+ // @Failure 500 {object} gin.H "Internal server error"
83+ // @Router /posts/{id} [get]
6284func (h * PostHandler ) GetPostByID (c * gin.Context ) {
6385 idParam := c .Param ("id" )
6486 id , err := strconv .ParseUint (idParam , 10 , 32 )
@@ -80,6 +102,18 @@ func (h *PostHandler) GetPostByID(c *gin.Context) {
80102 c .JSON (http .StatusOK , gin.H {"post" : post })
81103}
82104
105+ // @Summary Update a post
106+ // @Description Update a post by its ID
107+ // @Tags Posts
108+ // @Accept json
109+ // @Produce json
110+ // @Param id path int true "Post ID"
111+ // @Param post body models.UpdatePostRequest true "Updated post data"
112+ // @Success 200 {object} models.Post "Post updated successfully"
113+ // @Failure 400 {object} gin.H "Bad request"
114+ // @Failure 404 {object} gin.H "Post not found"
115+ // @Failure 500 {object} gin.H "Internal server error"
116+ // @Router /posts/{id} [put]
83117func (h * PostHandler ) UpdatePost (c * gin.Context ) {
84118 idParam := c .Param ("id" )
85119 id , err := strconv .ParseUint (idParam , 10 , 32 )
@@ -115,6 +149,17 @@ func (h *PostHandler) UpdatePost(c *gin.Context) {
115149 })
116150}
117151
152+ // @Summary Delete a post
153+ // @Description Delete a post by its ID
154+ // @Tags Posts
155+ // @Accept json
156+ // @Produce json
157+ // @Param id path int true "Post ID"
158+ // @Success 204 {object} nil "Post deleted successfully"
159+ // @Failure 400 {object} gin.H "Bad request"
160+ // @Failure 404 {object} gin.H "Post not found"
161+ // @Failure 500 {object} gin.H "Internal server error"
162+ // @Router /posts/{id} [delete]
118163func (h * PostHandler ) DeletePost (c * gin.Context ) {
119164 idParam := c .Param ("id" )
120165 id , err := strconv .ParseUint (idParam , 10 , 32 )
@@ -135,6 +180,16 @@ func (h *PostHandler) DeletePost(c *gin.Context) {
135180 c .Status (http .StatusNoContent )
136181}
137182
183+ // @Summary List posts by user ID
184+ // @Description Retrieve all posts created by a specific user
185+ // @Tags Posts
186+ // @Accept json
187+ // @Produce json
188+ // @Param id path int true "User ID"
189+ // @Success 200 {array} models.Post "Posts retrieved successfully"
190+ // @Failure 400 {object} gin.H "Bad request"
191+ // @Failure 500 {object} gin.H "Internal server error"
192+ // @Router /users/{id}/posts [get]
138193func (h * PostHandler ) ListPostsByUserID (c * gin.Context ) {
139194 userIDParam := c .Param ("id" )
140195 userID , err := strconv .ParseUint (userIDParam , 10 , 32 )
@@ -152,6 +207,16 @@ func (h *PostHandler) ListPostsByUserID(c *gin.Context) {
152207 c .JSON (http .StatusOK , gin.H {"posts" : posts })
153208}
154209
210+ // @Summary List posts by club ID
211+ // @Description Retrieve all posts associated with a specific club
212+ // @Tags Posts
213+ // @Accept json
214+ // @Produce json
215+ // @Param id path int true "Club ID"
216+ // @Success 200 {array} models.Post "Posts retrieved successfully"
217+ // @Failure 400 {object} gin.H "Bad request"
218+ // @Failure 500 {object} gin.H "Internal server error"
219+ // @Router /clubs/{id}/posts [get]
155220func (h * PostHandler ) ListPostsByClubID (c * gin.Context ) {
156221 clubIDParam := c .Param ("id" )
157222 clubID , err := strconv .ParseUint (clubIDParam , 10 , 32 )
@@ -169,6 +234,14 @@ func (h *PostHandler) ListPostsByClubID(c *gin.Context) {
169234 c .JSON (http .StatusOK , gin.H {"posts" : posts })
170235}
171236
237+ // @Summary List all posts
238+ // @Description Retrieve all posts in the system
239+ // @Tags Posts
240+ // @Accept json
241+ // @Produce json
242+ // @Success 200 {array} models.Post "Posts retrieved successfully"
243+ // @Failure 500 {object} gin.H "Internal server error"
244+ // @Router /posts [get]
172245func (h * PostHandler ) ListAllPosts (c * gin.Context ) {
173246 posts , err := h .postService .ListAllPosts ()
174247 if err != nil {
@@ -179,6 +252,18 @@ func (h *PostHandler) ListAllPosts(c *gin.Context) {
179252 c .JSON (http .StatusOK , gin.H {"posts" : posts })
180253}
181254
255+ // @Summary Like a post
256+ // @Description Like a post by its ID
257+ // @Tags Posts
258+ // @Accept json
259+ // @Produce json
260+ // @Param id path int true "Post ID"
261+ // @Success 200 {object} gin.H "Post liked successfully"
262+ // @Failure 400 {object} gin.H "Bad request"
263+ // @Failure 401 {object} gin.H "Unauthorized"
264+ // @Failure 404 {object} gin.H "Post not found"
265+ // @Failure 500 {object} gin.H "Internal server error"
266+ // @Router /posts/{id}/like [post]
182267func (h * PostHandler ) LikePost (c * gin.Context ) {
183268 postIdParam := c .Param ("id" )
184269 postID , err := strconv .ParseUint (postIdParam , 10 , 32 )
@@ -214,6 +299,18 @@ func (h *PostHandler) LikePost(c *gin.Context) {
214299 c .JSON (http .StatusOK , gin.H {"message" : "post liked successfully" })
215300}
216301
302+ // @Summary Unlike a post
303+ // @Description Unlike a post by its ID
304+ // @Tags Posts
305+ // @Accept json
306+ // @Produce json
307+ // @Param id path int true "Post ID"
308+ // @Success 200 {object} gin.H "Post unliked successfully"
309+ // @Failure 400 {object} gin.H "Bad request"
310+ // @Failure 401 {object} gin.H "Unauthorized"
311+ // @Failure 404 {object} gin.H "Post not found"
312+ // @Failure 500 {object} gin.H "Internal server error"
313+ // @Router /posts/{id}/unlike [post]
217314func (h * PostHandler ) UnlikePost (c * gin.Context ) {
218315 postIdParam := c .Param ("id" )
219316 postID , err := strconv .ParseUint (postIdParam , 10 , 32 )
@@ -249,6 +346,17 @@ func (h *PostHandler) UnlikePost(c *gin.Context) {
249346 c .JSON (http .StatusOK , gin.H {"message" : "post unliked successfully" })
250347}
251348
349+ // @Summary List likes by post ID
350+ // @Description Retrieve all likes associated with a specific post
351+ // @Tags Posts
352+ // @Accept json
353+ // @Produce json
354+ // @Param id path int true "Post ID"
355+ // @Success 200 {array} models.Like "Likes retrieved successfully"
356+ // @Failure 400 {object} gin.H "Bad request"
357+ // @Failure 404 {object} gin.H "Post not found or no likes found"
358+ // @Failure 500 {object} gin.H "Internal server error"
359+ // @Router /posts/{id}/likes [get]
252360func (h * PostHandler ) ListLikesByPostID (c * gin.Context ) {
253361 postIdParam := c .Param ("id" )
254362 postID , err := strconv .ParseUint (postIdParam , 10 , 32 )
0 commit comments