diff --git a/src/member/member.controller.ts b/src/member/member.controller.ts index 92cc12f..f7edf8a 100644 --- a/src/member/member.controller.ts +++ b/src/member/member.controller.ts @@ -6,7 +6,9 @@ import { Param, Post, Put, + UseGuards, } from '@nestjs/common'; +import { AuthGuard } from '@nestjs/passport'; import { ApiTags } from '@nestjs/swagger'; import { MemberService } from './member.service'; import { MemberDto } from './member.dto'; @@ -21,17 +23,25 @@ export class MemberController { return this.memberService.getMemberList(); } + @Get(':id') + getMemberById(@Param('id') id: number) { + return this.memberService.getMember(id); + } + @Post() + @UseGuards(AuthGuard('jwt')) addMember(@Body() dto: MemberDto) { return this.memberService.createMember(dto); } @Put() + @UseGuards(AuthGuard('jwt')) updateMember(@Param('id') id: number, @Body() dto: MemberDto) { return this.memberService.updateMember(id, dto); } @Delete() + @UseGuards(AuthGuard('jwt')) deleteMember(@Param('id') id: number) { return this.memberService.deleteMember(id); } diff --git a/src/member/member.service.ts b/src/member/member.service.ts index 378032c..b81c54a 100644 --- a/src/member/member.service.ts +++ b/src/member/member.service.ts @@ -8,22 +8,26 @@ import { MemberDto } from './member.dto'; export class MemberService { constructor( @InjectRepository(MemberEntity) - private memoryRepository: Repository, + private memberRepository: Repository, ) {} getMemberList() { - return this.memoryRepository.find(); + return this.memberRepository.find(); + } + + getMember(id: number) { + return this.memberRepository.findOneBy({ id: id }); } createMember(dto: MemberDto) { - return this.memoryRepository.save(dto); + return this.memberRepository.save(dto); } updateMember(id: number, dto: MemberDto) { - return this.memoryRepository.update(id, dto); + return this.memberRepository.update(id, dto); } deleteMember(id: number) { - return this.memoryRepository.delete(id); + return this.memberRepository.delete(id); } }