Skip to content

Commit

Permalink
✨ feat: 블랙 리스트 생성 및 삭제 기능 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
yanggwangseong committed Nov 24, 2024
1 parent b594ecd commit fa7f671
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/controllers/members.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import {
Param,
ParseIntPipe,
Patch,
Post,
UploadedFile,
UseInterceptors,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import * as bcrypt from "bcrypt";

import { CurrentMemberDecorator } from "@APP/common/decorators/current-member.decorator";
import { CreateBlockListDto } from "@APP/dtos/create-block-list.dto";
import { UpdateMemberDto } from "@APP/dtos/update-member.dto";
import { MembersService } from "@APP/services/members.service";

Expand All @@ -27,6 +29,28 @@ export class MembersController {
return await this.membersService.findBlocks(currentMemberId);
}

@Post("blocks")
async postBlock(
@CurrentMemberDecorator("id") currentMemberId: number,
@Body() dto: CreateBlockListDto,
) {
return await this.membersService.createBlock(
currentMemberId,
dto.blockedId,
);
}

@Delete("blocks/:blockedId")
async deleteBlock(
@CurrentMemberDecorator("id") currentMemberId: number,
@Param("blockedId", new ParseIntPipe()) blockedId: number,
) {
return await this.membersService.deleteBlock(
currentMemberId,
blockedId,
);
}

@Get(":memberId")
async getMember(@Param("memberId", new ParseIntPipe()) memberId: number) {
return await this.membersService.findById(memberId);
Expand Down
7 changes: 7 additions & 0 deletions src/dtos/create-block-list.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PickType } from "@nestjs/swagger";

import { BlockListEntity } from "@APP/entities/block-list.entity";

export class CreateBlockListDto extends PickType(BlockListEntity, [
"blockedId",
]) {}
3 changes: 3 additions & 0 deletions src/entities/block-list.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { IsNotEmpty, IsNumber } from "class-validator";
import {
CreateDateColumn,
Entity,
Expand All @@ -14,6 +15,8 @@ export class BlockListEntity {
blockerId!: number;

@PrimaryColumn({ type: "int" })
@IsNumber()
@IsNotEmpty()
blockedId!: number;

@CreateDateColumn({ type: "timestamp", nullable: false })
Expand Down
14 changes: 14 additions & 0 deletions src/services/members.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,18 @@ export class MembersService {
},
});
}

async createBlock(blockerId: number, blockedId: number) {
return await this.blockListRepository.save({
blockerId,
blockedId,
});
}

async deleteBlock(blockerId: number, blockedId: number) {
return await this.blockListRepository.delete({
blockerId,
blockedId,
});
}
}

0 comments on commit fa7f671

Please sign in to comment.