@@ -12,7 +12,7 @@ import (
1212type (
1313 PostService interface {
1414 CreatePost (ctx context.Context , userId string , req dto.PostCreateRequest ) (dto.PostResponse , error )
15- GetPostById (ctx context.Context , postId uuid.UUID ) (dto.PostResponse , error )
15+ GetPostById (ctx context.Context , postId uuid.UUID ) (dto.PostRepliesResponse , error )
1616 DeletePostById (ctx context.Context , postId uuid.UUID ) error
1717 UpdatePostById (ctx context.Context , userId string , postId uuid.UUID , req dto.PostUpdateRequest ) (dto.PostResponse , error )
1818 GetAllPosts (ctx context.Context , req dto.PaginationRequest ) (dto.PostPaginationResponse , error )
@@ -71,24 +71,57 @@ func (s *postService) CreatePost(ctx context.Context, userId string, req dto.Pos
7171 }, nil
7272}
7373
74- func (s * postService ) GetPostById (ctx context.Context , postId uuid.UUID ) (dto.PostResponse , error ) {
74+ func (s * postService ) GetPostById (ctx context.Context , postId uuid.UUID ) (dto.PostRepliesResponse , error ) {
7575 post , err := s .postRepo .GetPostById (ctx , nil , postId )
7676 if err != nil {
77- return dto.PostResponse {}, dto .ErrGetPostById
77+ return dto.PostRepliesResponse {}, dto .ErrGetPostById
7878 }
7979
80- return dto.PostResponse {
81- ID : post .ID .String (),
82- Text : post .Text ,
83- ParentID : post .ParentID ,
84- User : dto.UserResponse {
85- ID : post .UserID .String (),
86- Name : post .User .Name ,
87- Bio : post .User .Bio ,
88- UserName : post .User .Username ,
89- ImageUrl : post .User .ImageUrl ,
80+ replies , err := s .postRepo .GetAllPostRepliesWithPagination (ctx , nil , postId , dto.PaginationRequest {})
81+ if err != nil {
82+ return dto.PostRepliesResponse {}, dto .ErrGetPostReplies
83+ }
84+
85+ var data []dto.PostResponse
86+ for _ , reply := range replies .Replies {
87+ datum := dto.PostResponse {
88+ ID : reply .ID .String (),
89+ Text : reply .Text ,
90+ ParentID : reply .ParentID ,
91+ User : dto.UserResponse {
92+ ID : reply .UserID .String (),
93+ Name : reply .User .Name ,
94+ Bio : reply .User .Bio ,
95+ UserName : reply .User .Username ,
96+ ImageUrl : reply .User .ImageUrl ,
97+ },
98+ }
99+
100+ data = append (data , datum )
101+ }
102+
103+ return dto.PostRepliesResponse {
104+ PostResponse : dto.PostResponse {
105+ ID : post .ID .String (),
106+ Text : post .Text ,
107+ ParentID : post .ParentID ,
108+ User : dto.UserResponse {
109+ ID : post .UserID .String (),
110+ Name : post .User .Name ,
111+ Bio : post .User .Bio ,
112+ UserName : post .User .Username ,
113+ ImageUrl : post .User .ImageUrl ,
114+ },
115+ },
116+ Replies : data ,
117+ PaginationResponse : dto.PaginationResponse {
118+ Page : replies .Page ,
119+ PerPage : replies .PerPage ,
120+ MaxPage : replies .MaxPage ,
121+ Count : replies .Count ,
122+ },
90123 },
91- }, nil
124+ nil
92125}
93126
94127func (s * postService ) DeletePostById (ctx context.Context , postId uuid.UUID ) error {
0 commit comments