Skip to content

Commit

Permalink
feat: 데이터 모델 테이블 정의 및 형상 관리 (#1)
Browse files Browse the repository at this point in the history
* prod: jpa 및 기본 엔티티 설정

* feat: 엔티티 기본 구성 구현
  • Loading branch information
gengminy committed Nov 30, 2023
1 parent 4ef0c83 commit 2f26b5a
Show file tree
Hide file tree
Showing 22 changed files with 804 additions and 16 deletions.
14 changes: 14 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
FROM openjdk:17-alpine

EXPOSE 8080

ARG PROFILE=develop
ENV PROFILE=${PROFILE}
ENV TZ "Asia/Seoul"
ENV JAVA_OPTS="-Dspring.profiles.active=$PROFILE"

WORKDIR /app
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY ./build/libs/*.jar app.jar

ENTRYPOINT java $JAVA_OPTS -jar app.jar
12 changes: 12 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'org.springframework.boot' version '3.2.0'
id 'io.spring.dependency-management' version '1.1.4'
id 'com.diffplug.spotless' version '6.11.0'
}

group = 'com.testcar'
Expand Down Expand Up @@ -55,3 +56,14 @@ dependencies {
tasks.named('test') {
useJUnitPlatform()
}

spotless {
java {
target("**/*.java")
googleJavaFormat().aosp()
importOrder()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/testcar/car/CarApplication.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.testcar.car;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
Expand All @@ -8,8 +9,7 @@
@EnableJpaRepositories
public class CarApplication {

public static void main(String[] args) {
SpringApplication.run(CarApplication.class, args);
}

public static void main(String[] args) {
SpringApplication.run(CarApplication.class, args);
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/testcar/car/common/entity/BaseEntity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.testcar.car.common.entity;


import jakarta.persistence.Column;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.MappedSuperclass;
import java.time.LocalDateTime;
import lombok.Getter;
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/com/testcar/car/domains/car/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.testcar.car.domains.car;


import com.testcar.car.common.entity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "Car")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Car extends BaseEntity {
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// 차량명
@Column(length = 50, nullable = false)
private String name;

// 출시일자
@Column(nullable = false)
private LocalDateTime releasedAt;

// 차종
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private Type type;

@Builder
public Car(String name, LocalDateTime releasedAt, Type type) {
this.name = name;
this.releasedAt = releasedAt;
this.type = type;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/testcar/car/domains/car/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.testcar.car.domains.car;


import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum Type {
SEDAN("세단"),
SUV("SUV"),
TRUCK("트럭"),
VAN("승합차");

private final String description;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.testcar.car.domains.carReservation;


import com.testcar.car.common.entity.BaseEntity;
import com.testcar.car.domains.carStock.CarStock;
import com.testcar.car.domains.member.Member;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
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 java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "CarReservation")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CarReservation extends BaseEntity {
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// 사용자
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "memberId", nullable = false)
private Member member;

// 차량재고
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "carStockId", nullable = false)
private CarStock carStock;

// 대여시각
@Column(nullable = false)
private LocalDateTime reservedAt;

// 대여상태
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private ReservationStatus status;

@Builder
public CarReservation(
Member member, CarStock carStock, LocalDateTime reservedAt, ReservationStatus status) {
this.member = member;
this.carStock = carStock;
this.reservedAt = reservedAt;
this.status = status;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.testcar.car.domains.carReservation;


import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum ReservationStatus {
AVAILABLE("대여 가능"),
INSPECTION("검수중"),
RESERVED("대여중"),
UNAVAILABLE("폐기");

private final String description;
}
49 changes: 49 additions & 0 deletions src/main/java/com/testcar/car/domains/carStock/CarStock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package com.testcar.car.domains.carStock;


import com.testcar.car.common.entity.BaseEntity;
import com.testcar.car.domains.car.Car;
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.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "CarStock")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CarStock extends BaseEntity {
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// 차량
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "carId", nullable = false)
private Car car;

// 재고번호
@Column(nullable = false, length = 12, unique = true)
private String stockNumber;

// 재고상태
@Column(nullable = false)
private StockStatus status;

@Builder
public CarStock(Car car, String stockNumber, StockStatus status) {
this.car = car;
this.stockNumber = stockNumber;
this.status = status;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/testcar/car/domains/carStock/StockStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.testcar.car.domains.carStock;


import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum StockStatus {
AVAILABLE("대여 가능"),
INSPECTION("검수중"),
RESERVED("대여중"),
UNAVAILABLE("폐기");

private final String description;
}
75 changes: 75 additions & 0 deletions src/main/java/com/testcar/car/domains/carTest/CarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.testcar.car.domains.carTest;


import com.testcar.car.common.entity.BaseEntity;
import com.testcar.car.domains.carStock.CarStock;
import com.testcar.car.domains.member.Member;
import com.testcar.car.domains.track.Track;
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 java.time.LocalDateTime;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "CarTest")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class CarTest extends BaseEntity {
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// 사용자
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "memberId", nullable = false)
private Member member;

// 시험장
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "trackId", nullable = false)
private Track track;

// 차량재고
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "carStockId", nullable = false)
private CarStock carStock;

// 수행시간
@Column(nullable = false)
private LocalDateTime performedAt;

// 수행결과
@Column(nullable = false, columnDefinition = "TEXT")
private String result;

// 비고
@Column(columnDefinition = "TEXT")
private String memo;

@Builder
public CarTest(
Member member,
Track track,
CarStock carStock,
LocalDateTime performedAt,
String result,
String memo) {
this.member = member;
this.track = track;
this.carStock = carStock;
this.performedAt = performedAt;
this.result = result;
this.memo = memo;
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/testcar/car/domains/gasStation/GasStation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.testcar.car.domains.gasStation;


import com.testcar.car.common.entity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "GasStation")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class GasStation extends BaseEntity {
@Id
@Column(name = "id", nullable = false, updatable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

// 이름
@Column(nullable = false, length = 50)
private String name;

@Builder
public GasStation(String name) {
this.name = name;
}
}
Loading

0 comments on commit 2f26b5a

Please sign in to comment.