Skip to content

Commit

Permalink
#2 - Feat: Add Stay Search basic MVCs
Browse files Browse the repository at this point in the history
  • Loading branch information
eun61n00 committed Jun 20, 2023
1 parent 073b015 commit b870c30
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package org.routemaster.api.total.domain.attraction.controller;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.routemaster.api.total.domain.attraction.service.AttractionSearchService;
import org.routemaster.api.total.infra.tourapi.vo.AttractionSearchVO;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

@Slf4j
@RestController
@RequestMapping("/attraction-search")
@RequiredArgsConstructor
public class StaySearchRestController {

private final AttractionSearchService attractionSearchService;

@GetMapping("/stay")
public ResponseEntity<Mono<AttractionSearchVO>> stay(
@RequestParam(required = false) Integer numOfRows,
@RequestParam(required = false) Integer pageNo,
@RequestParam(required = false) String arrange,
@RequestParam(required = false) Integer areaCode,
@RequestParam(required = false) Integer sigunguCode,
@RequestParam(required = false) String modifiedTime
) {
Mono<AttractionSearchVO> result = attractionSearchService.searchStay(
numOfRows,
pageNo,
arrange,
areaCode,
sigunguCode,
modifiedTime
);
return ResponseEntity.ok(result);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Mono<AttractionSearchVO> searchLocationBasedAttraction(
Double mapY,
Integer radius,
Integer contentTypeId,
String modifiedtime
String modifiedTime
);

Mono<AttractionSearchVO> searchAreaBasedAttraction(
Expand Down Expand Up @@ -53,4 +53,13 @@ Mono<AttractionSearchVO> searchFestival(
String modifiedTime
);

Mono<AttractionSearchVO> searchStay(
Integer numOfRows,
Integer pageNo,
String arrange,
Integer areaCode,
Integer sigunguCode,
String modifiedTime
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Date;


@Slf4j
Expand Down Expand Up @@ -266,4 +265,56 @@ public Mono<AttractionSearchVO> searchFestival(
);
return result;
}

@Override
public Mono<AttractionSearchVO> searchStay(
Integer numOfRows,
Integer pageNo,
String arrange,
Integer areaCode,
Integer sigunguCode,
String modifiedTime
) {
ObjectMapper mapper = new ObjectMapper();
DefaultUriBuilderFactory factory = new DefaultUriBuilderFactory(TourAPI.baseUrl);
factory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.VALUES_ONLY);
WebClient webClient = WebClient.builder()
.uriBuilderFactory(factory)
.baseUrl(TourAPI.baseUrl)
.build();
Mono<AttractionSearchVO> result = webClient.get()
.uri(uriBuilder -> uriBuilder
.path("/searchStay1")
.queryParam("serviceKey", TourAPI.encodingKey)
.queryParam("MobileOS", MOBILEOS)
.queryParam("MobileApp", MOBILEAPP)
.queryParam("_type", TYPE)
.queryParam("numOfRows", numOfRows)
.queryParam("pageNo", pageNo)
.queryParam("listYN", LISTNY)
.queryParam("arrange", arrange)
.queryParam("areaCode", areaCode)
.queryParam("sigunguCode", sigunguCode)
.queryParam("modifiedtime", modifiedTime)
.build()
).accept(MediaType.APPLICATION_JSON)
.retrieve()
.bodyToMono(String.class)
.map(str -> {
ObjectMapper objectMapper = new ObjectMapper();
try {
JsonNode jsonNode = mapper.readTree(str);
AttractionSearchVO attractionSearchVO = AttractionSearchVO.builder()
.resultCode(jsonNode.get("response").get("header").get("resultCode").asText())
.resultMessage(jsonNode.get("response").get("header").get("resultMsg").asText())
.stayItems(jsonNode.get("response").get("body"))
.build();
return attractionSearchVO;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ public AttractionSearchVOBuilder festivalItems(JsonNode jsonNode) {
this.totalCount = jsonNode.get("totalCount").asInt();
return this;
}

public AttractionSearchVOBuilder stayItems(JsonNode jsonNode) {
this.attractions = new ArrayList<>();
jsonNode.get("items").get("item").forEach(item -> {
try {
AttractionVO attractionVO = new StayAttractionVO(item);
this.attractions.add(attractionVO);
} catch (Exception e) {
e.printStackTrace();
}
});
this.numOfRows = jsonNode.get("numOfRows").asInt();
this.pageNo = jsonNode.get("pageNo").asInt();
this.totalCount = jsonNode.get("totalCount").asInt();
return this;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.routemaster.api.total.infra.tourapi.vo;

import com.fasterxml.jackson.databind.JsonNode;
import lombok.Getter;

import java.text.ParseException;

public class StayAttractionVO extends AttractionVO {

private @Getter Boolean benikia;
private @Getter Boolean goodStay;
private @Getter Boolean hanok;

public StayAttractionVO(JsonNode item) throws ParseException {
super(item);
this.benikia = !item.get("benikia").asText().isEmpty();
this.goodStay = !item.get("goodstay").asText().isEmpty();
this.hanok = !item.get("hanok").asText().isEmpty();
}

}

0 comments on commit b870c30

Please sign in to comment.