|
16 | 16 | DeletePostById(ctx context.Context, postId uint64) error |
17 | 17 | UpdatePostById(ctx context.Context, userId string, postId uint64, req dto.PostUpdateRequest) (dto.PostResponse, error) |
18 | 18 | GetAllPosts(ctx context.Context, req dto.PaginationRequest) (dto.PostPaginationResponse, error) |
| 19 | + GetMyPosts(ctx context.Context, userId string, req dto.PaginationRequest) (dto.PostPaginationResponse, error) |
19 | 20 | } |
20 | 21 |
|
21 | 22 | postService struct { |
@@ -206,3 +207,39 @@ func (s *postService) GetAllPosts(ctx context.Context, req dto.PaginationRequest |
206 | 207 | }, |
207 | 208 | }, nil |
208 | 209 | } |
| 210 | + |
| 211 | +func (s *postService) GetMyPosts(ctx context.Context, userId string, req dto.PaginationRequest) (dto.PostPaginationResponse, error) { |
| 212 | + posts, err := s.postRepo.GetMyPosts(ctx, nil, userId, req) |
| 213 | + if err != nil { |
| 214 | + return dto.PostPaginationResponse{}, dto.ErrGetMyPosts |
| 215 | + } |
| 216 | + |
| 217 | + var data []dto.PostResponse |
| 218 | + for _, post := range posts.Posts { |
| 219 | + datum := dto.PostResponse{ |
| 220 | + ID: post.ID, |
| 221 | + Text: post.Text, |
| 222 | + TotalLikes: post.TotalLikes, |
| 223 | + ParentID: post.ParentID, |
| 224 | + User: dto.UserResponse{ |
| 225 | + ID: post.UserID.String(), |
| 226 | + Name: post.User.Name, |
| 227 | + Bio: post.User.Bio, |
| 228 | + UserName: post.User.Username, |
| 229 | + ImageUrl: post.User.ImageUrl, |
| 230 | + }, |
| 231 | + } |
| 232 | + |
| 233 | + data = append(data, datum) |
| 234 | + } |
| 235 | + |
| 236 | + return dto.PostPaginationResponse{ |
| 237 | + Data: data, |
| 238 | + PaginationResponse: dto.PaginationResponse{ |
| 239 | + Page: posts.Page, |
| 240 | + PerPage: posts.PerPage, |
| 241 | + MaxPage: posts.MaxPage, |
| 242 | + Count: posts.Count, |
| 243 | + }, |
| 244 | + }, nil |
| 245 | +} |
0 commit comments