Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor#209 인증 도메인 구조 변경 #212

Merged
merged 76 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
6650784
feat: 매칭 취소 시 유저 상태 확인
smartandhandsome Dec 19, 2023
55b9b83
style: 포맷팅
smartandhandsome Dec 19, 2023
4490ac3
test: 메인코드 변경에 따른 수정 및 매칭 취소 실패 케이스 테스트 작성
smartandhandsome Dec 19, 2023
d3e3631
refactor: infra -> domain 위치 변경 및 리팩토링
smartandhandsome Dec 19, 2023
faed8c5
feat: ObjectStorage impl 계층 구현
smartandhandsome Dec 19, 2023
d8dbdad
feat: update 메서드 구현
smartandhandsome Dec 19, 2023
b7dd4e7
feat: 패키지 이동 및 변수명 변경
smartandhandsome Dec 19, 2023
c90bcfd
feat: 패키지 이동 및 변수명 변경
smartandhandsome Dec 19, 2023
67aac13
feat: BusinessCardImage impl 계층 구현
smartandhandsome Dec 19, 2023
22f3afa
feat: Email 인증 관련 impl 계층 구현
smartandhandsome Dec 19, 2023
3738ca1
feat: 검증 정보 Query, Command 구현
smartandhandsome Dec 19, 2023
4dd31dd
refactor: 파일 변경
smartandhandsome Dec 19, 2023
7d4c7a7
refactor: Certification Query, Command 리팩토링
smartandhandsome Dec 19, 2023
b448fff
refactor: facade 패턴으로 Service 계층 구현
smartandhandsome Dec 19, 2023
d92f492
feat: 정적 팩토리 메서드 추가
smartandhandsome Dec 19, 2023
4570651
refactor: 메서드 명 변경
smartandhandsome Dec 19, 2023
5ed1192
test: 테스트 구현 및 메인 코드 변경에 따른 수정
smartandhandsome Dec 19, 2023
50800dc
refactor: 데이터 타입 수정
Dec 18, 2023
a74bcc4
refactor: report 도메인 dto 리팩토링
Dec 18, 2023
c57e236
refactor: certification 도메인 dto 리팩토링
Dec 18, 2023
ea1ad69
refactor: chatting current 도메인 리팩토링
Dec 18, 2023
d82c964
refactor: chatting history 도메인 리팩토링
Dec 18, 2023
d2f3b52
refactor: Inquiry 도메인 리팩토링
Dec 18, 2023
0548e72
test: Fixture 정리
Dec 18, 2023
0464622
refactor: String 값 상수 처리
Dec 18, 2023
2c6a911
refactor: Faker 대신 instancio 사용
Dec 19, 2023
8e54104
refactor: 네이밍 변경
Dec 19, 2023
fa7a643
refactor: 메서드 네이밍 변경
Dec 19, 2023
fdee847
refactor: ChattingMessageHistory -> ChattingHistory
Dec 19, 2023
b81545c
refactor: ChatRoom -> ChattingRoom
Dec 19, 2023
95c1886
refactor: Chat -> Chatting
Dec 19, 2023
ebe545c
refactor: ChattingHistoryCustomSlice, ChattingHistoryListDto 네이밍 변경
Dec 19, 2023
63d38d0
refactor: ReportSummary 네이밍 변경
Dec 19, 2023
752c001
refactor: import Report
Dec 19, 2023
c2465c4
feat: ChattingDto 생성
Dec 19, 2023
d8618c2
test: 메인코드 변경에 따른 수정 및 매칭 취소 실패 케이스 테스트 작성
smartandhandsome Dec 19, 2023
69e7f39
refactor: infra -> domain 위치 변경 및 리팩토링
smartandhandsome Dec 19, 2023
95547a5
feat: 패키지 이동 및 변수명 변경
smartandhandsome Dec 19, 2023
461404b
refactor: facade 패턴으로 Service 계층 구현
smartandhandsome Dec 19, 2023
b5278c3
feat: 정적 팩토리 메서드 추가
smartandhandsome Dec 19, 2023
120efd4
test: 테스트 구현 및 메인 코드 변경에 따른 수정
smartandhandsome Dec 19, 2023
71fa16e
refactor: 컨플릭트 수정
smartandhandsome Dec 20, 2023
ff6d24a
refactor: certification 도메인 dto 리팩토링
Dec 18, 2023
cb1e0b4
refactor: 네이밍 변경
Dec 19, 2023
3e0515d
feat: ChattingDto 생성
Dec 19, 2023
4adb6cd
refactor: infra -> domain 위치 변경 및 리팩토링
smartandhandsome Dec 19, 2023
d2fc3e5
feat: 패키지 이동 및 변수명 변경
smartandhandsome Dec 19, 2023
218dcf7
refactor: 데이터 타입 수정
Dec 18, 2023
789b8f5
refactor: certification 도메인 dto 리팩토링
Dec 18, 2023
8dc4777
test: Fixture 정리
Dec 18, 2023
941d026
refactor: 네이밍 변경
Dec 19, 2023
fb34c6b
feat: ChattingDto 생성
Dec 19, 2023
b250c01
feat: 패키지 이동 및 변수명 변경
smartandhandsome Dec 19, 2023
11a6eb4
test: 테스트 구현 및 메인 코드 변경에 따른 수정
smartandhandsome Dec 19, 2023
f267eab
refactor: 컨플릭트 수정
smartandhandsome Dec 20, 2023
21e3d1f
refactor: 데이터 타입 수정
Dec 18, 2023
25ad2d4
refactor: certification 도메인 dto 리팩토링
Dec 18, 2023
87d8082
test: Fixture 정리
Dec 18, 2023
ad129c4
refactor: 네이밍 변경
Dec 19, 2023
ebc3aa1
feat: ChattingDto 생성
Dec 19, 2023
a3aa965
refactor: infra -> domain 위치 변경 및 리팩토링
smartandhandsome Dec 19, 2023
9188212
feat: 패키지 이동 및 변수명 변경
smartandhandsome Dec 19, 2023
fc7a8f8
refactor: facade 패턴으로 Service 계층 구현
smartandhandsome Dec 19, 2023
9ab8b4c
feat: 정적 팩토리 메서드 추가
smartandhandsome Dec 19, 2023
93c280e
test: 테스트 구현 및 메인 코드 변경에 따른 수정
smartandhandsome Dec 19, 2023
1eb6670
refactor: 데이터 타입 수정
Dec 18, 2023
f6b10a6
refactor: certification 도메인 dto 리팩토링
Dec 18, 2023
0d90e3e
refactor: 네이밍 변경
Dec 19, 2023
5b91877
test: 테스트 구현 및 메인 코드 변경에 따른 수정
smartandhandsome Dec 19, 2023
7afe8be
refactor: 컨플릭트 수정
smartandhandsome Dec 20, 2023
d5e9278
refactor: certification 도메인 dto 리팩토링
Dec 18, 2023
214a054
refactor: 네이밍 변경
Dec 19, 2023
2a34718
refactor: 네이밍 변경
Dec 19, 2023
41a0c86
refactor: 컨플릭트 수정
smartandhandsome Dec 20, 2023
b9476af
Merge branch 'dev' into refactor/#209
smartandhandsome Dec 20, 2023
ad483d5
Merge branch 'dev' into refactor/#209
smartandhandsome Dec 21, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import coffeemeet.server.admin.implement.AdminQuery;
import coffeemeet.server.certification.implement.CertificationCommand;
import coffeemeet.server.certification.implement.CertificationQuery;
import coffeemeet.server.common.implement.FCMNotificationSender;
import coffeemeet.server.common.infrastructure.FCMNotificationSender;
import coffeemeet.server.inquiry.domain.Inquiry;
import coffeemeet.server.inquiry.implement.InquiryCommand;
import coffeemeet.server.inquiry.implement.InquiryQuery;
Expand Down Expand Up @@ -38,7 +38,7 @@ public void login(String id, String password) {
}

public void approveCertification(Long certificationId) {
certificationCommand.certificated(certificationId);
certificationCommand.completeCertification(certificationId);

Long userId = certificationQuery.getUserIdByCertificationId(certificationId);
NotificationInfo notificationInfo = userQuery.getNotificationInfoByUserId(userId);
Expand All @@ -48,7 +48,7 @@ public void approveCertification(Long certificationId) {
}

public void rejectCertification(Long certificationId) {
certificationCommand.deleteCertification(certificationId);
certificationCommand.deleteCertificationByUserId(certificationId);

Long userId = certificationQuery.getUserIdByCertificationId(certificationId);
NotificationInfo notificationInfo = userQuery.getNotificationInfoByUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,16 @@ public class Certification extends AdvancedBaseEntity {
@Column(nullable = false)
private String companyName;

@Embedded
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Department department;

@Embedded
private CompanyEmail companyEmail;

@Column(nullable = false)
private String businessCardUrl;

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Department department;

@Column(nullable = false)
private boolean isCertificated;

Expand All @@ -64,4 +63,12 @@ public void qualify() {
isCertificated = true;
}

public void update(String companyName, CompanyEmail companyEmail, String businessCardUrl,
Department department) {
this.companyName = companyName;
this.companyEmail = companyEmail;
this.businessCardUrl = businessCardUrl;
this.department = department;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
import org.springframework.data.redis.core.RedisHash;

@Getter
@RedisHash(value = "email_verification", timeToLive = 360)
public class EmailVerification {
@RedisHash(value = "email_verification", timeToLive = 300)
public class VerificationInfo {

@Id
private Long userId;
private CompanyEmail companyEmail;
private String code;
private String verificationCode;
private LocalDateTime createdAt;

public EmailVerification(@NonNull Long userId, @NonNull CompanyEmail companyEmail,
@NonNull String code) {
public VerificationInfo(@NonNull Long userId, @NonNull CompanyEmail companyEmail,
@NonNull String verificationCode) {
this.userId = userId;
this.companyEmail = companyEmail;
this.code = code;
this.verificationCode = verificationCode;
this.createdAt = LocalDateTime.now();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package coffeemeet.server.certification.infrastructure;
package coffeemeet.server.certification.domain.repository;

import coffeemeet.server.certification.domain.Certification;
import coffeemeet.server.certification.domain.CompanyEmail;
Expand All @@ -14,6 +14,8 @@ public interface CertificationRepository extends JpaRepository<Certification, Lo

boolean existsByCompanyEmail(CompanyEmail companyEmail);

void deleteByUserId(Long userId);

@Query("SELECT c FROM Certification c JOIN FETCH c.user WHERE c.isCertificated = false")
Page<Certification> findPendingCertifications(Pageable pageable);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package coffeemeet.server.certification.domain.repository;

import coffeemeet.server.certification.domain.VerificationInfo;
import org.springframework.data.repository.CrudRepository;

public interface VerificationInfoRepository extends CrudRepository<VerificationInfo, Long> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package coffeemeet.server.certification.implement;

import static coffeemeet.server.common.domain.S3KeyPrefix.BUSINESS_CARD;

import coffeemeet.server.certification.domain.Certification;
import coffeemeet.server.common.implement.ImageDeleter;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class BusinessCardImageDeleter {

private final CertificationQuery certificationQuery;
private final ImageDeleter imageDeleter;

public void deleteBusinessCardImageByUserId(Long userId) {
Certification certification = certificationQuery.getCertificationByUserId(userId);
imageDeleter.deleteImage(certification.getBusinessCardUrl(), BUSINESS_CARD);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package coffeemeet.server.certification.implement;

import static coffeemeet.server.common.domain.S3KeyPrefix.BUSINESS_CARD;

import coffeemeet.server.common.implement.ImageUploader;
import java.io.File;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class BusinessCardImageUploader {

private final ImageUploader imageUploader;

public String uploadBusinessCardImage(File businessCardImage) {
return imageUploader.uploadImage(businessCardImage, BUSINESS_CARD);
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package coffeemeet.server.certification.implement;

import static coffeemeet.server.certification.exception.CertificationErrorCode.EXISTED_COMPANY_EMAIL;

import coffeemeet.server.certification.domain.Certification;
import coffeemeet.server.certification.domain.CompanyEmail;
import coffeemeet.server.certification.domain.Department;
import coffeemeet.server.certification.infrastructure.CertificationRepository;
import coffeemeet.server.common.execption.InvalidInputException;
import coffeemeet.server.certification.domain.repository.CertificationRepository;
import coffeemeet.server.user.domain.User;
import java.util.function.Consumer;
import coffeemeet.server.user.implement.UserQuery;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -18,13 +15,13 @@
@RequiredArgsConstructor
public class CertificationCommand {

private static final String EXISTED_COMPANY_EMAIL_MESSAGE = "이미 사용 중인 회사 이메일(%s) 입니다.";

private final CertificationRepository certificationRepository;
private final CertificationQuery certificationQuery;
private final UserQuery userQuery;

public void createCertification(User user, String companyName, CompanyEmail companyEmail,
public void createCertification(Long userId, String companyName, CompanyEmail companyEmail,
Department department, String businessCardUrl) {
User user = userQuery.getUserById(userId);
certificationRepository.save(
Certification.builder()
.companyName(companyName)
Expand All @@ -36,25 +33,19 @@ public void createCertification(User user, String companyName, CompanyEmail comp
);
}

public void hasDuplicatedCompanyEmail(CompanyEmail companyEmail) {
if (certificationRepository.existsByCompanyEmail(companyEmail)) {
throw new InvalidInputException(EXISTED_COMPANY_EMAIL,
String.format(EXISTED_COMPANY_EMAIL_MESSAGE, companyEmail.getValue()));
}
public void updateCertification(Long userId, String companyName, CompanyEmail companyEmail,
Department department, String businessCardImageUrl) {
Certification certification = certificationQuery.getCertificationByUserId(userId);
certification.update(companyName, companyEmail, businessCardImageUrl, department);
}

public void certificated(Long userId) {
public void completeCertification(Long userId) {
Certification certification = certificationQuery.getCertificationByUserId(userId);
certification.qualify();
}

@Transactional(readOnly = true)
public void applyIfCertifiedUser(Long userId, Consumer<? super Certification> consumer) {
certificationRepository.findByUserId(userId).ifPresent(consumer);
}

public void deleteCertification(Long userId) {
certificationRepository.deleteById(userId);
public void deleteCertificationByUserId(Long userId) {
certificationRepository.deleteByUserId(userId);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import static coffeemeet.server.certification.exception.CertificationErrorCode.CERTIFICATION_NOT_FOUND;

import coffeemeet.server.certification.domain.Certification;
import coffeemeet.server.certification.infrastructure.CertificationRepository;
import coffeemeet.server.certification.domain.CompanyEmail;
import coffeemeet.server.certification.domain.repository.CertificationRepository;
import coffeemeet.server.common.execption.InvalidInputException;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -33,6 +34,10 @@ public String getCompanyNameByUserId(Long userId) {
).getCompanyName();
}

public boolean isExistedCompanyEmail(CompanyEmail companyEmail) {
return certificationRepository.existsByCompanyEmail(companyEmail);
}

public Long getUserIdByCertificationId(Long certificationId) {
return certificationId;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package coffeemeet.server.certification.implement;

import static coffeemeet.server.certification.exception.CertificationErrorCode.EXISTED_COMPANY_EMAIL;

import coffeemeet.server.certification.domain.CompanyEmail;
import coffeemeet.server.common.execption.InvalidInputException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class CompanyEmailValidator {

private static final String EXISTED_COMPANY_EMAIL_MESSAGE = "이미 사용 중인 회사 이메일(%s) 입니다.";

private final CertificationQuery certificationQuery;

public void validateDuplicatedCompanyEmail(CompanyEmail companyEmail) {
if (certificationQuery.isExistedCompanyEmail(companyEmail)) {
throw new InvalidInputException(EXISTED_COMPANY_EMAIL,
String.format(EXISTED_COMPANY_EMAIL_MESSAGE, companyEmail.getValue()));
}
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package coffeemeet.server.certification.implement;

import java.util.random.RandomGenerator;
import org.springframework.stereotype.Component;

@Component
public class VerificationCodeGenerator {

private static final RandomGenerator RANDOM_GENERATOR = RandomGenerator.getDefault();

public String generateVerificationCode() {
return String.format("%06d", RANDOM_GENERATOR.nextInt(1000000));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package coffeemeet.server.certification.implement;

import static coffeemeet.server.certification.exception.CertificationErrorCode.INVALID_VERIFICATION_CODE;

import coffeemeet.server.common.execption.InvalidInputException;
import org.springframework.stereotype.Component;

@Component
public class VerificationCodeValidator {

private static final String WRONG_VERIFICATION_CODE_MESSAGE = "잘못된 인증코드(%s)를 입력했습니다.";

public void validateVerificationCode(String verificationCode, String userInputCode) {
if (!userInputCode.equals(verificationCode)) {
throw new InvalidInputException(INVALID_VERIFICATION_CODE,
String.format(WRONG_VERIFICATION_CODE_MESSAGE, verificationCode));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package coffeemeet.server.certification.implement;

import coffeemeet.server.certification.domain.CompanyEmail;
import coffeemeet.server.certification.domain.VerificationInfo;
import coffeemeet.server.certification.domain.repository.VerificationInfoRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class VerificationInfoCommand {

private final VerificationInfoRepository verificationInfoRepository;

public void createVerificationInfo(Long userId, CompanyEmail companyEmail,
String verificationCode) {
verificationInfoRepository.save(new VerificationInfo(userId, companyEmail, verificationCode));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

import static coffeemeet.server.certification.exception.CertificationErrorCode.VERIFICATION_CODE_NOT_FOUND;

import coffeemeet.server.certification.domain.EmailVerification;
import coffeemeet.server.certification.infrastructure.EmailVerificationRepository;
import coffeemeet.server.certification.domain.VerificationInfo;
import coffeemeet.server.certification.domain.repository.VerificationInfoRepository;
import coffeemeet.server.common.execption.InvalidInputException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class EmailVerificationQuery {
public class VerificationInfoQuery {

private static final String VERIFICATION_CODE_NOT_FOUND_MESSAGE = "인증코드 기간이 만료되었거나 해당 유저(%s)가 인증코드를 요청한 기록이 없습니다.";

private final EmailVerificationRepository emailVerificationRepository;
private final VerificationInfoRepository verificationInfoRepository;

public String getCodeById(Long userId) {
EmailVerification emailVerification = emailVerificationRepository.findById(userId)
public String getVerificationCodeById(Long userId) {
VerificationInfo verificationInfo = verificationInfoRepository.findById(userId)
.orElseThrow(() -> new InvalidInputException(
VERIFICATION_CODE_NOT_FOUND,
String.format(VERIFICATION_CODE_NOT_FOUND_MESSAGE, userId)));
return emailVerification.getCode();
return verificationInfo.getVerificationCode();
}

}
Loading