Skip to content

Commit

Permalink
Merge pull request #170 from boostcampwm2023/BE-applySoftDelete-#169
Browse files Browse the repository at this point in the history
[BE/#169]  Soft Delete 적용
  • Loading branch information
koomin1227 authored Nov 24, 2023
2 parents c2bc7ee + 8a71ae0 commit a3b190f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
12 changes: 11 additions & 1 deletion BE/src/entities/blockPost.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { Entity, Column, ManyToOne, JoinColumn, PrimaryColumn } from 'typeorm';
import {
Entity,
Column,
ManyToOne,
JoinColumn,
PrimaryColumn,
DeleteDateColumn,
} from 'typeorm';
import { UserEntity } from './user.entity';
import { PostEntity } from './post.entity';

Expand All @@ -13,6 +20,9 @@ export class BlockPostEntity {
@Column({ nullable: false, default: true })
status: boolean;

@DeleteDateColumn()
delete_date: Date;

@ManyToOne(() => UserEntity, (blocker) => blocker.user_hash)
@JoinColumn({ name: 'blocker', referencedColumnName: 'user_hash' })
blockerUser: UserEntity;
Expand Down
13 changes: 12 additions & 1 deletion BE/src/entities/blockUser.entity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { Entity, Column, ManyToOne, JoinColumn, PrimaryColumn } from 'typeorm';
import {
Entity,
Column,
ManyToOne,
JoinColumn,
PrimaryColumn,
DeleteDateColumn,
} from 'typeorm';
import { UserEntity } from './user.entity';
import { Delete } from '@nestjs/common';

@Entity('block_user')
export class BlockUserEntity {
Expand All @@ -12,6 +20,9 @@ export class BlockUserEntity {
@Column({ nullable: false, default: true })
status: boolean;

@DeleteDateColumn()
delete_date: Date;

@ManyToOne(() => UserEntity, (blocker) => blocker.user_hash)
@JoinColumn({ name: 'blocker' })
blockerUser: UserEntity;
Expand Down
4 changes: 4 additions & 0 deletions BE/src/entities/post.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
ManyToOne,
JoinColumn,
OneToMany,
DeleteDateColumn,
} from 'typeorm';
import { UserEntity } from './user.entity';
import { PostImageEntity } from './postImage.entity';
Expand Down Expand Up @@ -57,6 +58,9 @@ export class PostEntity {
})
update_date: Date;

@DeleteDateColumn()
delete_date: Date;

@Column({ length: 2048, nullable: true, charset: 'utf8' })
thumbnail: string;

Expand Down
4 changes: 4 additions & 0 deletions BE/src/entities/postImage.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Column,
ManyToOne,
JoinColumn,
DeleteDateColumn,
} from 'typeorm';
import { PostEntity } from './post.entity';

Expand All @@ -18,6 +19,9 @@ export class PostImageEntity {
@Column({ nullable: false })
post_id: number;

@DeleteDateColumn()
delete_date: Date;

@ManyToOne(() => PostEntity, (post) => post.id)
@JoinColumn({ name: 'post_id' })
post: PostEntity;
Expand Down
4 changes: 4 additions & 0 deletions BE/src/entities/user.entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
Column,
CreateDateColumn,
DeleteDateColumn,
Entity,
OneToMany,
PrimaryGeneratedColumn,
Expand Down Expand Up @@ -56,4 +57,7 @@ export class UserEntity {

@Column({ length: 45, nullable: false, charset: 'utf8', unique: true })
user_hash: string;

@DeleteDateColumn()
delete_date: Date;
}
4 changes: 3 additions & 1 deletion BE/src/post/post.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ export class PostService {
where: { id: postId },
relations: ['post_images', 'user'],
});

console.log(post);
if (post === null) {
throw new HttpException('없는 게시물입니다.', 400);
}
Expand Down Expand Up @@ -232,7 +234,7 @@ export class PostService {
if (!isDataExists) {
return false;
} else {
await this.postRepository.update({ id: postId }, { status: false });
await this.postRepository.softDelete({ id: postId });
return true;
}
}
Expand Down

0 comments on commit a3b190f

Please sign in to comment.