Skip to content

Commit

Permalink
Merge pull request #64 from kakao-tech-campus-2nd-step3/develop
Browse files Browse the repository at this point in the history
deploy: 9주차 작업 내용 배포
  • Loading branch information
5win authored Nov 1, 2024
2 parents 3998124 + 0567956 commit dc7038b
Show file tree
Hide file tree
Showing 25 changed files with 1,203 additions and 31 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ nb-configuration.xml
## Miscellaneous
##############################
*.log

##############################
## Production
##############################
src/main/resources/application-prod-db.yml
src/main/resources/application-jwt.yml
4 changes: 3 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repositories {
}

dependencies {
implementation 'com.opencsv:opencsv:5.5.2'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'

Expand All @@ -38,6 +39,7 @@ dependencies {
runtimeOnly 'io.jsonwebtoken:jjwt-impl:0.12.6'
runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.12.6'

implementation 'com.mysql:mysql-connector-j:9.1.0'
compileOnly 'org.projectlombok:lombok'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
Expand All @@ -48,4 +50,4 @@ dependencies {

tasks.named('test') {
useJUnitPlatform()
}
}
9 changes: 6 additions & 3 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ APP_NAME=gamsa
cd $REPOSITORY

echo "> 현재 구동 중인 애플리케이션 pid 확인"
CURRENT_PID=$(pgrep -f ${APP_NAME}-*.jar)
CURRENT_PID=$(lsof -i :8080 -t)

echo "> 현재 구동 중인 애플리케이션 pid: $CURRENT_PID"
if [ -z "$CURRENT_PID" ]; then
Expand All @@ -18,12 +18,15 @@ else
fi

echo "> 새 애플리케이션 배포"
JAR_NAME=$(ls -tr $REPOSITORY/ | grep jar | tail -n 1)
JAR_NAME=$(ls -tr $REPOSITORY/ | grep jar | head -n 1)

echo "> JAR Name: $JAR_NAME"

echo "> $JAR_NAME에 실행권한 추가"
chmod +x $JAR_NAME

echo "> $JAR_NAME 실행"
nohup java -jar $REPOSITORY/$JAR_NAME --spring.profiles.active=prod 2>&1 &
nohup java -jar \
-Dspring.config.location=/home/ubuntu/prod/application-prod-db.yml,/home/ubuntu/prod/application-jwt.yml \
-Dspring.profiles.active=prod \
$REPOSITORY/$JAR_NAME 2>&1 &
4 changes: 2 additions & 2 deletions src/main/java/com/gamsa/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.scheduling.annotation.EnableScheduling;

@ConfigurationPropertiesScan
@EnableJpaAuditing
@EnableScheduling
@SpringBootApplication
public class Application {

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

}
4 changes: 4 additions & 0 deletions src/main/java/com/gamsa/activity/domain/District.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import lombok.Builder;
import lombok.Getter;

import java.math.BigDecimal;

@Getter
@Builder
public class District {
Expand All @@ -11,5 +13,7 @@ public class District {
private int sidoCode;
private String sidoName;
private String gunguName;
private BigDecimal latitude;
private BigDecimal longitude;
private boolean sido;
}
62 changes: 62 additions & 0 deletions src/main/java/com/gamsa/activity/dto/ActivityApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.gamsa.activity.dto;

import com.gamsa.activity.constant.Category;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.time.LocalDateTime;

@Getter
@Builder
@RequiredArgsConstructor
public class ActivityApiResponse {

private final Long actId;
private final String actTitle;
private final String actLocation;
private final String description;
private final LocalDateTime noticeStartDate;
private final LocalDateTime noticeEndDate;
private final LocalDateTime actStartDate;
private final LocalDateTime actEndDate;
private final int actStartTime;
private final int actEndTime;
private final int recruitTotalNum;
private final boolean adultPossible;
private final boolean teenPossible;
private final boolean groupPossible;
private final int actWeek;
private final String actManager;
private final String actPhone;
private final String url;
private final Category category;
private final String instituteName;
private final Integer sidoGunguCode;

public ActivitySaveRequest toSaveRequest(long instituteId) {
return ActivitySaveRequest.builder()
.actId(actId)
.actTitle(actTitle)
.actLocation(actLocation)
.description(description)
.noticeStartDate(noticeStartDate)
.noticeEndDate(noticeEndDate)
.actStartDate(actStartDate)
.actEndDate(actEndDate)
.actStartTime(actStartTime)
.actEndTime(actEndTime)
.recruitTotalNum(recruitTotalNum)
.adultPossible(adultPossible)
.teenPossible(teenPossible)
.groupPossible(groupPossible)
.actWeek(actWeek)
.actManager(actManager)
.actPhone(actPhone)
.url(url)
.category(category)
.instituteId(instituteId)
.sidoGunguCode(sidoGunguCode)
.build();
}
}
21 changes: 14 additions & 7 deletions src/main/java/com/gamsa/activity/dto/DistrictSaveRequest.java
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package com.gamsa.activity.dto;

import com.gamsa.activity.domain.District;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;

@Getter
@Builder
@RequiredArgsConstructor
@AllArgsConstructor
public class DistrictSaveRequest {

private final int sidoGunguCode;
private final int sidoCode;
private final String sidoName;
private final String gunguName;
private BigDecimal latitude;
private BigDecimal longitude;
private final boolean sido;

public District toModel() {
return District.builder()
.sidoGunguCode(sidoGunguCode)
.sidoCode(sidoCode)
.sidoName(sidoName)
.gunguName(gunguName)
.sido(sido)
.build();
.sidoGunguCode(sidoGunguCode)
.sidoCode(sidoCode)
.sidoName(sidoName)
.gunguName(gunguName)
.latitude(latitude)
.longitude(longitude)
.sido(sido)
.build();
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/gamsa/activity/dto/InstituteApiResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.gamsa.activity.dto;

import com.gamsa.activity.domain.District;
import com.gamsa.activity.domain.Institute;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.math.BigDecimal;
import java.util.Map;

@Getter
@Builder
@AllArgsConstructor
public class InstituteApiResponse {

private String name;
private String location;
private int sidoCode;
private int sidoGunguCode;
private String phone;

public InstituteSaveRequest toSaveRequest(Map<String, BigDecimal> coordinates) {
return InstituteSaveRequest.builder()
.name(name)
.location(location)
.sidoCode(sidoCode)
.sidoGunguCode(sidoGunguCode)
.longitude(coordinates.get("longitude"))
.latitude(coordinates.get("latitude"))
.phone(phone)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.math.BigDecimal;
import lombok.Builder;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@Builder
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/com/gamsa/activity/entity/DistrictJpaEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.*;

import java.math.BigDecimal;

@Getter
@Builder
Expand All @@ -27,6 +25,12 @@ public class DistrictJpaEntity extends BaseEntity {
@Column(name = "sido_code", nullable = false)
private int sidoCode;

@Column(name = "latitude")
private BigDecimal latitude;

@Column(name = "longitude")
private BigDecimal longitude;

@Column(name = "sido_name", length = 15, nullable = false)
private String sidoName;

Expand All @@ -38,21 +42,21 @@ public class DistrictJpaEntity extends BaseEntity {

public static DistrictJpaEntity from(District district) {
return DistrictJpaEntity.builder()
.sidoGunguCode(district.getSidoGunguCode())
.sidoCode(district.getSidoCode())
.sidoName(district.getSidoName())
.gunguName(district.getGunguName())
.sido(district.isSido())
.build();
.sidoGunguCode(district.getSidoGunguCode())
.sidoCode(district.getSidoCode())
.sidoName(district.getSidoName())
.gunguName(district.getGunguName())
.sido(district.isSido())
.build();
}

public District toModel() {
return District.builder()
.sidoGunguCode(getSidoGunguCode())
.sidoCode(getSidoCode())
.sidoName(getSidoName())
.gunguName(getGunguName())
.sido(isSido())
.build();
.sidoGunguCode(getSidoGunguCode())
.sidoCode(getSidoCode())
.sidoName(getSidoName())
.gunguName(getGunguName())
.sido(isSido())
.build();
}
}
15 changes: 14 additions & 1 deletion src/main/java/com/gamsa/activity/service/DistrictService.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.gamsa.activity.service;

import com.gamsa.activity.constant.ActivityErrorCode;
import com.gamsa.activity.domain.District;
import com.gamsa.activity.dto.DistrictFindAllResponse;
import com.gamsa.activity.dto.DistrictSaveRequest;
import com.gamsa.activity.exception.ActivityException;
import com.gamsa.activity.repository.DistrictRepository;
import java.util.List;

import java.math.BigDecimal;
import java.util.*;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand Down Expand Up @@ -44,4 +48,13 @@ public List<DistrictFindAllResponse> findAllGungu() {
.map(DistrictFindAllResponse::from)
.toList();
}

public Map<String, BigDecimal> findCoordinates(int gunguCode) {
District find = districtRepository.findBySidoGunguCode(gunguCode)
.orElseThrow(NoSuchElementException::new);
Map<String, BigDecimal> coordinates = new HashMap<>();
coordinates.put("longitude", find.getLongitude());
coordinates.put("latitude", find.getLatitude());
return coordinates;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public void save(InstituteSaveRequest saveRequest) {

instituteRepository.save(saveRequest.toModel(district));
}

public Long findByName(String name) {
return instituteRepository.findByName(name).orElseThrow(() -> new ActivityException(ActivityErrorCode.INSTITUTE_NOT_EXISTS)).getInstituteId();
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/gamsa/dataupdate/DataUpdateErrorCode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.gamsa.dataupdate;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public enum DataUpdateErrorCode {
// 1365 API 오류
OPENAPI_NOT_RESPOND(504, "Open API가 응답하지 않습니다."),
OPENAPI_ERROR(504, "Open API의 반환 값을 처리할 수 없습니다."),


// 카카오 API 오류
KAKAOLOCALAPI_NOT_RESPOND(504, "카카오 API가 정상적으로 응답하지 않습니다."),
KAKAOLOCALAPT_ERROR(504, "카카오 API의 반환 값을 처리할 수 없습니다."),

// 내부 처리 오류
INVALID_CSV(500, "주어진 CSV 파일을 처리할 수 없습니다"),
INVALID_FILE_SOURCE(500, "주어진 파일 경로가 올바르지 않습니다.");


private final int ststus;
private final String msg;
}
10 changes: 10 additions & 0 deletions src/main/java/com/gamsa/dataupdate/DataUpdateException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.gamsa.dataupdate;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class DataUpdateException extends RuntimeException {
private final DataUpdateErrorCode errorCode;
}
Loading

0 comments on commit dc7038b

Please sign in to comment.