-
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.
Browse files
Browse the repository at this point in the history
Feat/#46 Certification 테이블 생성, 회사 인증 등록 API 구현
- Loading branch information
Showing
26 changed files
with
381 additions
and
192 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
58 changes: 58 additions & 0 deletions
58
src/main/java/coffeemeet/server/certification/domain/Certification.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,58 @@ | ||
package coffeemeet.server.certification.domain; | ||
|
||
import coffeemeet.server.common.entity.AdvancedBaseEntity; | ||
import coffeemeet.server.user.domain.User; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embedded; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.EnumType; | ||
import jakarta.persistence.Enumerated; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.MapsId; | ||
import jakarta.persistence.OneToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.NonNull; | ||
|
||
@Entity | ||
@Getter | ||
@Table(name = "certifications") | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Certification extends AdvancedBaseEntity { | ||
|
||
@Id | ||
private Long id; | ||
|
||
@MapsId | ||
@OneToOne(fetch = FetchType.LAZY) | ||
private User user; | ||
|
||
@Embedded | ||
@Column(nullable = false) | ||
private CompanyEmail companyEmail; | ||
|
||
@Column(nullable = false) | ||
private String businessCardUrl; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private Department department; | ||
|
||
@Column(nullable = false) | ||
private boolean isCertificated; | ||
|
||
@Builder | ||
private Certification( | ||
@NonNull CompanyEmail companyEmail, @NonNull String businessCardUrl, | ||
@NonNull Department department, @NonNull User user) { | ||
this.companyEmail = companyEmail; | ||
this.businessCardUrl = businessCardUrl; | ||
this.department = department; | ||
this.isCertificated = false; | ||
this.user = user; | ||
} | ||
|
||
} |
15 changes: 9 additions & 6 deletions
15
...meet/server/user/domain/CompanyEmail.java → ...er/certification/domain/CompanyEmail.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
5 changes: 5 additions & 0 deletions
5
src/main/java/coffeemeet/server/certification/domain/Department.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,5 @@ | ||
package coffeemeet.server.certification.domain; | ||
|
||
public enum Department { | ||
IT, MANAGEMENT, SALES, DISTRIBUTION, DESIGN, MANUFACTURING, RESEARCH_AND_DEVELOPMENT, MARKETING, PLANNING | ||
} |
1 change: 0 additions & 1 deletion
1
src/main/java/coffeemeet/server/certification/domain/EmailVerification.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
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
14 changes: 14 additions & 0 deletions
14
src/main/java/coffeemeet/server/certification/repository/CertificationRepository.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,14 @@ | ||
package coffeemeet.server.certification.repository; | ||
|
||
import coffeemeet.server.certification.domain.Certification; | ||
import coffeemeet.server.certification.domain.CompanyEmail; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface CertificationRepository extends JpaRepository<Certification, Long> { | ||
|
||
Optional<Certification> findByUserId(Long userId); | ||
|
||
boolean existsByCompanyEmail(CompanyEmail companyEmail); | ||
|
||
} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/coffeemeet/server/certification/service/cq/CertificationCommand.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,31 @@ | ||
package coffeemeet.server.certification.service.cq; | ||
|
||
import coffeemeet.server.certification.domain.Certification; | ||
import coffeemeet.server.certification.domain.CompanyEmail; | ||
import coffeemeet.server.certification.domain.Department; | ||
import coffeemeet.server.certification.repository.CertificationRepository; | ||
import coffeemeet.server.user.domain.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional | ||
@RequiredArgsConstructor | ||
public class CertificationCommand { | ||
|
||
private final CertificationRepository certificationRepository; | ||
|
||
public void newCertification(CompanyEmail companyEmail, String businessCardUrl, | ||
Department department, User user) { | ||
certificationRepository.save( | ||
Certification.builder() | ||
.companyEmail(companyEmail) | ||
.businessCardUrl(businessCardUrl) | ||
.department(department) | ||
.user(user) | ||
.build() | ||
); | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/coffeemeet/server/certification/service/cq/CertificationQuery.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,36 @@ | ||
package coffeemeet.server.certification.service.cq; | ||
|
||
import coffeemeet.server.certification.domain.Certification; | ||
import coffeemeet.server.certification.domain.CompanyEmail; | ||
import coffeemeet.server.certification.repository.CertificationRepository; | ||
import java.util.function.Consumer; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class CertificationQuery { | ||
|
||
public static final String CERTIFICATION_NOT_FOUND = "해당 사용자의 인증정보를 찾을 수 없습니다."; | ||
private static final String EXISTED_COMPANY_EMAIL = "이미 사용 중인 회사 이메일입니다."; | ||
|
||
private final CertificationRepository certificationRepository; | ||
|
||
public Certification getCertificationByUserId(Long userId) { | ||
return certificationRepository.findByUserId(userId) | ||
.orElseThrow(() -> new IllegalArgumentException(CERTIFICATION_NOT_FOUND)); | ||
} | ||
|
||
public void checkDuplicatedCompanyEmail(CompanyEmail companyEmail) { | ||
if (certificationRepository.existsByCompanyEmail(companyEmail)) { | ||
throw new IllegalArgumentException(EXISTED_COMPANY_EMAIL); | ||
} | ||
} | ||
|
||
public void applyIfCertifiedUser(Long userId, Consumer<? super Certification> consumer) { | ||
certificationRepository.findByUserId(userId).ifPresent(consumer); | ||
} | ||
|
||
} |
Oops, something went wrong.