|
15 | 15 | GetPostById(ctx context.Context, postId uuid.UUID) (dto.PostResponse, 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 | + GetAllPosts(ctx context.Context, req dto.PaginationRequest) (dto.PostPaginationResponse, error) |
18 | 19 | } |
19 | 20 |
|
20 | 21 | postService struct { |
@@ -133,3 +134,38 @@ func (s *postService) UpdatePostById(ctx context.Context, userId string, postId |
133 | 134 | }, |
134 | 135 | }, nil |
135 | 136 | } |
| 137 | + |
| 138 | +func (s *postService) GetAllPosts(ctx context.Context, req dto.PaginationRequest) (dto.PostPaginationResponse, error) { |
| 139 | + dataWithPaginate, err := s.postRepo.GetAllPostsWithPagination(ctx, nil, req) |
| 140 | + if err != nil { |
| 141 | + return dto.PostPaginationResponse{}, err |
| 142 | + } |
| 143 | + |
| 144 | + var data []dto.PostResponse |
| 145 | + for _, post := range dataWithPaginate.Posts { |
| 146 | + datum := dto.PostResponse{ |
| 147 | + ID: post.ID.String(), |
| 148 | + Text: post.Text, |
| 149 | + ParentID: post.ParentID, |
| 150 | + User: dto.UserResponse{ |
| 151 | + ID: post.UserID.String(), |
| 152 | + Name: post.User.Name, |
| 153 | + Bio: post.User.Bio, |
| 154 | + UserName: post.User.Username, |
| 155 | + ImageUrl: post.User.ImageUrl, |
| 156 | + }, |
| 157 | + } |
| 158 | + |
| 159 | + data = append(data, datum) |
| 160 | + } |
| 161 | + |
| 162 | + return dto.PostPaginationResponse{ |
| 163 | + Data: data, |
| 164 | + PaginationResponse: dto.PaginationResponse{ |
| 165 | + Page: dataWithPaginate.Page, |
| 166 | + PerPage: dataWithPaginate.PerPage, |
| 167 | + MaxPage: dataWithPaginate.MaxPage, |
| 168 | + Count: dataWithPaginate.Count, |
| 169 | + }, |
| 170 | + }, nil |
| 171 | +} |
0 commit comments