-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from team9502/dev
feat: ์ด๋ฉ์ผ ์ธ์ฆ&๊ฒ์ฆ + ํ์๊ฐ์ /ํ๋กํ ์์ ์ ์ด๋ฉ์ผ ์ธ์ฆ&๊ฒ์ฆ ์ถ๊ฐ
- Loading branch information
Showing
23 changed files
with
528 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...ain/java/team9502/sinchulgwinong/domain/email/controller/EmailVerificationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package team9502.sinchulgwinong.domain.email.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.ExampleObject; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
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; | ||
import team9502.sinchulgwinong.domain.email.dto.request.EmailVerificationCodeRequestDTO; | ||
import team9502.sinchulgwinong.domain.email.dto.request.EmailVerificationRequestDTO; | ||
import team9502.sinchulgwinong.domain.email.service.EmailVerificationService; | ||
import team9502.sinchulgwinong.global.response.GlobalApiResponse; | ||
|
||
import static team9502.sinchulgwinong.global.response.SuccessCode.SUCCESS_EMAIL_VERIFICATION; | ||
import static team9502.sinchulgwinong.global.response.SuccessCode.SUCCESS_EMAIL_VERIFICATION_SENT; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/email") | ||
@Tag(name = "Email Verification", description = "์ด๋ฉ์ผ ์ธ์ฆ ๊ด๋ จ API [๊น์์ฑ]") | ||
public class EmailVerificationController { | ||
|
||
private final EmailVerificationService emailVerificationService; | ||
|
||
@PostMapping("/sendCode") | ||
@Operation(summary = "์ด๋ฉ์ผ ์ธ์ฆ ์ฝ๋ ๋ฐ์ก", description = "์ฌ์ฉ์ ์ด๋ฉ์ผ๋ก ์ธ์ฆ ์ฝ๋๋ฅผ ๋ฐ์กํฉ๋๋ค.") | ||
@ApiResponse(responseCode = "200", description = "์ธ์ฆ ์ฝ๋ ๋ฐ์ก ์ฑ๊ณต", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"200\", \"message\": \"์ธ์ฆ ์ฝ๋ ๋ฐ์ก ์ฑ๊ณต\", \"data\": null }"))) | ||
@ApiResponse(responseCode = "400", description = "์๋ชป๋ ์ ๋ ฅ", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"400\", \"message\": \"์๋ชป๋ ์ ๋ ฅ์ ๋๋ค.\", \"data\": null }"))) | ||
@ApiResponse(responseCode = "401", description = "์ด๋ฉ์ผ ์ธ์ฆ ์คํจ", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"401\", \"message\": \"์ด๋ฉ์ผ ์ธ์ฆ์ ์คํจํ์ต๋๋ค.\", \"data\": null }"))) | ||
@ApiResponse(responseCode = "500", description = "์๋ฒ ์๋ฌ", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"500\", \"message\": \"์๋ฒ ์๋ฌ\", \"data\": null }"))) | ||
public ResponseEntity<GlobalApiResponse<Void>> sendVerificationCode( | ||
@RequestBody EmailVerificationRequestDTO requestDTO) { | ||
|
||
emailVerificationService.createVerification(requestDTO.getEmail(), requestDTO.getUserType()); | ||
|
||
return ResponseEntity.status(SUCCESS_EMAIL_VERIFICATION_SENT.getHttpStatus()) | ||
.body( | ||
GlobalApiResponse.of( | ||
SUCCESS_EMAIL_VERIFICATION_SENT.getMessage(), | ||
null | ||
) | ||
); | ||
} | ||
|
||
@PostMapping("/verifyCode") | ||
@Operation(summary = "์ด๋ฉ์ผ ์ธ์ฆ ์ฝ๋ ๊ฒ์ฆ", description = "์ ๊ณต๋ ์ด๋ฉ์ผ๊ณผ ์ธ์ฆ ์ฝ๋์ ์ ํจ์ฑ์ ๊ฒ์ฆํฉ๋๋ค.") | ||
@ApiResponse(responseCode = "200", description = "์ด๋ฉ์ผ ์ธ์ฆ ์ฑ๊ณต", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"200\", \"message\": \"์ด๋ฉ์ผ ์ธ์ฆ ์ฑ๊ณต\", \"data\": null }"))) | ||
@ApiResponse(responseCode = "400", description = "์ ํจํ์ง ์๊ฑฐ๋ ๋ง๋ฃ๋ ์ฝ๋", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"400\", \"message\": \"์ ํจํ์ง ์๊ฑฐ๋ ๋ง๋ฃ๋ ์ธ์ฆ ์ฝ๋\", \"data\": null }"))) | ||
@ApiResponse(responseCode = "401", description = "์๋ชป๋ ์ ๋ ฅ", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"400\", \"message\": \"์๋ชป๋ ์ ๋ ฅ์ ๋๋ค.\", \"data\": null }"))) | ||
@ApiResponse(responseCode = "500", description = "์๋ฒ ์๋ฌ", | ||
content = @Content(mediaType = "application/json", | ||
examples = @ExampleObject(value = "{ \"code\": \"500\", \"message\": \"์๋ฒ ์๋ฌ\", \"data\": null }"))) | ||
public ResponseEntity<GlobalApiResponse<Void>> verifyCode( | ||
@RequestBody EmailVerificationCodeRequestDTO requestDTO) { | ||
|
||
emailVerificationService.verifyCode(requestDTO.getEmail(), requestDTO.getCode()); | ||
|
||
|
||
return ResponseEntity.status(SUCCESS_EMAIL_VERIFICATION.getHttpStatus()) | ||
.body( | ||
GlobalApiResponse.of( | ||
SUCCESS_EMAIL_VERIFICATION.getMessage(), | ||
null | ||
) | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...ava/team9502/sinchulgwinong/domain/email/dto/request/EmailVerificationCodeRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package team9502.sinchulgwinong.domain.email.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Data | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class EmailVerificationCodeRequestDTO { | ||
|
||
@Schema(description = "์ด๋ฉ์ผ ์ฃผ์", example = "[email protected]") | ||
private String email; | ||
|
||
@Schema(description = "์ธ์ฆ ์ฝ๋", example = "123456") | ||
private String code; | ||
} |
21 changes: 21 additions & 0 deletions
21
...in/java/team9502/sinchulgwinong/domain/email/dto/request/EmailVerificationRequestDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package team9502.sinchulgwinong.domain.email.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import team9502.sinchulgwinong.domain.email.enums.UserType; | ||
|
||
@Data | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class EmailVerificationRequestDTO { | ||
|
||
@Schema(description = "์ด๋ฉ์ผ ์ฃผ์", example = "[email protected]") | ||
private String email; | ||
|
||
@Schema(description = "์ฌ์ฉ์ ์ ํ", example = "USER") | ||
private UserType userType; | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/team9502/sinchulgwinong/domain/email/entity/EmailVerifications.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package team9502.sinchulgwinong.domain.email.entity; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import team9502.sinchulgwinong.domain.email.enums.UserType; | ||
import team9502.sinchulgwinong.domain.email.enums.VerificationStatus; | ||
|
||
import java.util.Date; | ||
|
||
@Entity | ||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Table(name = "EmailVerifications", indexes = { | ||
@Index(name = "idx_expires_at_status", columnList = "expiresAt, status") | ||
}) | ||
public class EmailVerifications { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long verificationId; | ||
|
||
@Column(nullable = false, length = 250) | ||
private String email; | ||
|
||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private UserType userType; | ||
|
||
@Column | ||
private Long userReferenceId; | ||
|
||
@Column(nullable = false, length = 6) | ||
private String verificationCode; | ||
|
||
@Column(nullable = false) | ||
@Temporal(TemporalType.TIMESTAMP) | ||
private Date createdAt; | ||
|
||
@Column(nullable = false) | ||
@Temporal(TemporalType.TIMESTAMP) | ||
private Date expiresAt; | ||
|
||
@Setter | ||
@Column(nullable = false) | ||
@Enumerated(EnumType.STRING) | ||
private VerificationStatus status; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/team9502/sinchulgwinong/domain/email/enums/UserType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package team9502.sinchulgwinong.domain.email.enums; | ||
|
||
public enum UserType { | ||
|
||
USER, CPUSER | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/team9502/sinchulgwinong/domain/email/enums/VerificationStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package team9502.sinchulgwinong.domain.email.enums; | ||
|
||
public enum VerificationStatus { | ||
|
||
PENDING, VERIFIED, EXPIRED | ||
} |
20 changes: 20 additions & 0 deletions
20
...ain/java/team9502/sinchulgwinong/domain/email/repository/EmailVerificationRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package team9502.sinchulgwinong.domain.email.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import team9502.sinchulgwinong.domain.email.entity.EmailVerifications; | ||
import team9502.sinchulgwinong.domain.email.enums.VerificationStatus; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface EmailVerificationRepository extends JpaRepository<EmailVerifications, Long> { | ||
|
||
Optional<EmailVerifications> findByEmailAndVerificationCodeAndExpiresAtAfterAndStatus(String email, String verificationCode, Date now, VerificationStatus status); | ||
|
||
List<EmailVerifications> findByExpiresAtBeforeAndStatus(Date expiresAt, VerificationStatus status); | ||
|
||
void deleteByExpiresAtBeforeAndStatus(Date expiresAt, VerificationStatus status); | ||
|
||
boolean existsByEmailAndStatus(String email, VerificationStatus status); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/team9502/sinchulgwinong/domain/email/service/EmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package team9502.sinchulgwinong.domain.email.service; | ||
|
||
public interface EmailService { | ||
|
||
void sendSimpleMessage(String to, String subject, String text); | ||
} |
Oops, something went wrong.