Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions src/main/java/koreatech/in/service/OwnerServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package koreatech.in.service;

import static koreatech.in.domain.Mail.MailForm.OWNER_FIND_PASSWORD_MAIL_FORM;
import static koreatech.in.domain.Mail.MailForm.OWNER_REGISTRATION_MAIL_FORM;
import static koreatech.in.domain.RedisOwnerKeyPrefix.ownerAuthPrefix;
import static koreatech.in.domain.RedisOwnerKeyPrefix.ownerChangePasswordAuthPrefix;

import java.sql.SQLException;

import org.apache.velocity.app.VelocityEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import koreatech.in.domain.User.EmailAddress;
import koreatech.in.domain.User.User;
import koreatech.in.domain.User.owner.CertificationCode;
Expand All @@ -26,15 +39,6 @@
import koreatech.in.util.SesMailSender;
import koreatech.in.util.SlackNotiSender;
import koreatech.in.util.StringRedisUtilObj;
import org.apache.velocity.app.VelocityEngine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static koreatech.in.domain.Mail.MailForm.*;

import static koreatech.in.domain.RedisOwnerKeyPrefix.*;

@Service
public class OwnerServiceImpl implements OwnerService {
Expand Down Expand Up @@ -90,19 +94,22 @@ public void inputPasswordToChangePassword(OwnerChangePasswordRequest ownerChange

public void certificateToChangePassword(VerifyCodeRequest verifyCodeRequest) {
OwnerInCertification ownerInCertification = OwnerConverter.INSTANCE.toOwnerInCertification(verifyCodeRequest);
redisOwnerMapper.changeAuthStatus(ownerInCertification, ownerInCertification.getEmail(), ownerChangePasswordAuthPrefix);
redisOwnerMapper.changeAuthStatus(ownerInCertification, ownerInCertification.getEmail(),
ownerChangePasswordAuthPrefix);
}

public void requestVerificationToChangePassword(VerifyEmailRequest verifyEmailRequest) {
EmailAddress emailAddress = OwnerConverter.INSTANCE.toEmailAddress(verifyEmailRequest);
validateEmailFromOwner(emailAddress);

CertificationCode certificationCode = mailService.sendMailWithTimes(emailAddress, OWNER_FIND_PASSWORD_MAIL_FORM);
CertificationCode certificationCode = mailService.sendMailWithTimes(emailAddress,
OWNER_FIND_PASSWORD_MAIL_FORM);

OwnerInVerification ownerInVerification = OwnerInVerification.of(certificationCode, emailAddress);

emailAddress.validateSendable();
redisOwnerMapper.putRedisFor(ownerChangePasswordAuthPrefix.getKey(emailAddress.getEmailAddress()), ownerInVerification);
redisOwnerMapper.putRedisFor(ownerChangePasswordAuthPrefix.getKey(emailAddress.getEmailAddress()),
ownerInVerification);

slackNotiSender.noticeEmailVerification(ownerInVerification);
}
Expand All @@ -112,7 +119,7 @@ private Owner validateEmailFromOwner(EmailAddress emailAddress) {
if (user == null || user.isStudent()) {
throw new BaseException(ExceptionInformation.NOT_EXIST_EMAIL);
}
return (Owner) user;
return (Owner)user;
}

@Override
Expand Down Expand Up @@ -224,7 +231,7 @@ private static OwnerAttachments ownerAttachmentsFillWithOwnerId(Owner owner) {
}

private OwnerAttachments updateAttachment(OwnerAttachments ownerAttachments,
OwnerAttachments ownerAttachmentsInDB) {
OwnerAttachments ownerAttachmentsInDB) {
OwnerAttachments result = ownerAttachmentsInDB.intersectionWith(ownerAttachments);

OwnerAttachments toAdd = ownerAttachments.removeDuplicatesFrom(ownerAttachmentsInDB);
Expand Down Expand Up @@ -281,7 +288,8 @@ private void validateOwnerIdUniqueness(int id) {

private void putRedisForRequestShop(OwnerShop ownerShop) {
try {
stringRedisUtilObj.setDataAsString(StringRedisUtilObj.makeOwnerShopKeyFor(ownerShop.getOwner_id()), ownerShop);
stringRedisUtilObj.setDataAsString(StringRedisUtilObj.makeOwnerShopKeyFor(ownerShop.getOwner_id()),
ownerShop);
} catch (Exception exception) {
throw new RuntimeException(exception);
}
Expand All @@ -302,6 +310,8 @@ private void createInDBFor(Owner owner) {
if (owner.hasRegistrationInformation()) {
ownerMapper.insertOwnerAttachments(ownerAttachmentsFillWithOwnerId(owner));
}
} catch (DuplicateKeyException e) {
throw new BaseException(ExceptionInformation.EMAIL_DUPLICATED);
} catch (SQLException e) {
throw new RuntimeException(e);
}
Expand Down