@@ -7,11 +7,13 @@ import (
77 "github.com/Lab-RPL-ITS/twitter-clone-api/service"
88 "github.com/Lab-RPL-ITS/twitter-clone-api/utils"
99 "github.com/gin-gonic/gin"
10+ "github.com/google/uuid"
1011)
1112
1213type (
1314 PostController interface {
14- Create (ctx * gin.Context )
15+ CreatePost (ctx * gin.Context )
16+ GetPostById (ctx * gin.Context )
1517 }
1618
1719 postController struct {
@@ -25,7 +27,7 @@ func NewPostController(ps service.PostService) PostController {
2527 }
2628}
2729
28- func (c * postController ) Create (ctx * gin.Context ) {
30+ func (c * postController ) CreatePost (ctx * gin.Context ) {
2931 var post dto.PostCreateRequest
3032 if err := ctx .ShouldBind (& post ); err != nil {
3133 res := utils .BuildResponseFailed (dto .MESSAGE_FAILED_GET_POST_DATA_FROM_BODY , err .Error (), nil )
@@ -43,3 +45,22 @@ func (c *postController) Create(ctx *gin.Context) {
4345 res := utils .BuildResponseSuccess (dto .MESSAGE_SUCCESS_CREATE_POST , result )
4446 ctx .JSON (http .StatusOK , res )
4547}
48+
49+ func (c * postController ) GetPostById (ctx * gin.Context ) {
50+ postId , err := uuid .Parse (ctx .Param ("post_id" ))
51+ if err != nil {
52+ res := utils .BuildResponseFailed (dto .MESSAGE_FAILED_GET_POST_ID , err .Error (), nil )
53+ ctx .AbortWithStatusJSON (http .StatusBadRequest , res )
54+ return
55+ }
56+
57+ result , err := c .postService .GetPostById (ctx .Request .Context (), postId )
58+ if err != nil {
59+ res := utils .BuildResponseFailed (dto .MESSAGE_FAILED_GET_POST_ID , err .Error (), nil )
60+ ctx .JSON (http .StatusBadRequest , res )
61+ return
62+ }
63+
64+ res := utils .BuildResponseSuccess (dto .MESSAGE_SUCCESS_CREATE_POST , result )
65+ ctx .JSON (http .StatusOK , res )
66+ }
0 commit comments