Skip to content

Commit 7e116bc

Browse files
committed
refactor: BuildingGraphController 그래프 관련 API 분리
1 parent 5177a65 commit 7e116bc

File tree

2 files changed

+228
-162
lines changed

2 files changed

+228
-162
lines changed
Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,233 @@
11
package com.moaguide.refactor.building.controller;
22

3+
import static com.moaguide.refactor.util.EmptyCheckUtil.isEmpty;
4+
import static com.moaguide.refactor.util.EmptyCheckUtil.isListEmpty;
5+
import static com.moaguide.refactor.util.HashMapUtil.createEmptyHashMap;
6+
7+
import com.moaguide.refactor.building.dto.BuildingSubwayResponseDto;
8+
import com.moaguide.refactor.building.dto.LandDto;
9+
import com.moaguide.refactor.building.dto.PopulationDto;
10+
import com.moaguide.refactor.building.dto.RentDto;
11+
import com.moaguide.refactor.building.dto.StayDayDto;
12+
import com.moaguide.refactor.building.dto.StayRateDto;
13+
import com.moaguide.refactor.building.dto.VacancyrateDto;
14+
import com.moaguide.refactor.building.service.graph.LandPriceService;
15+
import com.moaguide.refactor.building.service.graph.PopulationService;
16+
import com.moaguide.refactor.building.service.graph.RentService;
17+
import com.moaguide.refactor.building.service.graph.StayService;
18+
import com.moaguide.refactor.building.service.graph.SubwayService;
19+
import com.moaguide.refactor.building.service.graph.VacancyRateService;
20+
import java.util.ArrayList;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import java.util.Map;
24+
import lombok.AllArgsConstructor;
25+
import lombok.extern.slf4j.Slf4j;
26+
import org.springframework.http.ResponseEntity;
27+
import org.springframework.web.bind.annotation.GetMapping;
28+
import org.springframework.web.bind.annotation.PathVariable;
29+
import org.springframework.web.bind.annotation.RequestMapping;
30+
import org.springframework.web.bind.annotation.RequestParam;
31+
import org.springframework.web.bind.annotation.RestController;
32+
33+
/**
34+
* 건물 그래프 컨트롤러
35+
*/
36+
@RestController
37+
@AllArgsConstructor
38+
@Slf4j
39+
@RequestMapping("/detail/building")
340
public class BuildingGraphController {
441

42+
private final RentService rentService;
43+
private final LandPriceService landPriceService;
44+
private final StayService stayService;
45+
private final SubwayService subwayService;
46+
private final PopulationService populationService;
47+
private final VacancyRateService vacancyRateService;
48+
49+
/**
50+
* 건물의 상권 임대료 그래프를 조회하는 API
51+
*
52+
* @param product_Id 콘텐츠 고유 ID
53+
* @param type 상권 유형 (소규모/중대형)
54+
* @param syear 시작 연도
55+
* @param eyear 종료 연도
56+
* @return 건물의 상권 임대료 그래프 응답 DTO
57+
*/
58+
@GetMapping("/rentrate/{product_Id}")
59+
public ResponseEntity<Object> rentrate(@PathVariable String product_Id,
60+
@RequestParam String type, @RequestParam int syear, @RequestParam int eyear) {
61+
Map<String, List<RentDto>> rentDtos = rentService.getRentByRegion(product_Id, type, syear,
62+
eyear);
63+
Map<String, Object> response = new HashMap<>();
64+
65+
if (rentDtos == null) {
66+
response.put("populations", new ArrayList<>());
67+
return ResponseEntity.ok(response);
68+
}
69+
response.put("rent", rentDtos);
70+
return ResponseEntity.ok(response);
71+
}
72+
73+
/**
74+
* 건물의 상권 공실률 그래프를 조회하는 API
75+
*
76+
* @param product_Id 콘텐츠 고유 ID
77+
* @param type 상권 유형 (소규모/중대형)
78+
* @param syear 시작 연도
79+
* @param eyear 종료 연도
80+
* @return 건물의 상권 공실률 그래프 응답 DTO
81+
*/
82+
@GetMapping("/vacancyrate/{product_Id}")
83+
public ResponseEntity<Object> vacancyrate(@PathVariable String product_Id,
84+
@RequestParam String type, @RequestParam int syear, @RequestParam int eyear) {
85+
Map<String, List<VacancyrateDto>> vacancyrateDtos = vacancyRateService.findBase(product_Id,
86+
type, syear, eyear);
87+
Map<String, Object> response = new HashMap<>();
88+
89+
if (vacancyrateDtos == null) {
90+
response.put("populations", new ArrayList<>());
91+
return ResponseEntity.ok(response);
92+
}
93+
response.put("vacancyrate", vacancyrateDtos);
94+
return ResponseEntity.ok(response);
95+
}
96+
97+
/**
98+
* 건물의 숙박 방문자 수 그래프를 조회하는 API
99+
*
100+
* @param productId 콘텐츠 고유 ID
101+
* @param syear 시작 연도
102+
* @param eyear 종료 연도
103+
* @return 숙박 유형별 방문자 수 그래프 응답 DTO
104+
*/
105+
@GetMapping("/stay/day/{productId}")
106+
public ResponseEntity<Object> stayday(@PathVariable String productId, @RequestParam int syear,
107+
@RequestParam int eyear) {
108+
String keyword;
109+
Map<String, Object> response = new HashMap<>();
110+
111+
if (productId.equals("sou.6")) {
112+
keyword = "전주 시화연풍";
113+
List<StayDayDto> stayday = stayService.findbykeyword(keyword, syear, eyear);
114+
response.put("object", stayday);
115+
return ResponseEntity.ok(response);
116+
} else if (productId.equals("kasa.KR011A20000052")) {
117+
keyword = "부티크호텔 더 페이즈";
118+
List<StayDayDto> stayday = stayService.findbykeyword(keyword, syear, eyear);
119+
response.put("object", stayday);
120+
return ResponseEntity.ok(response);
121+
} else if (productId.equals("kasa.KR011A20000090")) {
122+
keyword = "북촌 월하재";
123+
List<StayDayDto> stayday = stayService.findbykeyword(keyword, syear, eyear);
124+
response.put("object", stayday);
125+
return ResponseEntity.ok(response);
126+
} else if (productId.equals("funble.FB2412111")) {
127+
keyword = "더 코노셔 여의도";
128+
List<StayDayDto> stayday = stayService.findbykeyword(keyword, syear, eyear);
129+
response.put("object", stayday);
130+
return ResponseEntity.ok(response);
131+
} else {
132+
response.put("object", new ArrayList<>());
133+
return ResponseEntity.ok(response);
134+
}
135+
}
136+
137+
/**
138+
* 건물의 숙박 방문자 / 숙박일 그래프를 조회하는 API
139+
*
140+
* @param productId 콘텐츠 고유 ID
141+
* @param syear 시작 연도
142+
* @param eyear 종료 연도
143+
* @return 숙박 방문자 비율 / 평균 숙박일 그래프 응답 DTO
144+
*/
145+
@GetMapping("/stay/rate/{productId}")
146+
public ResponseEntity<Object> stayrate(@PathVariable String productId, @RequestParam int syear,
147+
@RequestParam int eyear) {
148+
String keyword;
149+
Map<String, Object> response = new HashMap<>();
150+
if (productId.equals("sou.6")) {
151+
keyword = "전주 시화연풍";
152+
List<StayRateDto> stayday = stayService.findRateBykeyword(keyword, syear, eyear);
153+
response.put("object", stayday);
154+
return ResponseEntity.ok(response);
155+
} else if (productId.equals("kasa.KR011A20000052")) {
156+
keyword = "부티크호텔 더 페이즈";
157+
List<StayRateDto> stayday = stayService.findRateBykeyword(keyword, syear, eyear);
158+
response.put("object", stayday);
159+
return ResponseEntity.ok(response);
160+
} else if (productId.equals("kasa.KR011A20000090")) {
161+
keyword = "북촌 월하재";
162+
List<StayRateDto> stayday = stayService.findRateBykeyword(keyword, syear, eyear);
163+
response.put("object", stayday);
164+
return ResponseEntity.ok(response);
165+
} else if (productId.equals("funble.FB2412111")) {
166+
keyword = "더 코노셔 여의도";
167+
List<StayRateDto> stayday = stayService.findRateBykeyword(keyword, syear, eyear);
168+
response.put("object", stayday);
169+
return ResponseEntity.ok(response);
170+
} else {
171+
response.put("object", new ArrayList<>());
172+
return ResponseEntity.ok(response);
173+
}
174+
}
175+
176+
/**
177+
* 건물의 상권 공시지가 그래프를 조회하는 API
178+
*
179+
* @param product_Id 콘텐츠 고유 ID
180+
* @return 건물의 상권 공시지가 그래프 응답 DTO
181+
*/
182+
@GetMapping("/land/{product_Id}")
183+
public ResponseEntity<Object> land(@PathVariable String product_Id) {
184+
List<LandDto> landPrice = landPriceService.priceList(product_Id);
185+
Map<String, Object> response = new HashMap<>();
186+
187+
if (isListEmpty(landPrice)) {
188+
response.put("lands", new ArrayList<>());
189+
return ResponseEntity.ok(response);
190+
}
191+
192+
response.put("lands", landPrice);
193+
return ResponseEntity.ok(response);
194+
}
195+
196+
/**
197+
* 건물의 상권 유동 인구 그래프를 조회하는 API
198+
*
199+
* @param productId 콘텐츠 고유 ID
200+
* @return 건물의 상권 유동 인구 그래프 응답 DTO
201+
*/
202+
@GetMapping("/subway/{productId}")
203+
public ResponseEntity<Object> subway(@PathVariable String productId) {
204+
BuildingSubwayResponseDto subwayResponseDto = subwayService.findByProductId(productId);
205+
206+
if (isEmpty(subwayResponseDto) ||
207+
subwayResponseDto.getSubwayDay().isEmpty() ||
208+
subwayResponseDto.getSubwayMonth().isEmpty()) {
209+
return ResponseEntity.ok(new BuildingSubwayResponseDto());
210+
}
211+
212+
return ResponseEntity.ok(subwayResponseDto);
213+
}
214+
215+
/**
216+
* 건물의 상권 유동 인구 그래프를 조회하는 API
217+
*
218+
* @param product_Id 콘텐츠 고유 ID
219+
* @return 건물의 상권 유동 인구 그래프 응답 DTO
220+
*/
221+
@GetMapping("/population/{product_Id}")
222+
public ResponseEntity<Object> population(@PathVariable String product_Id) {
223+
List<PopulationDto> populationDto = populationService.findbydate(product_Id);
224+
Map<String, Object> response = new HashMap<>();
225+
226+
if (populationDto == null) {
227+
response.put("populations", new ArrayList<>());
228+
return ResponseEntity.ok(response);
229+
}
230+
response.put("populations", populationDto);
231+
return ResponseEntity.ok(response);
232+
}
5233
}

0 commit comments

Comments
 (0)