Skip to content

Commit

Permalink
Merge pull request #248 from hwangdaesun/feat/#246
Browse files Browse the repository at this point in the history
[BE/feat] Docker Volume과 log 파일 연동
  • Loading branch information
LJH098 committed May 21, 2024
2 parents 42c1a9a + 3563789 commit dc2ca04
Show file tree
Hide file tree
Showing 15 changed files with 921 additions and 799 deletions.
6 changes: 6 additions & 0 deletions BE/exceed/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ services:
- ENCRYPTION_ALGORITHM=${ENCRYPTION_ALGORITHM}
- SPRING_REDIS_HOST=gaebaljip-redis
- SPRING_REDIS_PORT=6379
volumes:
- type: volume
source: gaebaljip-log
target: /log
networks:
- gaebaljip-network
restart:
Expand Down Expand Up @@ -85,6 +89,8 @@ services:
volumes:
grafana-data:
prometheus-data:
gaebaljip-log:
external: true

networks:
gaebaljip-network:
1,582 changes: 791 additions & 791 deletions BE/exceed/food_data.csv

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.gaebaljip.exceed.common.data;

import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.food.adapter.out.FoodEntity;
import com.gaebaljip.exceed.food.application.port.out.FoodPort;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvException;

import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;

@Component
@Log4j2
@RequiredArgsConstructor
@ConditionalOnExpression("${ableAutoComplete:true}")
public class MariaDBAutoComplete implements ApplicationRunner {

private final FoodPort foodPort;

@Override
public void run(ApplicationArguments args) throws Exception {

// CSV 파일에서 식품명 열 데이터 로드
String csvPath = args.getSourceArgs()[0];
try (CSVReader reader =
new CSVReaderBuilder(new FileReader(csvPath))
.withSkipLines(1) // 첫 번째 행(헤더) 건너뛰기
.build()) {
List<String[]> allRows = reader.readAll();
List<FoodEntity> foodEntities =
allRows.stream()
.map(
row ->
FoodEntity.builder()
.calorie(Double.valueOf(row[1]))
.carbohydrate(Double.valueOf(row[2]))
.fat(Double.valueOf(row[3]))
.name(row[4])
.protein(Double.valueOf(row[5]))
.servingSize(Double.valueOf(row[6]))
.sugars(Double.valueOf(row[7]))
.dietaryFiber(Double.valueOf(row[8]))
.sodium(Double.valueOf(row[9]))
.build())
.toList();
foodPort.saveAll(foodEntities);
} catch (IOException | CsvException e) {
log.error("Failed to read CSV file: {}", e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gaebaljip.exceed.infrastructure.redis;
package com.gaebaljip.exceed.common.data;

import static com.gaebaljip.exceed.common.EatCeedStaticMessage.REDIS_AUTO_COMPLETE_KEY;

Expand All @@ -11,6 +11,7 @@
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.common.redis.RedisUtils;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
import com.opencsv.exceptions.CsvException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.gaebaljip.exceed.infrastructure.redis;
package com.gaebaljip.exceed.common.redis;

import java.util.Set;
import java.util.concurrent.TimeUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public Slice<Food> query(String lastFoodName, int size, String keyword) {
public FoodEntity command(FoodEntity foodEntity) {
return foodRepository.save(foodEntity);
}

@Override
public void saveAll(List<FoodEntity> foodEntities) {
foodRepository.saveAll(foodEntities);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import org.springframework.stereotype.Service;

import com.gaebaljip.exceed.common.EatCeedStaticMessage;
import com.gaebaljip.exceed.common.redis.RedisUtils;
import com.gaebaljip.exceed.dto.response.GetFoodsResponse;
import com.gaebaljip.exceed.dto.response.GetPageableFood;
import com.gaebaljip.exceed.food.application.port.in.GetFoodQuery;
import com.gaebaljip.exceed.food.application.port.out.FoodPort;
import com.gaebaljip.exceed.food.domain.Food;
import com.gaebaljip.exceed.infrastructure.redis.RedisUtils;

import lombok.RequiredArgsConstructor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public interface FoodPort {
Slice<Food> query(String lastFoodName, int size, String keyword);

FoodEntity command(FoodEntity foodEntity);

void saveAll(List<FoodEntity> foodEntities);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gaebaljip.exceed.health;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gaebaljip.exceed.common.ApiResponse;
import com.gaebaljip.exceed.common.ApiResponseGenerator;

@RestController
@RequestMapping("/api")
public class HealthController {
@GetMapping("/health")
public ApiResponse<ApiResponse.CustomBody<Void>> health() {
return ApiResponseGenerator.success(HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import org.springframework.stereotype.Component;

import com.gaebaljip.exceed.infrastructure.redis.RedisUtils;
import com.gaebaljip.exceed.common.redis.RedisUtils;
import com.gaebaljip.exceed.member.application.port.out.TimeOutPort;

import lombok.RequiredArgsConstructor;
Expand Down
7 changes: 7 additions & 0 deletions BE/exceed/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,10 @@ management:
include: "*"
exclude: "env, beans"

logging:
level:
org:
hibernate:
type:
descriptor:
sql: trace
7 changes: 7 additions & 0 deletions BE/exceed/src/main/resources/application-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,10 @@ management:
include: "*"
exclude: "env, beans"

logging:
level:
org:
hibernate:
type:
descriptor:
sql: trace
10 changes: 9 additions & 1 deletion BE/exceed/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@ encryption:
jwt:
secret: ${JWT_SECRET}

ableAutoComplete: true
ableAutoComplete: true

logging:
level:
org:
hibernate:
type:
descriptor:
sql: trace
10 changes: 9 additions & 1 deletion BE/exceed/src/main/resources/application-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,12 @@ logging.level:
jwt:
secret: secretKeydlqslekdsecretKeydlqslekdsecretKeydlqslekdsecretKeydlqslekdsecretKeydlqslekdsecretKeydlqslekdse

ableAutoComplete: false
ableAutoComplete: false

logging:
level:
org:
hibernate:
type:
descriptor:
sql: trace
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
//
// import com.gaebaljip.exceed.common.EatCeedStaticMessage;
// import com.gaebaljip.exceed.common.IntegrationTest;
// import com.gaebaljip.exceed.infrastructure.redis.RedisAutoComplete;
// import com.gaebaljip.exceed.infrastructure.redis.RedisUtils;
// import com.gaebaljip.exceed.common.data.RedisAutoComplete;
// import com.gaebaljip.exceed.common.redis.RedisUtils;
//
// import lombok.extern.log4j.Log4j2;
//
Expand Down

0 comments on commit dc2ca04

Please sign in to comment.