Skip to content

Commit

Permalink
컨테이너로 동작할 수 있게 설정 (#44)
Browse files Browse the repository at this point in the history
* feat: flyway 추가

* refactor: 환경 변수로 값 지정할 수 있게 yml 변경

* build: CD에서 jar로 이미지 만들 수 있게 도커파일 추가

* refactor: 직접 참조 간접 참조로 변경

* refactor: 매 정각, 30분 마다 api 호출하도록 변경
  • Loading branch information
This2sho authored Mar 16, 2024
1 parent 26d334e commit 8f22cdc
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 73 deletions.
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM amazoncorretto:17-alpine

COPY build/libs/parking-0.0.1-SNAPSHOT.jar app.jar

CMD ["java", "-jar", "app.jar"]
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ dependencies {
testImplementation "org.testcontainers:junit-jupiter:1.19.6"
testImplementation "com.redis:testcontainers-redis:2.2.0"
testImplementation "org.testcontainers:mysql:1.19.6"

// flyway 추가
implementation 'org.flywaydb:flyway-mysql'
implementation 'org.flywaydb:flyway-core'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
package com.example.parking.application.searchcondition;

import com.example.parking.application.searchcondition.dto.SearchConditionDto;
import com.example.parking.domain.member.Member;
import com.example.parking.domain.member.MemberRepository;
import com.example.parking.domain.parking.OperationType;
import com.example.parking.domain.parking.ParkingType;
import com.example.parking.domain.parking.PayType;
import com.example.parking.domain.searchcondition.SearchConditionAvailable;
import com.example.parking.domain.searchcondition.FeeType;
import com.example.parking.domain.searchcondition.Hours;
import com.example.parking.domain.searchcondition.Priority;
import com.example.parking.domain.searchcondition.SearchCondition;
import com.example.parking.domain.searchcondition.SearchConditionAvailable;
import com.example.parking.domain.searchcondition.SearchConditionRepository;
import com.example.parking.support.Association;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -23,7 +22,6 @@
public class SearchConditionService {

private final SearchConditionRepository searchConditionRepository;
private final MemberRepository memberRepository;

public SearchConditionDto findSearchCondition(Long memberId) {
SearchCondition searchCondition = searchConditionRepository.getByMemberId(memberId);
Expand Down Expand Up @@ -58,9 +56,8 @@ public void updateSearchCondition(Long memberId, SearchConditionDto searchCondit
}

private SearchCondition createSearchCondition(Long memberId, SearchConditionDto searchConditionDto) {
Member member = memberRepository.getById(memberId);
return new SearchCondition(
member,
Association.from(memberId),
toEnums(searchConditionDto.getOperationType(), OperationType.values()),
toEnums(searchConditionDto.getParkingType(), ParkingType.values()),
toEnums(searchConditionDto.getFeeType(), FeeType.values()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
import com.example.parking.infra.converter.OperationTypeConverter;
import com.example.parking.infra.converter.ParkingTypeConverter;
import com.example.parking.infra.converter.PayTypeConverter;
import com.example.parking.support.Association;
import jakarta.persistence.AttributeOverride;
import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Embedded;
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.OneToOne;
import java.util.List;
import lombok.AccessLevel;
import lombok.Getter;
Expand All @@ -29,49 +29,50 @@
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class SearchCondition {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn
private Member member;
@Embedded
@AttributeOverride(name = "id", column = @Column(name = "member_id"))
private Association<Member> memberId;

@Convert(converter = OperationTypeConverter.class)
private List<OperationType> operationTypes;
@Convert(converter = OperationTypeConverter.class)
private List<OperationType> operationTypes;

@Convert(converter = ParkingTypeConverter.class)
private List<ParkingType> parkingTypes;
@Convert(converter = ParkingTypeConverter.class)
private List<ParkingType> parkingTypes;

@Convert(converter = FeeTypeConverter.class)
private List<FeeType> feeTypes;
@Convert(converter = FeeTypeConverter.class)
private List<FeeType> feeTypes;

@Convert(converter = PayTypeConverter.class)
private List<PayType> payTypes;
@Convert(converter = PayTypeConverter.class)
private List<PayType> payTypes;

@Enumerated(EnumType.STRING)
private Priority priority;
@Enumerated(EnumType.STRING)
private Priority priority;

@Embedded
private Hours hours;
@Embedded
private Hours hours;

public SearchCondition(Member member, List<OperationType> operationTypes, List<ParkingType> parkingTypes,
List<FeeType> feeTypes, List<PayType> payTypes, Priority priority, Hours hours) {
this.member = member;
this.operationTypes = operationTypes;
this.parkingTypes = parkingTypes;
this.feeTypes = feeTypes;
this.payTypes = payTypes;
this.priority = priority;
this.hours = hours;
}
public SearchCondition(Association<Member> memberId, List<OperationType> operationTypes,
List<ParkingType> parkingTypes,
List<FeeType> feeTypes, List<PayType> payTypes, Priority priority, Hours hours) {
this.memberId = memberId;
this.operationTypes = operationTypes;
this.parkingTypes = parkingTypes;
this.feeTypes = feeTypes;
this.payTypes = payTypes;
this.priority = priority;
this.hours = hours;
}

public void update(SearchCondition updated) {
this.operationTypes = updated.operationTypes;
this.parkingTypes = updated.parkingTypes;
this.feeTypes = updated.feeTypes;
this.payTypes = updated.payTypes;
this.priority = updated.priority;
this.hours = updated.hours;
}
public void update(SearchCondition updated) {
this.operationTypes = updated.operationTypes;
this.parkingTypes = updated.parkingTypes;
this.feeTypes = updated.feeTypes;
this.payTypes = updated.payTypes;
this.priority = updated.priority;
this.hours = updated.hours;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class ParkingUpdateScheduler {
private final CoordinateService coordinateService;
private final ParkingService parkingService;

@Scheduled(fixedRate = 30, timeUnit = TimeUnit.MINUTES)
@Scheduled(cron = "0 */30 * * * *")
public void autoUpdateOfferCurrentParking() {
Map<String, Parking> parkingLots = readBy(ParkingApiService::offerCurrentParking);
Map<String, Parking> saved = findAllByName(parkingLots.keySet());
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
spring:
# JPA
jpa:
hibernate:
ddl-auto: create
show-sql: true
properties:
hibernate:
format_sql: true
flyway:
enabled: false
22 changes: 22 additions & 0 deletions src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
spring:
# JPA
jpa:
hibernate:
ddl-auto: validate
database: mysql
open-in-view: false

# DB
datasource:
url: ${DB_URL}
username: ${DB_USERNAME}
password: ${DB_PASSWORD}
driver-class-name: com.mysql.cj.jdbc.Driver
# flyway
flyway:
enabled: true
url: ${DB_URL}
user: ${DB_USERNAME}
password: ${DB_PASSWORD}
baseline-on-migrate: true
locations: classpath:db/migration/mysql
40 changes: 15 additions & 25 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,31 @@
spring:
jpa:
hibernate:
ddl-auto: create
show-sql: true
properties:
hibernate:
format_sql: true
# mail
profiles:
active: ${PROFILE:dev}
# MAIL
mail:
host: smtp.gmail.com
port: 587
username: everythinginparking3@gmail.com
password: test
host: ${MAIL_HOST:smtp.gmail.com}
port: ${MAIL_PORT:587}
username: ${MAIL_USERNAME:mail@gmail.com}
password: ${MAIL_PASSWORD:password}
properties:
mail:
smtp:
auth: true
timeout: 5000
starttls:
enable: true
# redis
# REDIS
data:
redis:
host: localhost
port: 6379

# file
file:
dir: src/test/resources/static/images/
host: ${REDIS_HOST:localhost}
port: ${REDIS_PORT:6379}

# authcode
# AUTH CODE
authcode:
expired-time: 300


# key
# API KEY
kakao:
key: test
seoul-public-parking-key: test
pusan-public-parking-key: test
key: ${KAKAO_API_KEY:kakao}
seoul-public-parking-key: ${SEOUL_API_KEY:seoul}
pusan-public-parking-key: ${PUSAN_API_KEY:pusan}
88 changes: 88 additions & 0 deletions src/main/resources/db/migration/mysql/V1.0.0__initial_schema.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
-- favorite 테이블 생성
CREATE TABLE favorite (
id BIGINT NOT NULL AUTO_INCREMENT,
created_at TIMESTAMP,
updated_at TIMESTAMP,
member_id BIGINT,
parking_id BIGINT,
PRIMARY KEY (id),
UNIQUE (member_id, parking_id)
);

-- member 테이블 생성
CREATE TABLE member (
id BIGINT NOT NULL AUTO_INCREMENT,
deleted BOOLEAN,
email VARCHAR(255) UNIQUE,
name VARCHAR(255),
nickname VARCHAR(255),
password VARCHAR(255),
PRIMARY KEY (id)
);

-- member_session 테이블 생성
CREATE TABLE member_session (
session_id VARCHAR(255) NOT NULL,
created_at TIMESTAMP,
expired_at TIMESTAMP,
member_id BIGINT,
PRIMARY KEY (session_id)
);

-- parking 테이블 생성
CREATE TABLE parking (
id BIGINT NOT NULL AUTO_INCREMENT,
created_at TIMESTAMP,
updated_at TIMESTAMP,
base_fee INTEGER,
base_time_unit INTEGER,
capacity INTEGER,
current_parking INTEGER,
day_maximum_fee INTEGER,
extra_fee INTEGER,
extra_time_unit INTEGER,
holiday_begin_time TIME,
holiday_end_time TIME,
holiday_free_begin_time TIME,
holiday_free_end_time TIME,
latitude FLOAT NOT NULL,
longitude FLOAT NOT NULL,
saturday_begin_time TIME,
saturday_end_time TIME,
saturday_free_begin_time TIME,
saturday_free_end_time TIME,
weekday_begin_time TIME,
weekday_end_time TIME,
weekday_free_begin_time TIME,
weekday_free_end_time TIME,
address VARCHAR(255),
description VARCHAR(255),
name VARCHAR(255),
operation_type ENUM ('PUBLIC', 'PRIVATE', 'NO_INFO'),
parking_type ENUM ('OFF_STREET', 'ON_STREET', 'MECHANICAL', 'NO_INFO'),
tel VARCHAR(255),
PRIMARY KEY (id)
);

-- review 테이블 생성
CREATE TABLE review (
id BIGINT NOT NULL AUTO_INCREMENT,
created_at TIMESTAMP,
parking_id BIGINT,
reviewer_id BIGINT,
contents VARCHAR(255),
PRIMARY KEY (id)
);

-- search_condition 테이블 생성
CREATE TABLE search_condition (
id BIGINT NOT NULL AUTO_INCREMENT,
hours INTEGER NOT NULL,
member_id BIGINT,
fee_types VARCHAR(255),
operation_types VARCHAR(255),
parking_types VARCHAR(255),
pay_types VARCHAR(255),
priority ENUM ('DISTANCE', 'PRICE', 'RECOMMENDATION'),
PRIMARY KEY (id)
);
6 changes: 4 additions & 2 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
spring:
flyway:
enabled: false
jpa:
hibernate:
ddl-auto: create
Expand All @@ -9,7 +11,7 @@ spring:
mail:
host: smtp.gmail.com
port: 587
username: everythinginparking3@gmail.com
username: test@gmail.com
password: test
properties:
mail:
Expand All @@ -32,7 +34,7 @@ kakao:
key: test

seoul-public-parking-key: test
pusan-public-parking-key: test%2FbCRaddaK2FMoeVpVW2SqG%2B2cdn4Xdf1LpWru4O8opXbJc0wbbSdjXhQykcw2S8HmDuA%2BW3GiFFGDPgQ%3D%3D
pusan-public-parking-key: test

authcode:
expired-time: 60

0 comments on commit 8f22cdc

Please sign in to comment.