🗂️ 개인프로젝트/인생은선착순

[개인프로젝트/인생은선착순] 2. DB 테이블 설계 및 엔티티 개발

케로⸝⸝◜࿀◝ ⸝⸝ 2024. 6. 27. 17:00

DB 테이블 설계

coupons 테이블

Column Name Data Type Constraints Comments
id BIGINT(20) PK, NOT NULL, AUTO_INCREMENT  
title VARCHAR(255) NOT NULL 쿠폰명
coupon_type VARCHAR(255) NOT NULL 쿠폰 타입 (선착순 쿠폰, ..)
total_quantity INT NULL 쿠폰 발급 최대 수량
issued_quantity INT NOT NULL 발급된 쿠폰 수량
discount_amount INT NOT NULL 할인 금액
min_available_amount INT NOT NULL 최소 사용 금액
date_issue_start datetime(6) NOT NULL 발급 시작 일시
date_issue_end datetime(6) NOT NULL 발급 종료 일시
date_created datetime(6) NOT NULL 생성 일시
date_updated datetime(6) NOT NULL 수정 일시

 

coupon_issues 테이블

Column Name Data Type Constraints Comments
id BIGINT(20) PK, NOT NULL, AUTO_INCREMENT  
coupon_id BIGINT(20) NOT NULL 쿠폰 ID
user_id BIGINT(20) NOT NULL 유저 ID
date_issued datetime(6) NOT NULL 발급 일시
date_used datetime(6) NULL 사용 일시
date_created datetime(6) NOT NULL 생성 일시
date_updated datetime(6) NOT NULL 수정 일시

 

BaseTimeEntity 추가

더보기
package me.progfrog.couponcore.model;

import jakarta.persistence.EntityListeners;
import jakarta.persistence.MappedSuperclass;
import lombok.Getter;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDate;

@Getter
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class BaseTimeEntity {

    @CreatedDate
    private LocalDate dateCreated;

    @LastModifiedDate
    private LocalDate dateUpdated;
}
  • @EntityListeners(AuditingEntityListener.class)
package me.progfrog.couponcore;

import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

@EnableJpaAuditing
@ComponentScan
@EnableAutoConfiguration
public class CouponCoreConfiguration {
}
  • @EnableJpaAuditing

 

쿠폰 엔티티 개발

 

[feature/domain] 쿠폰 엔티티 및 쿠폰 발급 기능 개발 by happyprogfrog · Pull Request #1 · happyprogfrog/coupon-sa

작업 내용 DB 테이블 스키마 추가 쿠폰 정책 확인용 쿠폰 발급 내역 기록용 쿠폰 엔티티 작성 쿠폰 발급 기능 개발 쿠폰 발급 기간 검증 쿠폰 발급 수량 검증 중복 발급 요청 검증 모든 검증이 완

github.com

 

[스프링] QueryDSL 설정

QueryDSL자바를 위한 동적 쿼리 작성을 위한 오픈 소스 라이브러리QueryDSL은 정적 타입 검사 및 코드 자동 완성을 제공하여, 쿼리 작성 시 발생할 수 있는 오류를 사전에 방지하고, 쿼리 작성을 더

progfrog.tistory.com

 

반응형