11package koreatech .in .service ;
22
3+ import static koreatech .in .domain .Mail .MailForm .OWNER_FIND_PASSWORD_MAIL_FORM ;
4+ import static koreatech .in .domain .Mail .MailForm .OWNER_REGISTRATION_MAIL_FORM ;
5+ import static koreatech .in .domain .RedisOwnerKeyPrefix .ownerAuthPrefix ;
6+ import static koreatech .in .domain .RedisOwnerKeyPrefix .ownerChangePasswordAuthPrefix ;
7+
38import java .sql .SQLException ;
9+
10+ import org .apache .velocity .app .VelocityEngine ;
11+ import org .springframework .beans .factory .annotation .Autowired ;
12+ import org .springframework .dao .DuplicateKeyException ;
13+ import org .springframework .security .crypto .password .PasswordEncoder ;
14+ import org .springframework .stereotype .Service ;
15+ import org .springframework .transaction .annotation .Transactional ;
16+
417import koreatech .in .domain .User .EmailAddress ;
518import koreatech .in .domain .User .User ;
619import koreatech .in .domain .User .owner .CertificationCode ;
2639import koreatech .in .util .SesMailSender ;
2740import koreatech .in .util .SlackNotiSender ;
2841import koreatech .in .util .StringRedisUtilObj ;
29- import org .apache .velocity .app .VelocityEngine ;
30- import org .springframework .beans .factory .annotation .Autowired ;
31- import org .springframework .security .crypto .password .PasswordEncoder ;
32- import org .springframework .stereotype .Service ;
33- import org .springframework .transaction .annotation .Transactional ;
34-
35- import static koreatech .in .domain .Mail .MailForm .*;
36-
37- import static koreatech .in .domain .RedisOwnerKeyPrefix .*;
3842
3943@ Service
4044public class OwnerServiceImpl implements OwnerService {
@@ -90,19 +94,22 @@ public void inputPasswordToChangePassword(OwnerChangePasswordRequest ownerChange
9094
9195 public void certificateToChangePassword (VerifyCodeRequest verifyCodeRequest ) {
9296 OwnerInCertification ownerInCertification = OwnerConverter .INSTANCE .toOwnerInCertification (verifyCodeRequest );
93- redisOwnerMapper .changeAuthStatus (ownerInCertification , ownerInCertification .getEmail (), ownerChangePasswordAuthPrefix );
97+ redisOwnerMapper .changeAuthStatus (ownerInCertification , ownerInCertification .getEmail (),
98+ ownerChangePasswordAuthPrefix );
9499 }
95100
96101 public void requestVerificationToChangePassword (VerifyEmailRequest verifyEmailRequest ) {
97102 EmailAddress emailAddress = OwnerConverter .INSTANCE .toEmailAddress (verifyEmailRequest );
98103 validateEmailFromOwner (emailAddress );
99104
100- CertificationCode certificationCode = mailService .sendMailWithTimes (emailAddress , OWNER_FIND_PASSWORD_MAIL_FORM );
105+ CertificationCode certificationCode = mailService .sendMailWithTimes (emailAddress ,
106+ OWNER_FIND_PASSWORD_MAIL_FORM );
101107
102108 OwnerInVerification ownerInVerification = OwnerInVerification .of (certificationCode , emailAddress );
103109
104110 emailAddress .validateSendable ();
105- redisOwnerMapper .putRedisFor (ownerChangePasswordAuthPrefix .getKey (emailAddress .getEmailAddress ()), ownerInVerification );
111+ redisOwnerMapper .putRedisFor (ownerChangePasswordAuthPrefix .getKey (emailAddress .getEmailAddress ()),
112+ ownerInVerification );
106113
107114 slackNotiSender .noticeEmailVerification (ownerInVerification );
108115 }
@@ -112,7 +119,7 @@ private Owner validateEmailFromOwner(EmailAddress emailAddress) {
112119 if (user == null || user .isStudent ()) {
113120 throw new BaseException (ExceptionInformation .NOT_EXIST_EMAIL );
114121 }
115- return (Owner ) user ;
122+ return (Owner )user ;
116123 }
117124
118125 @ Override
@@ -224,7 +231,7 @@ private static OwnerAttachments ownerAttachmentsFillWithOwnerId(Owner owner) {
224231 }
225232
226233 private OwnerAttachments updateAttachment (OwnerAttachments ownerAttachments ,
227- OwnerAttachments ownerAttachmentsInDB ) {
234+ OwnerAttachments ownerAttachmentsInDB ) {
228235 OwnerAttachments result = ownerAttachmentsInDB .intersectionWith (ownerAttachments );
229236
230237 OwnerAttachments toAdd = ownerAttachments .removeDuplicatesFrom (ownerAttachmentsInDB );
@@ -281,7 +288,8 @@ private void validateOwnerIdUniqueness(int id) {
281288
282289 private void putRedisForRequestShop (OwnerShop ownerShop ) {
283290 try {
284- stringRedisUtilObj .setDataAsString (StringRedisUtilObj .makeOwnerShopKeyFor (ownerShop .getOwner_id ()), ownerShop );
291+ stringRedisUtilObj .setDataAsString (StringRedisUtilObj .makeOwnerShopKeyFor (ownerShop .getOwner_id ()),
292+ ownerShop );
285293 } catch (Exception exception ) {
286294 throw new RuntimeException (exception );
287295 }
@@ -302,6 +310,8 @@ private void createInDBFor(Owner owner) {
302310 if (owner .hasRegistrationInformation ()) {
303311 ownerMapper .insertOwnerAttachments (ownerAttachmentsFillWithOwnerId (owner ));
304312 }
313+ } catch (DuplicateKeyException e ) {
314+ throw new BaseException (ExceptionInformation .EMAIL_DUPLICATED );
305315 } catch (SQLException e ) {
306316 throw new RuntimeException (e );
307317 }
0 commit comments