1
1
package koreatech .in .service ;
2
2
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
+
3
8
import 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
+
4
17
import koreatech .in .domain .User .EmailAddress ;
5
18
import koreatech .in .domain .User .User ;
6
19
import koreatech .in .domain .User .owner .CertificationCode ;
26
39
import koreatech .in .util .SesMailSender ;
27
40
import koreatech .in .util .SlackNotiSender ;
28
41
import 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 .*;
38
42
39
43
@ Service
40
44
public class OwnerServiceImpl implements OwnerService {
@@ -90,19 +94,22 @@ public void inputPasswordToChangePassword(OwnerChangePasswordRequest ownerChange
90
94
91
95
public void certificateToChangePassword (VerifyCodeRequest verifyCodeRequest ) {
92
96
OwnerInCertification ownerInCertification = OwnerConverter .INSTANCE .toOwnerInCertification (verifyCodeRequest );
93
- redisOwnerMapper .changeAuthStatus (ownerInCertification , ownerInCertification .getEmail (), ownerChangePasswordAuthPrefix );
97
+ redisOwnerMapper .changeAuthStatus (ownerInCertification , ownerInCertification .getEmail (),
98
+ ownerChangePasswordAuthPrefix );
94
99
}
95
100
96
101
public void requestVerificationToChangePassword (VerifyEmailRequest verifyEmailRequest ) {
97
102
EmailAddress emailAddress = OwnerConverter .INSTANCE .toEmailAddress (verifyEmailRequest );
98
103
validateEmailFromOwner (emailAddress );
99
104
100
- CertificationCode certificationCode = mailService .sendMailWithTimes (emailAddress , OWNER_FIND_PASSWORD_MAIL_FORM );
105
+ CertificationCode certificationCode = mailService .sendMailWithTimes (emailAddress ,
106
+ OWNER_FIND_PASSWORD_MAIL_FORM );
101
107
102
108
OwnerInVerification ownerInVerification = OwnerInVerification .of (certificationCode , emailAddress );
103
109
104
110
emailAddress .validateSendable ();
105
- redisOwnerMapper .putRedisFor (ownerChangePasswordAuthPrefix .getKey (emailAddress .getEmailAddress ()), ownerInVerification );
111
+ redisOwnerMapper .putRedisFor (ownerChangePasswordAuthPrefix .getKey (emailAddress .getEmailAddress ()),
112
+ ownerInVerification );
106
113
107
114
slackNotiSender .noticeEmailVerification (ownerInVerification );
108
115
}
@@ -112,7 +119,7 @@ private Owner validateEmailFromOwner(EmailAddress emailAddress) {
112
119
if (user == null || user .isStudent ()) {
113
120
throw new BaseException (ExceptionInformation .NOT_EXIST_EMAIL );
114
121
}
115
- return (Owner ) user ;
122
+ return (Owner )user ;
116
123
}
117
124
118
125
@ Override
@@ -224,7 +231,7 @@ private static OwnerAttachments ownerAttachmentsFillWithOwnerId(Owner owner) {
224
231
}
225
232
226
233
private OwnerAttachments updateAttachment (OwnerAttachments ownerAttachments ,
227
- OwnerAttachments ownerAttachmentsInDB ) {
234
+ OwnerAttachments ownerAttachmentsInDB ) {
228
235
OwnerAttachments result = ownerAttachmentsInDB .intersectionWith (ownerAttachments );
229
236
230
237
OwnerAttachments toAdd = ownerAttachments .removeDuplicatesFrom (ownerAttachmentsInDB );
@@ -281,7 +288,8 @@ private void validateOwnerIdUniqueness(int id) {
281
288
282
289
private void putRedisForRequestShop (OwnerShop ownerShop ) {
283
290
try {
284
- stringRedisUtilObj .setDataAsString (StringRedisUtilObj .makeOwnerShopKeyFor (ownerShop .getOwner_id ()), ownerShop );
291
+ stringRedisUtilObj .setDataAsString (StringRedisUtilObj .makeOwnerShopKeyFor (ownerShop .getOwner_id ()),
292
+ ownerShop );
285
293
} catch (Exception exception ) {
286
294
throw new RuntimeException (exception );
287
295
}
@@ -302,6 +310,8 @@ private void createInDBFor(Owner owner) {
302
310
if (owner .hasRegistrationInformation ()) {
303
311
ownerMapper .insertOwnerAttachments (ownerAttachmentsFillWithOwnerId (owner ));
304
312
}
313
+ } catch (DuplicateKeyException e ) {
314
+ throw new BaseException (ExceptionInformation .EMAIL_DUPLICATED );
305
315
} catch (SQLException e ) {
306
316
throw new RuntimeException (e );
307
317
}
0 commit comments