Skip to content

Commit

Permalink
Merge pull request #314 from boostcampwm2023/BE-PostChange-#313
Browse files Browse the repository at this point in the history
[BE/#313] post 테이블 변경
  • Loading branch information
namewhat99 authored Dec 5, 2023
2 parents 497715a + 7f9b437 commit 7e4338d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
6 changes: 3 additions & 3 deletions BE/src/entities/post.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export class PostEntity {
description: string;

@Column({ nullable: false })
user_id: number;
user_hash: string;

@ManyToOne(() => UserEntity, (user) => user.id)
@JoinColumn({ name: 'user_id' })
@ManyToOne(() => UserEntity, (user) => user.user_hash)
@JoinColumn({ name: 'user_hash', referencedColumnName: 'user_hash' })
user: UserEntity;

@Column({ type: 'datetime', nullable: false })
Expand Down
17 changes: 8 additions & 9 deletions BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ export class PostService {
}

async getFilteredList(userId: string) {
const blockedUsersId: number[] = (
const blockedUsersId: string[] = (
await this.blockUserRepository.find({
where: { blocker: userId },
relations: ['blockedUser'],
})
).map((blockedUser) => blockedUser.blockedUser.id);
).map((blockedUser) => blockedUser.blockedUser.user_hash);

const blockedPostsId: number[] = (
await this.blockPostRepository.find({
Expand All @@ -58,7 +58,7 @@ export class PostService {
return posts.filter((post) => {
return !(
blockedPostsId.includes(post.id) ||
blockedUsersId.includes(post.user_id)
blockedUsersId.includes(post.user_hash)
);
});
}
Expand All @@ -67,7 +67,8 @@ export class PostService {
const { blockedUsersId, blockedPostsId } =
await this.getFilteredList(userId);
return (
blockedPostsId.includes(post.id) || blockedUsersId.includes(post.user_id)
blockedPostsId.includes(post.id) ||
blockedUsersId.includes(post.user_hash)
);
}

Expand Down Expand Up @@ -119,7 +120,7 @@ export class PostService {
title: post.title,
description: post.description,
price: post.price,
user_id: post.user.user_hash,
user_id: post.user_hash,
images: post.post_images.map((post_image) => post_image.image_url),
is_request: post.is_request,
start_date: post.start_date,
Expand Down Expand Up @@ -201,16 +202,14 @@ export class PostService {

async createPost(imageLocations, createPostDto, userHash) {
const post = new PostEntity();
const user = await this.userRepository.findOne({
where: { user_hash: userHash },
});

post.title = createPostDto.title;
post.description = createPostDto.description;
post.price = createPostDto.price;
post.is_request = createPostDto.is_request;
post.start_date = createPostDto.start_date;
post.end_date = createPostDto.end_date;
post.user_id = user.id;
post.user_hash = userHash;
post.thumbnail = imageLocations.length > 0 ? imageLocations[0] : null;
// 이미지 추가
const res = await this.postRepository.save(post);
Expand Down
2 changes: 1 addition & 1 deletion BE/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class UsersService {

async deleteCascadingUser(userId, userHash) {
const postsByUser = await this.postRepository.find({
where: { user_id: userId },
where: { user_hash: userHash },
});
for (const postByUser of postsByUser) {
await this.deleteCascadingPost(postByUser.id);
Expand Down

0 comments on commit 7e4338d

Please sign in to comment.