diff --git a/src/main/java/com/project/mapdagu/domain/member/controller/MemberController.java b/src/main/java/com/project/mapdagu/domain/member/controller/MemberController.java index b6f5edc..11b4c46 100644 --- a/src/main/java/com/project/mapdagu/domain/member/controller/MemberController.java +++ b/src/main/java/com/project/mapdagu/domain/member/controller/MemberController.java @@ -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; @@ -64,4 +66,16 @@ public ResponseEntity 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 checkUserName(@RequestBody MemberUserNameRequestDto requestDto) { + MemberUserNameResponseDto responseDto = memberService.checkUserName(requestDto); + return ResponseDto.ok(responseDto); + } } diff --git a/src/main/java/com/project/mapdagu/domain/member/dto/request/MemberUserNameRequestDto.java b/src/main/java/com/project/mapdagu/domain/member/dto/request/MemberUserNameRequestDto.java new file mode 100644 index 0000000..4df1b57 --- /dev/null +++ b/src/main/java/com/project/mapdagu/domain/member/dto/request/MemberUserNameRequestDto.java @@ -0,0 +1,4 @@ +package com.project.mapdagu.domain.member.dto.request; + +public record MemberUserNameRequestDto(String userName) { +} diff --git a/src/main/java/com/project/mapdagu/domain/member/dto/response/MemberUserNameResponseDto.java b/src/main/java/com/project/mapdagu/domain/member/dto/response/MemberUserNameResponseDto.java new file mode 100644 index 0000000..fb6c766 --- /dev/null +++ b/src/main/java/com/project/mapdagu/domain/member/dto/response/MemberUserNameResponseDto.java @@ -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); + } +} diff --git a/src/main/java/com/project/mapdagu/domain/member/service/MemberService.java b/src/main/java/com/project/mapdagu/domain/member/service/MemberService.java index 82e98c3..a37d2fb 100644 --- a/src/main/java/com/project/mapdagu/domain/member/service/MemberService.java +++ b/src/main/java/com/project/mapdagu/domain/member/service/MemberService.java @@ -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; @@ -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; + } }