Skip to content

Commit dd851d2

Browse files
committed
[Refactor]CampusServiceV2 클래스 분리
1 parent 0c7cd50 commit dd851d2

File tree

3 files changed

+50
-112
lines changed

3 files changed

+50
-112
lines changed

src/main/java/com/example/Jinus/service/v2/cafeteria/CafeteriaServiceV2.java

Lines changed: 3 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@
1111
public class CafeteriaServiceV2 {
1212

1313
private final CampusServiceV2 campusServiceV2;
14+
private final CampusResponseServiceV2 campusResponseServiceV2;
1415
private final CacheServiceV2 cacheServiceV2;
1516
private final CafeteriaResponseServiceV2 cafeteriaResponseServiceV2;
1617

1718
// 사용자가 선택한 블록 ID값에 따라 반환 조건 설정
1819
// campusId가 -1이면 사용자 정보가 존재하지 않는 경우임
1920
public String campusOrCafeteria(int userCampusId, int sysCampusId) {
2021
if (sysCampusId == -1) { // 더보기 버튼 누른 경우 -> 캠퍼스 리스트 반환
21-
return campusServiceV2.makeCampusListCard();
22+
return campusResponseServiceV2.makeCampusListCard();
2223
}
2324
// 사용자가 캠퍼스를 선택한 경우
2425
int targetCampusId = (sysCampusId > 0) ? sysCampusId : userCampusId;
2526
return (targetCampusId != -1) // 사용자 정보 DB 존재 여부
2627
? returnCafeteriaListCard(targetCampusId) // 존재 O -> 식당 정보 반환
27-
: campusServiceV2.makeCampusListCard(); // 존재 X -> 캠퍼스 정보 반환
28+
: campusResponseServiceV2.makeCampusListCard(); // 존재 X -> 캠퍼스 정보 반환
2829
}
2930

3031
// 식당 리스트 반환
@@ -33,79 +34,4 @@ private String returnCafeteriaListCard(int campusId) {
3334
List<CafeteriaDto> cafeteriaList = cacheServiceV2.getCafeteriaList(campusId);
3435
return cafeteriaResponseServiceV2.createCafeteriaListCard(campusName, cafeteriaList);
3536
}
36-
37-
// // 반환 조건 설정
38-
// public String campusOrCafeteria(int campusId, int sysCampusId) {
39-
// // 더보기 버튼 누른 경우
40-
// if (sysCampusId == -1) {
41-
// return campusServiceV2.makeCampusListCard();
42-
// }
43-
//
44-
// // 사용자가 원하는 캠퍼스가 있을 때
45-
// if (sysCampusId > 0) {
46-
// return makeCafeteriaListCard(sysCampusId);
47-
// }
48-
//
49-
// // 사용자가 원하는 캠퍼스가 없을 때
50-
// return (campusId != -1) // 사용자 존재 여부
51-
// ? makeCafeteriaListCard(campusId)
52-
// : campusServiceV2.makeCampusListCard();
53-
// }
54-
//
55-
// // 식당 리스트 반환 메소드
56-
// private String makeCafeteriaListCard(int campusId) {
57-
// String campusName = campusServiceV2.getUserCampusName(campusId);
58-
// List<CafeteriaDto> cafeteriaList = cacheServiceV2.getCafeteriaList(campusId);
59-
//
60-
// // 식당 리스트 객체 생성
61-
// List<ListItemDto> listItems = mappingCafeteriaList(campusName, cafeteriaList);
62-
// // response 객체 생성
63-
// ResponseDto responseDto = ListCardResponse.mappingResponseDto("어떤 교내 식당 정보가 알고싶어 ?", listItems, mappingButtonDto());
64-
//
65-
// return JsonUtils.toJsonResponse(responseDto);
66-
// }
67-
//
68-
//
69-
// // 식당 리스트 객체 생성
70-
// private List<ListItemDto> mappingCafeteriaList(String campusName, List<CafeteriaDto> cafeteriaList) {
71-
// List<ListItemDto> listItems = new ArrayList<>();
72-
// for (CafeteriaDto cafeteria : cafeteriaList) {
73-
// String userMessage = campusName + " " + cafeteria.getCafeteriaNameKo();
74-
//
75-
// // 리스트 아이템 객체 생성
76-
// ListItemDto listItem = new ListItemDto(cafeteria.getCafeteriaNameKo(), campusName,
77-
// cafeteria.getThumbnailUrl(), "message", userMessage);
78-
// listItems.add(listItem);
79-
// }
80-
// return listItems;
81-
// }
82-
//
83-
//
84-
// // 더보기 버튼 리스트 생성
85-
// private List<ButtonDto> mappingButtonDto() {
86-
// List<ButtonDto> buttonDto = new ArrayList<>();
87-
// Map<String, Object> extra = new HashMap<>();
88-
// extra.put("sys_campus_id", -1);
89-
// // 버튼 객체 생성
90-
// ButtonDto button = new ButtonDto("더보기", "block", "66067167cdd882158c759fc2", extra);
91-
// buttonDto.add(button);
92-
// return buttonDto;
93-
// }
94-
//
95-
//
96-
//
97-
// @Cacheable(value = "cafeteriaId", key = "#campusId + '::' + #cafeteriaName",
98-
// unless = "#result == -1",
99-
// cacheManager = "contentCacheManager")
100-
// // 캠퍼스에 식당이 존재한다면 cafeteriaId 찾기
101-
// public int getCafeteriaId(String cafeteriaName, int campusId) {
102-
// return cafeteriaRepositoryV2.findCafeteriaId(cafeteriaName, campusId).orElse(-1);
103-
// }
104-
//
105-
//
106-
// // 식당 imgUrl 찾기
107-
// public String getImgUrl(int cafeteriaId) {
108-
// return cafeteriaRepositoryV2.findImgUrlByCafeteriaId(cafeteriaId);
109-
// }
110-
11137
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.example.Jinus.service.v2.cafeteria;
2+
3+
import com.example.Jinus.dto.response.ListItemDto;
4+
import com.example.Jinus.dto.response.ResponseDto;
5+
import com.example.Jinus.entity.cafeteria.CampusEntity;
6+
import com.example.Jinus.utility.JsonUtils;
7+
import com.example.Jinus.utility.ListCardResponse;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.stereotype.Service;
10+
11+
import java.util.ArrayList;
12+
import java.util.HashMap;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
@Service
17+
@RequiredArgsConstructor
18+
public class CampusResponseServiceV2 {
19+
20+
private final CampusServiceV2 campusServiceV2;
21+
22+
// 캠퍼스 리스트 반환 메소드
23+
public String makeCampusListCard() {
24+
List<CampusEntity> campusList = campusServiceV2.getCampusList();
25+
// 캠퍼스 리스트 객체 생성
26+
List<ListItemDto> listItems = mappingCampusList(campusList);
27+
// response 객체 생성
28+
ResponseDto responseDto = ListCardResponse.mappingResponseDto("어떤 캠퍼스 식당 정보가 궁금해 ?", listItems, null);
29+
return JsonUtils.toJsonResponse(responseDto);
30+
}
31+
32+
// 캠퍼스 리스트 객체 생성
33+
private List<ListItemDto> mappingCampusList(List<CampusEntity> campusList) {
34+
List<ListItemDto> listItems = new ArrayList<>();
35+
for (CampusEntity campus : campusList) {
36+
String campusName = campus.getCampusNameKo();
37+
String imageUrl = campus.getThumbnailUrl();
38+
Map<String, Object> extra = new HashMap<>();
39+
extra.put("sys_campus_id", campus.getId());
40+
41+
// 캠퍼스 아이템 객체 생성
42+
ListItemDto listItem = new ListItemDto(campusName, imageUrl, "block", "66067167cdd882158c759fc2", extra);
43+
listItems.add(listItem);
44+
}
45+
return listItems;
46+
}
47+
}
Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,11 @@
11
package com.example.Jinus.service.v2.cafeteria;
22

3-
import com.example.Jinus.dto.response.ListItemDto;
4-
import com.example.Jinus.dto.response.ResponseDto;
53
import com.example.Jinus.entity.cafeteria.CampusEntity;
64
import com.example.Jinus.repository.v2.cafeteria.CampusRepositoryV2;
7-
import com.example.Jinus.utility.JsonUtils;
8-
import com.example.Jinus.utility.ListCardResponse;
95
import lombok.RequiredArgsConstructor;
106
import org.springframework.stereotype.Service;
117

12-
import java.util.ArrayList;
13-
import java.util.HashMap;
148
import java.util.List;
15-
import java.util.Map;
169

1710
@Service
1811
@RequiredArgsConstructor
@@ -34,32 +27,4 @@ public List<CampusEntity> getCampusList() {
3427
public int getCampusId(String campusName) {
3528
return campusRepositoryV2.findCampusIdByName(campusName);
3629
}
37-
38-
// 캠퍼스 리스트 반환 메소드
39-
public String makeCampusListCard() {
40-
List<CampusEntity> campusList = getCampusList();
41-
42-
// 캠퍼스 리스트 객체 생성
43-
List<ListItemDto> listItems = mappingCampusList(campusList);
44-
// response 객체 생성
45-
ResponseDto responseDto = ListCardResponse.mappingResponseDto("어떤 캠퍼스 식당 정보가 궁금해 ?", listItems, null);
46-
47-
return JsonUtils.toJsonResponse(responseDto);
48-
}
49-
50-
// 캠퍼스 리스트 객체 생성
51-
private List<ListItemDto> mappingCampusList(List<CampusEntity> campusList) {
52-
List<ListItemDto> listItems = new ArrayList<>();
53-
for (CampusEntity campus : campusList) {
54-
String campusName = campus.getCampusNameKo();
55-
String imageUrl = campus.getThumbnailUrl();
56-
Map<String, Object> extra = new HashMap<>();
57-
extra.put("sys_campus_id", campus.getId());
58-
59-
// 캠퍼스 아이템 객체 생성
60-
ListItemDto listItem = new ListItemDto(campusName, imageUrl, "block", "66067167cdd882158c759fc2", extra);
61-
listItems.add(listItem);
62-
}
63-
return listItems;
64-
}
6530
}

0 commit comments

Comments
 (0)