Skip to content

Commit

Permalink
add member get API
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueHorn07 committed Nov 13, 2023
1 parent fa7f200 commit 95f6cea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/member/member.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}
Expand Down
14 changes: 9 additions & 5 deletions src/member/member.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,26 @@ import { MemberDto } from './member.dto';
export class MemberService {
constructor(
@InjectRepository(MemberEntity)
private memoryRepository: Repository<MemberEntity>,
private memberRepository: Repository<MemberEntity>,
) {}

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);
}
}

0 comments on commit 95f6cea

Please sign in to comment.