Skip to content

Commit

Permalink
feat : 좌표 근처 호텔 정보 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
Dayon-Hong committed May 14, 2024
1 parent 107dc7b commit 9a8179a
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
package com.isp.backend.domain.hotel.controller;

import com.amadeus.exceptions.ResponseException;
import com.isp.backend.domain.hotel.dto.request.SearchGeocodeRequest;
import com.isp.backend.domain.hotel.service.HotelService;
import com.isp.backend.global.exception.flight.AmadeusSearchFailedException;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bookings/hotels")
@RequiredArgsConstructor
public class HotelController {

private final HotelService hotelService ;

/** 좌표 주변 호텔 리스트 API **/
@PostMapping("/search")
public ResponseEntity<String> searchHotelsByGeocode(@RequestBody SearchGeocodeRequest request) {
try {
String hotelsJson = hotelService.searchHotelsByGeocode(request);
return ResponseEntity.ok(hotelsJson);
} catch (ResponseException e) {
throw new AmadeusSearchFailedException();
}
}

/** 호텔 선택시 스카이스캐너 사이트로 연결 API **/


/** 호텔 좋아요 저장 API **/


/** 호텔 좋아요 목록 불러오기 API **/


/** 호텔 좋아요 삭제하기 API **/




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ public class SearchGeocodeRequest {

private String longitude;

private int radius ;

private String ratings ; // 호텔 등급

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.isp.backend.domain.hotel.service;

import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.Hotel;
import com.isp.backend.domain.hotel.dto.request.SearchGeocodeRequest;

public interface HotelService {
public String searchHotelsByGeocode(SearchGeocodeRequest request) throws ResponseException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.isp.backend.domain.hotel.service;

import com.amadeus.Amadeus;
import com.amadeus.Params;
import com.amadeus.exceptions.ResponseException;
import com.amadeus.resources.Hotel;
import com.amadeus.shopping.HotelOffersSearch;
import com.google.gson.Gson;
import com.isp.backend.domain.hotel.dto.request.SearchGeocodeRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class HotelServiceImpl implements HotelService {
private final Amadeus amadeus;

/**
* 좌표 주변 호텔 리스트 API
**/
@Override
public String searchHotelsByGeocode(SearchGeocodeRequest request) throws ResponseException {
String latitude = request.getLatitude();
String longitude = request.getLongitude();
int radius = request.getRadius();
String ratings = request.getRatings();

Hotel[] hotelSearch = amadeus.referenceData.locations.hotels.byGeocode.get(
Params.with("latitude", latitude)
.and("longitude", longitude)
.and("radius", radius)
.and("radiusUnit", "KM")
.and("ratings", ratings)
.and("hotelSource", "ALL")
);
Gson gson = new Gson();
String hotelSearchJson = gson.toJson(hotelSearch);
return hotelSearchJson;
}


}

0 comments on commit 9a8179a

Please sign in to comment.