Skip to content

Commit 2ca3bdc

Browse files
authored
Merge pull request #26 from nerdinary-hackathon-8th/feature/consumption-rate
Feature/consumption rate
2 parents 3c6c9e4 + ff18a5c commit 2ca3bdc

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

hackathon/src/main/java/nerdinary/hackathon/domain/rate/controller/RateController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package nerdinary.hackathon.domain.rate.controller;
22

33
import io.swagger.v3.oas.annotations.Operation;
4+
import io.swagger.v3.oas.annotations.Parameter;
45
import io.swagger.v3.oas.annotations.responses.ApiResponse;
56
import io.swagger.v3.oas.annotations.responses.ApiResponses;
67
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -22,7 +23,7 @@ public class RateController {
2223
private final RateService rateService;
2324

2425
@Operation(
25-
summary = "냉장고 소비율 및 BTI 분석 결과 조회",
26+
summary = "MBTI 분석 결과 조회",
2627
description = "사용자의 냉장고 소비율, 유통기한 임박 식품 개수, 레벨, BTI 정보 등을 조회합니다."
2728
)
2829
@ApiResponses(value = {
@@ -31,7 +32,9 @@ public class RateController {
3132
@ApiResponse(responseCode = "500", description = "서버 오류")
3233
})
3334
@GetMapping("/rate")
34-
public ResponseEntity<RateResponse> getRate(@JwtValidation Long userId) {
35+
public ResponseEntity<RateResponse> getRate(
36+
@Parameter(hidden = true)
37+
@JwtValidation Long userId) {
3538
RateResponse response = rateService.calculateUserRate(userId);
3639
return ResponseEntity.ok(response);
3740
}

hackathon/src/main/java/nerdinary/hackathon/domain/rate/rateService/RateService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
import nerdinary.hackathon.domain.login.service.UserException;
1212
import nerdinary.hackathon.domain.user.User;
1313
import nerdinary.hackathon.domain.user.UserRepository;
14+
import org.springframework.core.io.ClassPathResource;
1415
import org.springframework.stereotype.Component;
1516
import java.io.File;
17+
import java.io.InputStream;
1618
import java.time.LocalDate;
1719
import java.util.List;
1820
import java.util.Map;
21+
import org.springframework.core.io.Resource;
1922

2023
@Component
2124
@RequiredArgsConstructor
@@ -32,16 +35,18 @@ public class RateService {
3235
public void init() {
3336
try {
3437
ObjectMapper mapper = new ObjectMapper();
35-
File file = new File("./rateJson/rate-date.json"); // 현재 작업 디렉토리 기준
3638

37-
rateDataList = mapper.readValue(file, new TypeReference<>() {});
39+
// ClassPathResource를 사용해서 resources 폴더 내부 파일 읽기
40+
Resource resource = new ClassPathResource("rateJson/rate-date.json");
41+
InputStream inputStream = resource.getInputStream();
42+
43+
rateDataList = mapper.readValue(inputStream, new TypeReference<>() {});
3844
System.out.println("rate-data.json 로드 완료!");
3945
} catch (Exception e) {
4046
throw new RuntimeException("rate-data.json 파일 로드 실패", e);
4147
}
4248
}
4349

44-
4550
public RateResponse calculateUserRate(Long userId) {
4651
User user = userRepository.findById(userId)
4752
.orElseThrow(() -> new UserException(USER_NOT_FOUND));

hackathon/src/main/java/nerdinary/hackathon/domain/rate/rateService/rateJson/rate-date.json renamed to hackathon/src/main/resources/rateJson/rate-date.json

File renamed without changes.

0 commit comments

Comments
 (0)