Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nerdinary.hackathon.domain.rate.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -22,7 +23,7 @@ public class RateController {
private final RateService rateService;

@Operation(
summary = "냉장고 소비율 및 BTI 분석 결과 조회",
summary = "MBTI 분석 결과 조회",
description = "사용자의 냉장고 소비율, 유통기한 임박 식품 개수, 레벨, BTI 정보 등을 조회합니다."
)
@ApiResponses(value = {
Expand All @@ -31,7 +32,9 @@ public class RateController {
@ApiResponse(responseCode = "500", description = "서버 오류")
})
@GetMapping("/rate")
public ResponseEntity<RateResponse> getRate(@JwtValidation Long userId) {
public ResponseEntity<RateResponse> getRate(
@Parameter(hidden = true)
@JwtValidation Long userId) {
RateResponse response = rateService.calculateUserRate(userId);
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import nerdinary.hackathon.domain.login.service.UserException;
import nerdinary.hackathon.domain.user.User;
import nerdinary.hackathon.domain.user.UserRepository;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.InputStream;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import org.springframework.core.io.Resource;

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

rateDataList = mapper.readValue(file, new TypeReference<>() {});
// ClassPathResource를 사용해서 resources 폴더 내부 파일 읽기
Resource resource = new ClassPathResource("rateJson/rate-date.json");
InputStream inputStream = resource.getInputStream();

rateDataList = mapper.readValue(inputStream, new TypeReference<>() {});
System.out.println("rate-data.json 로드 완료!");
} catch (Exception e) {
throw new RuntimeException("rate-data.json 파일 로드 실패", e);
}
}


public RateResponse calculateUserRate(Long userId) {
User user = userRepository.findById(userId)
.orElseThrow(() -> new UserException(USER_NOT_FOUND));
Expand Down