@@ -12,7 +12,7 @@ import (
12
12
type (
13
13
PostService interface {
14
14
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 )
16
16
DeletePostById (ctx context.Context , postId uuid.UUID ) error
17
17
UpdatePostById (ctx context.Context , userId string , postId uuid.UUID , req dto.PostUpdateRequest ) (dto.PostResponse , error )
18
18
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
71
71
}, nil
72
72
}
73
73
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 ) {
75
75
post , err := s .postRepo .GetPostById (ctx , nil , postId )
76
76
if err != nil {
77
- return dto.PostResponse {}, dto .ErrGetPostById
77
+ return dto.PostRepliesResponse {}, dto .ErrGetPostById
78
78
}
79
79
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
+ },
90
123
},
91
- }, nil
124
+ nil
92
125
}
93
126
94
127
func (s * postService ) DeletePostById (ctx context.Context , postId uuid.UUID ) error {
0 commit comments