Skip to content

Commit

Permalink
Merge pull request #586 from boostcampwm2023/BE-ChangePostList-#585
Browse files Browse the repository at this point in the history
[BE/#585] post list api 수정
  • Loading branch information
namewhat99 authored Dec 23, 2023
2 parents 8350631 + fabdeed commit 77fb925
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion BE/src/post/dto/postList.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export class PostListDto {
@IsNumber()
@IsOptional()
@Type(() => Number)
page: number;
cursorId: number;

@IsNumber()
@IsOptional()
Expand Down
6 changes: 3 additions & 3 deletions BE/src/post/post.repository.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('', () => {
describe('createPost()', () => {
it('should success (nothing)', async function () {
const res = repository.createOption({
page: undefined,
cursorId: undefined,
requestFilter: undefined,
writer: undefined,
searchKeyword: undefined,
Expand All @@ -36,7 +36,7 @@ describe('', () => {
});
it('should success (page)', async function () {
const res = repository.createOption({
page: 1,
cursorId: 1,
requestFilter: undefined,
writer: undefined,
searchKeyword: undefined,
Expand All @@ -45,7 +45,7 @@ describe('', () => {
});
it('should success (more than two options)', async function () {
const res = repository.createOption({
page: 1,
cursorId: 1,
requestFilter: undefined,
writer: 'user',
searchKeyword: undefined,
Expand Down
5 changes: 2 additions & 3 deletions BE/src/post/post.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export class PostRepository extends Repository<PostEntity> {
'bu',
'bu.blocker = :blocker AND bu.blocked_user = post.user_hash',
)
.leftJoinAndSelect('post.post_images', 'pi', 'pi.post_id = post.id')
.where('bp.blocked_post IS NULL')
.andWhere('bu.blocked_user IS NULL')
.andWhere(this.createOption(options))
Expand Down Expand Up @@ -65,9 +64,9 @@ export class PostRepository extends Repository<PostEntity> {

createOption(options: PostListDto) {
let option =
options.page === undefined
options.cursorId === undefined
? 'post.id > -1 AND '
: `post.id < ${options.page} AND `;
: `post.id < ${options.cursorId} AND `;
if (options.requestFilter !== undefined) {
option += `post.is_request = ${options.requestFilter} AND `;
}
Expand Down
5 changes: 1 addition & 4 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@ export class PostService {
return {
title: filteredPost.title,
price: filteredPost.price,
description: filteredPost.description,
post_id: filteredPost.id,
user_id: filteredPost.user_hash,
is_request: filteredPost.is_request,
images: filteredPost.post_images.map(
(post_image) => post_image.image_url,
),
post_image: filteredPost.thumbnail,
start_date: filteredPost.start_date,
end_date: filteredPost.end_date,
};
Expand Down

0 comments on commit 77fb925

Please sign in to comment.