Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import com.example.Jinus.dto.request.RequestDto;
import com.example.Jinus.service.v2.cafeteria.CafeteriaServiceV2;
import com.example.Jinus.service.v2.userInfo.UserServiceV2;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
Comment on lines +6 to +9
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused imports

The imports for JsonProcessingException, ObjectMapper, and Autowired are added but not used in this controller. Unlike other controllers, no ObjectMapper field is injected here.

This creates inconsistency with other controllers and clutters the code.

- import com.fasterxml.jackson.core.JsonProcessingException;
- import com.fasterxml.jackson.databind.ObjectMapper;
 import lombok.RequiredArgsConstructor;
- import org.springframework.beans.factory.annotation.Autowired;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import lombok.RequiredArgsConstructor;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -27,5 +30,4 @@ public String responseCafeteriaOrCampusListCard(@RequestBody RequestDto requestD

return cafeteriaServiceV2.campusOrCafeteria(userCampusId, sysCampusId);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.example.Jinus.dto.request.RequestDto;
import com.example.Jinus.service.v2.cafeteria.DietServiceV2;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -14,6 +16,9 @@
public class DietControllerV2 {
private final DietServiceV2 dietServiceV2;

@Autowired
private ObjectMapper objectMapper;

Comment on lines +19 to +21
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused ObjectMapper and consider consistent DI style

The injected ObjectMapper is never used in this class, making it unnecessary. Additionally, the class mixes constructor injection (via @requiredargsconstructor) with field injection (@Autowired), which is inconsistent.

Spring best practices generally recommend constructor injection for required dependencies.

If the ObjectMapper is intended for future use, consider:

- @Autowired
- private ObjectMapper objectMapper;

If it will be needed later, add it through constructor injection instead:

private final ObjectMapper objectMapper;

// Update the class to use @AllArgsConstructor instead of @RequiredArgsConstructor
// or create an explicit constructor

@PostMapping("/v2/dish")
public String handleRequest(@RequestBody RequestDto requestDto) {
return dietServiceV2.requestHandler(requestDto);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.example.Jinus.controller.v2;

import com.example.Jinus.dto.request.RequestDto;
import com.example.Jinus.service.v2.notice.CategoryServiceV2;
import com.example.Jinus.service.v2.notice.NoticeServiceV2;
import com.example.Jinus.service.v2.userInfo.DepartmentServiceV2;
import com.example.Jinus.service.v2.userInfo.UserServiceV2;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -19,6 +20,8 @@ public class NoticeControllerV2 {
private final NoticeServiceV2 noticeServiceV2;
private final DepartmentServiceV2 departmentServiceV2;
private final UserServiceV2 userServiceV2;
@Autowired
private ObjectMapper objectMapper;
Comment on lines +23 to +24
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Remove unused ObjectMapper and consider consistent DI style

The injected ObjectMapper is never used in this class, making it unnecessary. Additionally, the class mixes constructor injection (via @requiredargsconstructor) with field injection (@Autowired), which is inconsistent.

Spring best practices generally recommend constructor injection for required dependencies.

If the ObjectMapper is intended for future use, consider:

- @Autowired
- private ObjectMapper objectMapper;

If it will be needed later, add it through constructor injection instead:

private final ObjectMapper objectMapper;

// Update the class to use @AllArgsConstructor instead of @RequiredArgsConstructor
// or create an explicit constructor


// 학교 공지사항 조회
@PostMapping("/v2/main-notice")
Expand All @@ -32,6 +35,7 @@ public String getMainNotice() {
@PostMapping("/v2/department-notice")
public String responseDepartmentNotice(@RequestBody RequestDto requestDto) {
String userId = requestDto.getUserRequest().getUser().getId();

int departmentId = userServiceV2.getUserDepartmentId(userId);
// 학과 영문명 찾기
String departmentEng = departmentServiceV2.getDepartmentEng(departmentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class CacheServiceV2 {
private final DietRepositoryV2 dietRepositoryV2;
private final CafeteriaRepositoryV2 cafeteriaRepositoryV2;

@Cacheable(
value = "dietList",
key = "#parameters.dietDate + '::' + #parameters.period + '::' + #cafeteriaId",
unless = "#result == null || #result.isEmpty()",
cacheManager = "contentCacheManager"
)
// @Cacheable(
// value = "dietList",
// key = "#parameters?.dietDate?.toString() + '::' + #parameters?.period + '::' + #cafeteriaId",
// unless = "#result == null || #result.isEmpty()",
// cacheManager = "contentCacheManager"
// )
// 식단 데이터 가져오기
public List<DietDto> getDietList(HandleRequestDto parameters, int cafeteriaId) {
// 오늘, 내일 문자열로 날짜 설정하기
Expand All @@ -34,7 +34,7 @@ public List<DietDto> getDietList(HandleRequestDto parameters, int cafeteriaId) {


// Redis에서 조회 (없으면 DB에서 가져옴)
@Cacheable(value = "cafeteriaList", key = "#campusId", cacheManager = "contentCacheManager")
// @Cacheable(value = "cafeteriaList", key = "#campusId", cacheManager = "contentCacheManager")
public List<CafeteriaDto> getCafeteriaList(int campusId) {
return cafeteriaRepositoryV2.findCafeteriaListByCampusId(campusId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
public class DietServiceV2 {

private final CampusServiceV2 campusServiceV2;
private final CafeteriaQueryServiceV2 queryServiceV2;
private final DietParameterServiceV2 parameterServiceV2;
private final CafeteriaQueryServiceV2 cafeteriaQueryServiceV2;
private final DietParameterServiceV2 dietParameterServiceV2;
private final DietResponseServiceV2 dietResponseServiceV2;
private final DietQueryServiceV2 dietQueryServiceV2;

Expand All @@ -31,15 +31,15 @@ public String requestHandler(RequestDto requestDto) {
// 현재 시간 파악
LocalTime time = getCurrentTime();
// 사용자 발화에서 파라미터 추출 및 객체 생성
HandleRequestDto parameters = parameterServiceV2.setParameters(kakaoId, time, requestDto);
HandleRequestDto parameters = dietParameterServiceV2.setParameters(kakaoId, time, requestDto);

return checkIsCafeteriaInCampus(parameters);
}

// 식당 존재 여부에 따른 메뉴 조회 로직
private String checkIsCafeteriaInCampus(HandleRequestDto parameters) {
int campusId = campusServiceV2.getCampusId(parameters.getCampusName());
int cafeteriaId = queryServiceV2.getCafeteriaId(parameters.getCafeteriaName(), campusId);
int cafeteriaId = cafeteriaQueryServiceV2.getCafeteriaId(parameters.getCafeteriaName(), campusId);

// 캠퍼스에 식당이 존재하지 않는 경우
if (cafeteriaId == -1) {
Expand All @@ -54,7 +54,7 @@ private String checkIsCafeteriaInCampus(HandleRequestDto parameters) {
// 응답 내용 생성
private String makeContents(HandleRequestDto parameters, int cafeteriaId, String diets) {
// 식당 img 찾기
String imgUrl = queryServiceV2.getImgUrl(cafeteriaId);
String imgUrl = cafeteriaQueryServiceV2.getImgUrl(cafeteriaId);

// title 데이터 연결
String title = "\uD83C\uDF71 " +
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/example/Jinus/utility/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
private static final ObjectMapper objectMapper = new ObjectMapper();
public static final ObjectMapper objectMapper = new ObjectMapper();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider the implications of exposing ObjectMapper as public

Changing the visibility of the ObjectMapper from private to public exposes it for external modification and direct access. While this enables reuse across controllers, it introduces risks:

  1. External code could modify its configuration, leading to inconsistent behavior
  2. It creates two ways to handle JSON: via the utility method and direct access
  3. The static instance may have thread-safety concerns in certain scenarios

Consider whether the direct access is necessary, or if all JSON processing could be encapsulated through methods in JsonUtils.

If direct access is required, consider:

- public static final ObjectMapper objectMapper = new ObjectMapper();
+ // Create an immutable public instance with defense against modification
+ public static final ObjectMapper OBJECT_MAPPER = createObjectMapper();
+
+ private static ObjectMapper createObjectMapper() {
+     ObjectMapper mapper = new ObjectMapper();
+     mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
+     return mapper;
+ }

And remove the static block since initialization would happen in the createObjectMapper method.


static {
// null 값 무시 설정
Expand Down
Loading