Skip to content

Commit

Permalink
[#2] 회원 - 닉네임 중복 체크 API 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jun108059 committed Oct 18, 2021
1 parent 64300ed commit b6b3999
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.teamnexters.lazy.api.exception.MemberNotFoundException;
import com.teamnexters.lazy.api.service.MemberService;
import com.teamnexters.lazy.common.domain.member.Member;
import com.teamnexters.lazy.common.error.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Content;
Expand Down Expand Up @@ -34,7 +35,9 @@ public class MemberController {
responses = {
@ApiResponse(
responseCode = "200", description = "[Ok] Get One Member Info",
content = @Content(schema = @Schema(implementation = MemberDto.AllMemberRes.class)))})
content = @Content(schema = @Schema(implementation = MemberDto.AllMemberRes.class))),
@ApiResponse(responseCode = "414", description = "[Error] 존재하지 않는 회원입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))})
@GetMapping("/v1/member")
public ResponseEntity<Member> getOneMember(
@Parameter(hidden = true) Authentication authentication) {
Expand All @@ -44,19 +47,20 @@ public ResponseEntity<Member> getOneMember(
if (member == null) {
throw new MemberNotFoundException("Auth");
} else {
log.info(">>> Member info : {}", member);
log.debug(">>> Member info : {}", member);
return ResponseEntity.ok().body(member);
}
}


@Operation(summary = "✅ 닉네임 수정 API",
description = "회원의 닉네임을 수정해요.",
security = @SecurityRequirement(name = "bearerAuth"),
responses = {
@ApiResponse(
responseCode = "200", description = "[Ok] Update Member NickName",
content = @Content(schema = @Schema(implementation = MemberDto.MemberIndexRes.class)))})
content = @Content(schema = @Schema(implementation = MemberDto.MemberIndexRes.class))),
@ApiResponse(responseCode = "411", description = "[Error] 이미 등록된 닉네임입니다.",
content = @Content(schema = @Schema(implementation = ErrorResponse.class)))})
@PutMapping("/v1/member")
public ResponseEntity<Long> updateMemberNickName(
@Parameter(hidden = true) Authentication authentication,
Expand All @@ -68,4 +72,23 @@ public ResponseEntity<Long> updateMemberNickName(
memberService.updateNickName(dto, memIdx);
return ResponseEntity.ok().body(memIdx);
}
}

@Operation(summary = "✅ 닉네임 중복체크 API",
description = "닉네임이 중복됐는지 검사해요.(중복 : true)",
security = @SecurityRequirement(name = "bearerAuth"),
responses = {
@ApiResponse(
responseCode = "200", description = "[Ok] Check Member NickName",
content = @Content(schema = @Schema(implementation = Boolean.class)))})
@GetMapping("/v1/member/{nickname}")
public ResponseEntity<Boolean> checkNickNameDuplication(
@Parameter(hidden = true) Authentication authentication,
@Parameter(description = "체크할 닉네임", required = true) @PathVariable(name="nickname") String nickName) {
Member member = (Member) authentication.getPrincipal();
Long memIdx = member.getMemIdx();
log.debug(">>> Check Member No [{}] NickName : {}", memIdx, nickName);

return ResponseEntity.ok().body(memberService.isExistedNickName(nickName));
}

}
13 changes: 13 additions & 0 deletions api/src/main/java/com/teamnexters/lazy/api/domain/MemberDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ public static class UpdateNickNameReq {
private String nickName;
}

/**
* 중복 체크할 닉네임 Dto
*/
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor
@Schema(description = "Request to check duplication NickName")
public static class checkNickNameReq {
@Schema(description = "회원 닉네임", defaultValue = "체크할 닉네임")
private String nickName;
}

/**
* 회원 데이터 Dto
*/
Expand Down Expand Up @@ -61,4 +73,5 @@ public static class MemberIndexRes {
@Schema(description = "회원 번호", defaultValue = "2")
private final Long memIdx;
}

}

0 comments on commit b6b3999

Please sign in to comment.