diff --git a/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java b/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java index 10591e2..e6ddfa4 100644 --- a/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java +++ b/src/main/java/com/readyvery/readyverydemo/domain/CeoInfo.java @@ -1,7 +1,10 @@ package com.readyvery.readyverydemo.domain; import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; +import jakarta.persistence.CascadeType; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.EnumType; @@ -12,6 +15,7 @@ import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; +import jakarta.persistence.OneToMany; import jakarta.persistence.Table; import lombok.AllArgsConstructor; import lombok.Builder; @@ -37,29 +41,38 @@ public class CeoInfo extends BaseTimeEntity { @Column(nullable = false, length = 45) private String email; + // 비밀번호 + @Column(nullable = false, length = 100) + private String password; + // 닉네임 @Column(nullable = false) private String nickName; // 프로필 이미지 - @Column(nullable = false, columnDefinition = "TEXT") + @Column(nullable = true) private String imageUrl; // 전화번호 - @Column(nullable = false) + @Column private String phone; // 계좌번호 @Column private String accountNumber; + // 유저 권한 + @Column(nullable = false, columnDefinition = "VARCHAR(10) default 'USER'") + @Enumerated(EnumType.STRING) + private Role role; + // 소셜 로그인 타입 - @Column(nullable = false) + @Column @Enumerated(EnumType.STRING) private SocialType socialType; // KAKAO, NAVER, GOOGLE // 소셜 로그인 타입의 식별자 값 (일반 로그인인 경우 null) - @Column(nullable = false) + @Column private String socialId; // 로그인한 소셜 타입의 식별자 값 (일반 로그인인 경우 null) // 유저 상태 @@ -81,6 +94,11 @@ public class CeoInfo extends BaseTimeEntity { // 사장님 가게 연관관계 매핑 @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "store_idx") - private Store store; + private Store store = null; + + // 사장님 입점신청서 연관관계 매핑 + @Builder.Default + @OneToMany(mappedBy = "ceoInfo", cascade = CascadeType.ALL) + private List ceoMetaInfos = new ArrayList(); } diff --git a/src/main/java/com/readyvery/readyverydemo/domain/CeoMetaInfo.java b/src/main/java/com/readyvery/readyverydemo/domain/CeoMetaInfo.java new file mode 100644 index 0000000..e417aa6 --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/domain/CeoMetaInfo.java @@ -0,0 +1,57 @@ +package com.readyvery.readyverydemo.domain; + +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.FetchType; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; +import jakarta.persistence.Table; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +@Getter +@NoArgsConstructor +@Entity +@Builder +@Table(name = "INFOTAINMENT") +@AllArgsConstructor +@Slf4j +public class CeoMetaInfo extends BaseTimeEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ceo_meta_idx") + private Long id; + + @Column(nullable = false, length = 45) + private String storeName; + + @Column(nullable = false, length = 100) + private String storeAddress; + + @Column(nullable = false, length = 45) + private String registrationNumber; + + @Column(nullable = false, columnDefinition = "TEXT") + private String businessLicenseFileName; + + @Column(nullable = false, columnDefinition = "TEXT") + private String businessReportFileName; + + @Column(nullable = false, columnDefinition = "TEXT") + private String identityCardFileName; + + @Column(nullable = false, columnDefinition = "TEXT") + private String bankAccountFileName; + + // 입점신청 사장님 연관관계 매핑 + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "ceo_idx") + private CeoInfo ceoInfo; + +} diff --git a/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtServiceImpl.java b/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtServiceImpl.java index 4cdaa28..62d7a64 100644 --- a/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtServiceImpl.java +++ b/src/main/java/com/readyvery/readyverydemo/security/jwt/service/JwtServiceImpl.java @@ -101,6 +101,7 @@ public Optional extractAccessToken(HttpServletRequest request) { public Optional extractEmail(String accessToken) { try { // 토큰 유효성 검사하는 데에 사용할 알고리즘이 있는 JWT verifier builder 반환 + log.info("액세스 토큰 유효성 검사"); return jwtTokenizer.verifyAccessToken(accessToken); } catch (Exception e) { log.error("액세스 토큰이 유효하지 않습니다."); diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java index cb19535..6ecc1ce 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/CurrentRes.java @@ -15,4 +15,5 @@ public class CurrentRes { private String estimatedTime; private String cancels; private Long inout; + private Long expectPoint; } diff --git a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java index 48b2b4f..287aceb 100644 --- a/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java +++ b/src/main/java/com/readyvery/readyverydemo/src/order/dto/OrderMapper.java @@ -22,6 +22,7 @@ import com.readyvery.readyverydemo.domain.Point; import com.readyvery.readyverydemo.domain.Receipt; import com.readyvery.readyverydemo.src.order.config.TossPaymentConfig; +import com.readyvery.readyverydemo.src.point.PointPolicy; import lombok.RequiredArgsConstructor; @@ -29,6 +30,7 @@ @RequiredArgsConstructor public class OrderMapper { private final TossPaymentConfig tossPaymentConfig; + private final PointPolicy pointPolicy; public FoodyDetailRes foodieToFoodyDetailRes(Foodie foodie, Long inout) { Long price = determinePrice(foodie, inout); @@ -294,6 +296,7 @@ private ReceiptHistoryDto orderToReceiptHistoryDto(Order order) { public CurrentRes orderToCurrentRes(Order order) { return CurrentRes.builder() .inout(order.getInOut()) + .expectPoint(pointPolicy.calculatePoint(order.getAmount())) .cancels(order.getReceipt().getCancels()) .name(order.getStore().getName()) .orderNum(order.getOrderNumber()) diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/DefaultPointPolicy.java b/src/main/java/com/readyvery/readyverydemo/src/point/DefaultPointPolicy.java new file mode 100644 index 0000000..877abac --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/point/DefaultPointPolicy.java @@ -0,0 +1,14 @@ +package com.readyvery.readyverydemo.src.point; + +import org.springframework.stereotype.Service; + +@Service +public class DefaultPointPolicy implements PointPolicy { + private Double pointRate = 2.5; + + @Override + public Long calculatePoint(Long price) { + Double tmp = price * pointRate / 100 + 0.5; // 반올림 + return tmp.longValue(); + } +} diff --git a/src/main/java/com/readyvery/readyverydemo/src/point/PointPolicy.java b/src/main/java/com/readyvery/readyverydemo/src/point/PointPolicy.java new file mode 100644 index 0000000..6d3bbcf --- /dev/null +++ b/src/main/java/com/readyvery/readyverydemo/src/point/PointPolicy.java @@ -0,0 +1,5 @@ +package com.readyvery.readyverydemo.src.point; + +public interface PointPolicy { + Long calculatePoint(Long price); +} diff --git a/src/test/java/com/readyvery/readyverydemo/src/point/DefaultPointPolicyTest.java b/src/test/java/com/readyvery/readyverydemo/src/point/DefaultPointPolicyTest.java new file mode 100644 index 0000000..41e08bc --- /dev/null +++ b/src/test/java/com/readyvery/readyverydemo/src/point/DefaultPointPolicyTest.java @@ -0,0 +1,48 @@ +package com.readyvery.readyverydemo.src.point; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.junit.jupiter.MockitoExtension; + +@ExtendWith(MockitoExtension.class) +class DefaultPointPolicyTest { + @InjectMocks + private DefaultPointPolicy defaultPointPolicy; + + @Test + @DisplayName("작은 금액 테스트") + void calculateSmallPoint() { + // given + Long amount = 1_050L; // 계산 금액 + // when + Long point = defaultPointPolicy.calculatePoint(amount); + // then + assertEquals(26L, point); + } + + @Test + @DisplayName("보통 금액 테스트") + void calculateNomalPoint() { + // given + Long amount = 10_000L; // 계산 금액 + // when + Long point = defaultPointPolicy.calculatePoint(amount); + // then + assertEquals(250L, point); + } + + @Test + @DisplayName("큰 금액 테스트") + void calculateBigPoint() { + // given + Long amount = 532_400L; // 계산 금액 + // when + Long point = defaultPointPolicy.calculatePoint(amount); + // then + assertEquals(13_310L, point); + } +}