Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE/#134] GET /posts/block API 구현 #139

Merged
merged 7 commits into from
Nov 23, 2023
Merged
4 changes: 2 additions & 2 deletions BE/src/entities/blockPost.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class BlockPostEntity {
status: boolean;

@ManyToOne(() => UserEntity, (blocker) => blocker.user_hash)
@JoinColumn({ name: 'blocker' })
@JoinColumn({ name: 'blocker', referencedColumnName: 'user_hash' })
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refereceColumn 적용 좋습니다~

blockerUser: UserEntity;

@ManyToOne(() => UserEntity, (blocked_post) => blocked_post.id)
@ManyToOne(() => PostEntity, (blocked_post) => blocked_post.id)
@JoinColumn({ name: 'blocked_post' })
blockedPost: PostEntity;
}
2 changes: 1 addition & 1 deletion BE/src/entities/post.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ export class PostEntity {
post_images: PostImageEntity[];

@OneToMany(() => BlockPostEntity, (post_image) => post_image.blocked_post)
blocked_posts: PostImageEntity[];
blocked_posts: BlockPostEntity[];
}
2 changes: 2 additions & 0 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export class PostService {
price: res.price,
user_id: res.user_id,
images: res.post_images,
post_image: res.thumbnail,
is_request: res.is_request,
start_date: res.start_date,
end_date: res.end_date,
Expand Down Expand Up @@ -140,6 +141,7 @@ export class PostService {
post.end_date = createPostDto.end_date;
post.status = true;
post.user_id = user.id;
post.thumbnail = imageLocations.length > 0 ? imageLocations[0] : null;
// 이미지 추가
const res = await this.postRepository.save(post);
if (res.is_request === false) {
Expand Down
10 changes: 9 additions & 1 deletion BE/src/posts-block/posts-block.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Param, Post } from '@nestjs/common';
import { Controller, Get, Param, Post } from '@nestjs/common';
import { PostsBlockService } from './posts-block.service';

@Controller('posts/block')
Expand All @@ -9,4 +9,12 @@ export class PostsBlockController {
const blockerId = 'qwe';
await this.postsBlockService.createPostsBlock(blockerId, postId);
}

@Get()
async postsBlockList() {
const blockerId: string = 'qwe';
const blockedPosts =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추후에 로그인 구현 이후에 이 부분 같이 바꿉시다~

await this.postsBlockService.findBlockedPosts(blockerId);
return blockedPosts;
}
}
20 changes: 19 additions & 1 deletion BE/src/posts-block/posts-block.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,30 @@ export class PostsBlockService {
blocked_post: postId,
},
});
if (isExist.status === true) {
if (isExist !== null && isExist.status === true) {
throw new HttpException('이미 차단 되었습니다.', 400);
}
blockPostEntity.blocked_post = postId;
blockPostEntity.blocker = blockerId;
blockPostEntity.status = true;
await this.blockPostRepository.save(blockPostEntity);
}

async findBlockedPosts(blockerId: string) {
const blockLists = await this.blockPostRepository.find({
where: {
blocker: blockerId,
status: true,
},
relations: ['blockedPost'],
});
return blockLists.map((blockList) => {
const blockedPost = blockList.blockedPost;
return {
title: blockedPost.title,
post_image: blockedPost.thumbnail,
post_id: blockedPost.id,
};
});
}
}
Loading