Skip to content

Commit

Permalink
feat: account 중복 시 400 반환 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim0914 committed Sep 12, 2023
1 parent 08374ac commit b5e6645
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ protected void doPost(HttpRequest httpRequest, HttpResponse httpResponse) throws
String email = httpRequest.getParam(EMAIL);
String password = httpRequest.getParam(PASSWORD);

if (isDuplicateAccount(httpResponse, account)) {
return;
}

User user = new User(account, password, email);
InMemoryUserRepository.save(user);
LOG.info("회원가입 성공한 회원 : {}", user);
Expand All @@ -37,6 +41,17 @@ protected void doPost(HttpRequest httpRequest, HttpResponse httpResponse) throws
httpResponse.setLocation(INDEX_PAGE);
}

private boolean isDuplicateAccount(HttpResponse httpResponse, String account) throws IOException {
if (InMemoryUserRepository.findByAccount(account).isPresent()) {
String content = FileReader.read(REGISTER_PAGE);
httpResponse.setHttpStatus(HttpStatus.BAD_REQUEST);
httpResponse.setContentType(ContentType.TEXT_HTML);
httpResponse.setBody(content);
return true;
}
return false;
}

@Override
protected void doGet(HttpRequest httpRequest, HttpResponse httpResponse) throws IOException {
String content = FileReader.read(REGISTER_PAGE);
Expand Down
1 change: 1 addition & 0 deletions tomcat/src/main/java/org/apache/response/HttpStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public enum HttpStatus {

OK("200"),
FOUND("302"),
BAD_REQUEST("400"),
UNAUTHORIZED("401"),
NOT_FOUND("404"),
METHOD_NOT_ALLOWED("405");
Expand Down

0 comments on commit b5e6645

Please sign in to comment.