Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

닉네임 중복 체크 항상 200OK 보내는 문제 해결 #296

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/security
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class WebConfig implements WebMvcConfigurer {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedMethods("*")
.allowedOrigins("http://rebon.s3-website.ap-northeast-2.amazonaws.com/", "http://localhost:8080");
.allowedOrigins("http://rebon.s3-website.ap-northeast-2.amazonaws.com/", "http://localhost:3000", "http://localhost:8080");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.handong.rebon.member.application.dto.response.MemberCreateResponseDto;
import com.handong.rebon.member.application.dto.response.MemberReadResponseDto;
import com.handong.rebon.member.presentation.dto.MemberAssembler;
import com.handong.rebon.member.presentation.dto.request.DuplicateRequest;
import com.handong.rebon.member.presentation.dto.request.MemberCreateRequest;
import com.handong.rebon.member.presentation.dto.request.MemberUpdateRequest;
import com.handong.rebon.member.presentation.dto.response.MemberCreateResponse;
Expand All @@ -35,13 +36,6 @@ public ResponseEntity<MemberCreateResponse> create(@RequestBody MemberCreateRequ
.body(MemberCreateResponse.from(response));
}

@PostMapping("/members/nickname/check-duplicate")
public ResponseEntity<Void> nicknameDuplicateCheck(@RequestBody String nickname) {
memberService.checkNicknameDuplicate(nickname);
return ResponseEntity.ok()
.build();
}

@RequiredLogin
@PatchMapping("/members")
public ResponseEntity<Void> update(
Expand All @@ -55,6 +49,13 @@ public ResponseEntity<Void> update(
.build();
}

@PostMapping("/members/nickname/check-duplicate")
public ResponseEntity<Void> nicknameDuplicateCheck(@RequestBody DuplicateRequest duplicateRequest) {
memberService.checkNicknameDuplicate(duplicateRequest.getNickname());
return ResponseEntity.ok()
.build();
}

@RequiredLogin
@GetMapping("/members")
public ResponseEntity<MemberReadResponse> getMemberInfo(@Login LoginMember loginMember) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.handong.rebon.member.presentation.dto.request;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@AllArgsConstructor
@Getter
public class DuplicateRequest {
private String nickname;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.handong.rebon.acceptance.member;

import com.handong.rebon.acceptance.AcceptanceTest;
import com.handong.rebon.member.presentation.dto.request.DuplicateRequest;
import com.handong.rebon.member.presentation.dto.request.MemberCreateRequest;

import org.springframework.http.HttpStatus;
Expand Down Expand Up @@ -42,8 +43,9 @@ void saveMember() {
void checkDidNotDuplicateNickname() {
//given
String nickname = "ReBoN";
DuplicateRequest duplicateRequest = new DuplicateRequest(nickname);
//when
ExtractableResponse<Response> response = checkDuplicateNickname(nickname);
ExtractableResponse<Response> response = checkDuplicateNickname(duplicateRequest);

//then
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
Expand All @@ -54,16 +56,17 @@ void checkDidNotDuplicateNickname() {
void checkDuplicatedNickname() {
//given
String nickname = "test";
DuplicateRequest duplicateRequest = new DuplicateRequest(nickname);
saveMember(new MemberCreateRequest("[email protected]", nickname, "google", true));

//when
ExtractableResponse<Response> response = checkDuplicateNickname(nickname);
ExtractableResponse<Response> response = checkDuplicateNickname(duplicateRequest);

//then
assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());
}

private ExtractableResponse<Response> checkDuplicateNickname(String nickname) {
private ExtractableResponse<Response> checkDuplicateNickname(DuplicateRequest nickname) {
return RestAssured.given(getRequestSpecification())
.log().all()
.contentType(APPLICATION_JSON_VALUE)
Expand Down