Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/h-jjang/bauction into fix/
Browse files Browse the repository at this point in the history
…#63-post-entity
  • Loading branch information
Gnu-Kenny committed May 27, 2022
2 parents 4c18d40 + 1d97af0 commit a85623d
Show file tree
Hide file tree
Showing 26 changed files with 546 additions and 203 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.hjjang.backend.domain.mail.controller;

import static com.hjjang.backend.global.response.code.SuccessCode.*;
import static org.springframework.http.HttpStatus.*;

import com.hjjang.backend.domain.mail.dto.MailRequest;
import com.hjjang.backend.domain.mail.dto.MailResponse;
import com.hjjang.backend.domain.mail.service.MailService;
import com.hjjang.backend.global.response.response.SuccessResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/mail")
public class MailController {

private final MailService mailService;

@PostMapping("/send")
public ResponseEntity<SuccessResponse> send(@RequestBody MailRequest mailRequest) {
String mail = mailRequest.getMail();
MailResponse mailResponse = mailService.sendMail(mail);
SuccessResponse response = SuccessResponse.of(MAIL_SEND_SUCCESS, mailResponse);
return new ResponseEntity<>(response, CREATED);
}

@PostMapping("/check")
public ResponseEntity<SuccessResponse> auth(@RequestBody MailRequest mailRequest) {
MailResponse mailResponse = mailService.checkCode(mailRequest);
return ResponseEntity.ok(SuccessResponse.of(MAIL_CHECK_SUCCESS));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.hjjang.backend.domain.email.domain;
package com.hjjang.backend.domain.mail.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum EmailMessage {
public enum MailMessage {
TITLE("[Bauction] 인증번호를 발송했습니다."),
MESSAGE("본인확인 인증 메일\n"
+ "이메일 인증을 진행해주세요.\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.hjjang.backend.domain.mail.domain;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum MailRegex {
UNIVERSITY("UNIVERSITY_MAIL_REGEX", "^[a-zA-Z0-9]+@[a-zA-Z0-9]+\\.+a+c+\\.+k+r+$"),
GS_UNIVERSITY("GS_UNIVERSITY_MAIL_REGEX", "^[a-zA-Z0-9]+@+g+s+\\.+[a-zA-Z0-9]+\\.+a+c+\\.+k+r+$"),
MAIL_PARSE("MAIL_PARSE_REGEX", "[@.]");

private final String name;
private final String regex;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hjjang.backend.domain.email.dto;
package com.hjjang.backend.domain.mail.dto;

import java.util.Random;
import lombok.AllArgsConstructor;
Expand All @@ -10,7 +10,7 @@
@AllArgsConstructor
@Getter
@Setter
public class Email {
public class Mail {

private String code;
private String address;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hjjang.backend.domain.email.dto;
package com.hjjang.backend.domain.mail.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -7,7 +7,7 @@
@AllArgsConstructor
public class MailRequest {

private String email;
private String mail;

private String code;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.hjjang.backend.domain.email.dto;
package com.hjjang.backend.domain.mail.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand All @@ -7,5 +7,5 @@
@AllArgsConstructor
public class MailResponse {

private Email email;
private Mail mail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hjjang.backend.domain.mail.exception;

import com.hjjang.backend.global.execption.BusinessException;
import com.hjjang.backend.global.response.code.ErrorCode;

public class InvalidMailException extends BusinessException {

public InvalidMailException() {
super(ErrorCode.INVALID_MAIL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.hjjang.backend.domain.mail.exception;

import com.hjjang.backend.global.execption.BusinessException;
import com.hjjang.backend.global.response.code.ErrorCode;

public class UnauthorizedException extends BusinessException {

public UnauthorizedException() {
super(ErrorCode.INVALID_CODE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.hjjang.backend.domain.mail.exception.handler;

import static com.hjjang.backend.global.response.code.ErrorCode.*;
import static org.springframework.http.HttpStatus.*;

import com.hjjang.backend.domain.mail.exception.InvalidMailException;
import com.hjjang.backend.domain.mail.exception.UnauthorizedException;
import com.hjjang.backend.global.response.response.ErrorResponse;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class MailExceptionHandler {

@ExceptionHandler(value = InvalidMailException.class)
public ResponseEntity<ErrorResponse> mailExceptionHandle() {
ErrorResponse response = ErrorResponse.of(INVALID_MAIL);
return new ResponseEntity<>(response, BAD_REQUEST);
}

@ExceptionHandler(value = UnauthorizedException.class)
public ResponseEntity<ErrorResponse> unauthorizedExceptionHandle() {
ErrorResponse response = ErrorResponse.of(INVALID_CODE);
return new ResponseEntity<>(response, UNAUTHORIZED);
}
}
Loading

0 comments on commit a85623d

Please sign in to comment.