@@ -19,17 +19,20 @@ type (
1919 Verify (ctx context.Context , req dto.UserLoginRequest ) (dto.UserLoginResponse , error )
2020 GetUserByUsername (ctx context.Context , username string ) (dto.UserResponse , error )
2121 UpdateUser (ctx context.Context , userId string , req dto.UserProfileUpdateRequest ) (dto.UserResponse , error )
22+ GetUserPosts (ctx context.Context , username string , req dto.PaginationRequest ) (dto.PostPaginationResponse , error )
2223 }
2324
2425 userService struct {
2526 userRepo repository.UserRepository
27+ postRepo repository.PostRepository
2628 jwtService JWTService
2729 }
2830)
2931
30- func NewUserService (userRepo repository.UserRepository , jwtService JWTService ) UserService {
32+ func NewUserService (userRepo repository.UserRepository , postRepo repository. PostRepository , jwtService JWTService ) UserService {
3133 return & userService {
3234 userRepo : userRepo ,
35+ postRepo : postRepo ,
3336 jwtService : jwtService ,
3437 }
3538}
@@ -161,3 +164,39 @@ func (s *userService) UpdateUser(ctx context.Context, userId string, req dto.Use
161164 ImageUrl : userUpdate .ImageUrl ,
162165 }, nil
163166}
167+
168+ func (s * userService ) GetUserPosts (ctx context.Context , username string , req dto.PaginationRequest ) (dto.PostPaginationResponse , error ) {
169+ dataWithPaginate , err := s .postRepo .GetAllPostsWithPaginationByUsername (ctx , nil , username , req )
170+ if err != nil {
171+ return dto.PostPaginationResponse {}, err
172+ }
173+
174+ var data []dto.PostResponse
175+ for _ , post := range dataWithPaginate .Posts {
176+ datum := dto.PostResponse {
177+ ID : post .ID ,
178+ Text : post .Text ,
179+ TotalLikes : post .TotalLikes ,
180+ ParentID : post .ParentID ,
181+ User : dto.UserResponse {
182+ ID : post .UserID .String (),
183+ Name : post .User .Name ,
184+ Bio : post .User .Bio ,
185+ UserName : post .User .Username ,
186+ ImageUrl : post .User .ImageUrl ,
187+ },
188+ }
189+
190+ data = append (data , datum )
191+ }
192+
193+ return dto.PostPaginationResponse {
194+ Data : data ,
195+ PaginationResponse : dto.PaginationResponse {
196+ Page : dataWithPaginate .Page ,
197+ PerPage : dataWithPaginate .PerPage ,
198+ MaxPage : dataWithPaginate .MaxPage ,
199+ Count : dataWithPaginate .Count ,
200+ },
201+ }, nil
202+ }
0 commit comments