Skip to content

Commit

Permalink
feat: 회원 이름 중복 검사 기능 구현 (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyeong-hyeok committed Sep 18, 2023
1 parent d249ff6 commit 2de76c1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import com.project.mapdagu.common.dto.ResponseDto;
import com.project.mapdagu.domain.member.dto.request.MemberUpdateInfoRequestDto;
import com.project.mapdagu.domain.member.dto.request.MemberUserNameRequestDto;
import com.project.mapdagu.domain.member.dto.response.MemberReadInfoResponseDto;
import com.project.mapdagu.domain.member.dto.response.MemberReadMainResponseDto;
import com.project.mapdagu.domain.member.dto.response.MemberUserNameResponseDto;
import com.project.mapdagu.domain.member.service.MemberService;
import com.project.mapdagu.error.dto.ErrorResponse;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -64,4 +66,16 @@ public ResponseEntity<MemberReadMainResponseDto> readMainInfo(@AuthenticationPri
MemberReadMainResponseDto responseDto = memberService.readMainInfo(loginUser.getUsername());
return ResponseDto.ok(responseDto);
}

@Operation(summary = "회원 정보 수정", description = "회원 정보를 수정합니다.",
responses = {
@ApiResponse(responseCode = "204", description = "회원 정보 수정 성공")
, @ApiResponse(responseCode = "401", description = "인증에 실패했습니다.")
, @ApiResponse(responseCode = "404", description = "1. 해당 회원을 찾을 수 없습니다. /t/n 2. 현재 사용자 이름과 동일합니다. /t/n 3. 이미 존재하는 사용자 이름입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class)))
})
@PostMapping("/userName/isDuplicated")
public ResponseEntity<MemberUserNameResponseDto> checkUserName(@RequestBody MemberUserNameRequestDto requestDto) {
MemberUserNameResponseDto responseDto = memberService.checkUserName(requestDto);
return ResponseDto.ok(responseDto);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.project.mapdagu.domain.member.dto.request;

public record MemberUserNameRequestDto(String userName) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.project.mapdagu.domain.member.dto.response;

public record MemberUserNameResponseDto(Boolean isDuplicated) {

public static MemberUserNameResponseDto of(Boolean isDuplicated){
return new MemberUserNameResponseDto(isDuplicated);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.project.mapdagu.domain.member.service;

import com.project.mapdagu.domain.member.dto.request.MemberUpdateInfoRequestDto;
import com.project.mapdagu.domain.member.dto.request.MemberUserNameRequestDto;
import com.project.mapdagu.domain.member.dto.response.MemberReadInfoResponseDto;
import com.project.mapdagu.domain.member.dto.response.MemberReadMainResponseDto;
import com.project.mapdagu.domain.member.dto.response.MemberUserNameResponseDto;
import com.project.mapdagu.domain.member.entity.Member;
import com.project.mapdagu.domain.member.repository.MemberRepository;
import com.project.mapdagu.error.ErrorCode;
Expand Down Expand Up @@ -36,4 +38,10 @@ public MemberReadMainResponseDto readMainInfo(String email) {
MemberReadMainResponseDto response = MemberReadMainResponseDto.of(member.getUserName(), member.getLevel(), member.getImageNum());
return response;
}

public MemberUserNameResponseDto checkUserName(MemberUserNameRequestDto requestDto) {
Boolean isDuplicated = memberRepository.existsByUserName(requestDto.userName());
MemberUserNameResponseDto response = MemberUserNameResponseDto.of(isDuplicated);
return response;
}
}

0 comments on commit 2de76c1

Please sign in to comment.