Skip to content

Commit

Permalink
Feat: Add cluster type
Browse files Browse the repository at this point in the history
  • Loading branch information
Minjae-vincent committed Jul 17, 2024
1 parent 512358e commit 5fb553a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import kr.ac.kopo.jeonse.domain.jeonse.dto.InfraDTO;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseCheckList;
import kr.ac.kopo.jeonse.domain.jeonse.dto.RecommendRequest;
import kr.ac.kopo.jeonse.domain.jeonse.dto.RecommendResponse;
import kr.ac.kopo.jeonse.domain.jeonse.service.JeonseService;
import kr.ac.kopo.jeonse.global.payload.ApiResponse;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -58,7 +59,7 @@ public ApiResponse<List<InfraDTO>> infraList() {
}

@PostMapping("/recommend")
public ApiResponse<List<JeonseCheckList>> recommend(@RequestBody RecommendRequest recommendRequest) {
public ApiResponse<RecommendResponse> recommend(@RequestBody RecommendRequest recommendRequest) {
return ApiResponse.onSuccess(jeonseService.recommendJeonse(recommendRequest));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.ac.kopo.jeonse.domain.jeonse.dto;

import lombok.Data;

import java.util.List;

@Data
public class RecommendResponse {
private String clusterType;
private List<JeonseCheckList> jeonseCheckList;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import kr.ac.kopo.jeonse.domain.jeonse.domain.*;
import kr.ac.kopo.jeonse.domain.jeonse.dto.InfraDTO;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseCheckList;
import kr.ac.kopo.jeonse.domain.jeonse.dto.JeonseRateDto;
import kr.ac.kopo.jeonse.domain.jeonse.dto.RecommendRequest;
import kr.ac.kopo.jeonse.domain.jeonse.dto.*;
import kr.ac.kopo.jeonse.domain.jeonse.mapper.BuildingRegisterMapper;
import kr.ac.kopo.jeonse.domain.jeonse.mapper.JeonseMapper;
import kr.ac.kopo.jeonse.global.utils.NullToEmptyStringUtil;
Expand Down Expand Up @@ -125,7 +122,7 @@ public JeonseCheckList checkJeonse(String actlNo) {
Jeonse jeonse = jeonseMapper.selectJeonseByAtclNo(actlNo);
JeonseRateDto jeonseRateDto = calculateJeonseRate(actlNo);

if(jeonseRateDto.getJeonsePrice() == null) {
if (jeonseRateDto.getJeonsePrice() == null) {
jeonseRateDto.setJeonsePrice("0");
}

Expand Down Expand Up @@ -219,12 +216,12 @@ private Jeonse transformJeonse(Jeonse jeonse) {
String tmp = jeonse.getFlrInfo();
String[] flrInfo = tmp.split("/");
if (flrInfo.length == 1) {
jeonse.setFlrInfo(flrInfo[0]+"/1");
jeonse.setFlrInfo(flrInfo[0] + "/1");
} else {
String firstValue = flrInfo[0];
int secondValue = Integer.parseInt(flrInfo[1]);
if (firstValue.contains("B")) {
jeonse.setFlrInfo(Integer.parseInt(String.valueOf(firstValue.toCharArray()[1])) * -1 +"/1");
jeonse.setFlrInfo(Integer.parseInt(String.valueOf(firstValue.toCharArray()[1])) * -1 + "/1");
return jeonse;
}
String calculatedFloor = switch (firstValue) {
Expand All @@ -237,7 +234,7 @@ private Jeonse transformJeonse(Jeonse jeonse) {
jeonse.setFlrInfo(calculatedFloor + "/1");
}

if(!jeonse.getAddress().contains("-")){
if (!jeonse.getAddress().contains("-")) {
jeonse.setAddress(jeonse.getAddress() + "-0");

}
Expand Down Expand Up @@ -321,9 +318,14 @@ private List<InfraDTO.BusStation> getBusStations(String gu) {
.collect(Collectors.toList());
}

public List<JeonseCheckList> recommendJeonse(RecommendRequest recommendRequest) {
public RecommendResponse recommendJeonse(RecommendRequest recommendRequest) {
List<String> atclNos = getRecommendationList(recommendRequest);

RecommendResponse recommendResponse = new RecommendResponse();
recommendResponse.setClusterType(atclNos.get(atclNos.size() - 1));

atclNos.remove(atclNos.size() - 1);

List<JeonseCheckList> recommendList = new ArrayList<>();

for (String atclNo : atclNos) {
Expand All @@ -345,8 +347,8 @@ public List<JeonseCheckList> recommendJeonse(RecommendRequest recommendRequest)
recommendList.add(jeonseCheckList);
}
}

return recommendList;
recommendResponse.setJeonseCheckList(recommendList);
return recommendResponse;
}

private List<String> getRecommendationList(RecommendRequest recommendRequest) {
Expand Down

0 comments on commit 5fb553a

Please sign in to comment.