-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…dattions_by_keywords_api [Backend] [43] 검색 조건에 따른 숙소 목록 조회 기능 구현
- Loading branch information
Showing
8 changed files
with
181 additions
and
30 deletions.
There are no files selected for viewing
43 changes: 23 additions & 20 deletions
43
backend/src/main/java/team15/airbnb/accommodation/application/AccommodationService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,43 @@ | ||
package team15.airbnb.accommodation.application; | ||
|
||
import java.util.List; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import team15.airbnb.accommodation.domain.Accommodation; | ||
import team15.airbnb.accommodation.infrastructure.AccommodationRepository; | ||
import team15.airbnb.accommodation.presentation.dto.AccommodationDetailsResponse; | ||
import team15.airbnb.accommodation.presentation.dto.AccommodationFeeDto; | ||
import team15.airbnb.accommodation.presentation.dto.AccommodationFeesResponse; | ||
import team15.airbnb.accommodation.presentation.dto.*; | ||
import team15.airbnb.user.infrastructure.UserRepository; | ||
|
||
@Slf4j | ||
@Service | ||
public class AccommodationService { | ||
|
||
private final AccommodationRepository accommodationRepository; | ||
private final UserRepository userRepository; | ||
private final AccommodationRepository accommodationRepository; | ||
private final UserRepository userRepository; | ||
|
||
public AccommodationService(AccommodationRepository accommodationRepository, UserRepository userRepository) { | ||
this.accommodationRepository = accommodationRepository; | ||
this.userRepository = userRepository; | ||
} | ||
public AccommodationService(AccommodationRepository accommodationRepository, UserRepository userRepository) { | ||
this.accommodationRepository = accommodationRepository; | ||
this.userRepository = userRepository; | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public AccommodationDetailsResponse searchById(Long accommodationId) { | ||
Accommodation accommodation = accommodationRepository.findById(accommodationId); | ||
@Transactional(readOnly = true) | ||
public AccommodationDetailsResponse searchById(Long accommodationId) { | ||
Accommodation accommodation = accommodationRepository.findById(accommodationId); | ||
/* | ||
TODO 유저 조회 (JWT 에 sign 된 user id를 통해서..) 후 like 여부 판단 | ||
*/ | ||
return AccommodationDetailsResponse.convertFrom(accommodation, true); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public AccommodationFeesResponse searchByFeeRange(int minPrice, int maxPrice) { | ||
List<AccommodationFeeDto> accommodations = accommodationRepository.findByFee(minPrice, maxPrice); | ||
return AccommodationFeesResponse.convertFrom(accommodations); | ||
} | ||
return AccommodationDetailsResponse.convertFrom(accommodation, true); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public AccommodationFeesResponse searchByFeeRange(int minPrice, int maxPrice) { | ||
List<AccommodationFeeDto> accommodations = accommodationRepository.findByFee(minPrice, maxPrice); | ||
return AccommodationFeesResponse.convertFrom(accommodations); | ||
} | ||
|
||
public SearchAccommodationsByOptionsResponse searchByOptions(SearchAccommodationsOptionsRequest request, Long userId) { | ||
return new SearchAccommodationsByOptionsResponse(new AccommodationListResponse(accommodationRepository.findByOptions(request, userId))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...src/main/java/team15/airbnb/accommodation/presentation/dto/AccommodationListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package team15.airbnb.accommodation.presentation.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class AccommodationListResponse { | ||
|
||
private int totalCount; | ||
private List<AccommodationSimpleInfoResponse> accommodations = new ArrayList<>(); | ||
|
||
public AccommodationListResponse(List<AccommodationSimpleInfoResponse> accommodations) { | ||
totalCount = accommodations.size(); | ||
this.accommodations = accommodations; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...in/java/team15/airbnb/accommodation/presentation/dto/AccommodationSimpleInfoResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package team15.airbnb.accommodation.presentation.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.locationtech.jts.geom.Point; | ||
import org.locationtech.jts.io.ParseException; | ||
import org.locationtech.jts.io.WKTReader; | ||
import team15.airbnb.user.domain.UserType; | ||
|
||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class AccommodationSimpleInfoResponse { | ||
|
||
private Long accommodationId; | ||
private boolean like; | ||
private boolean superHost; | ||
private String accommodationName; | ||
private String mainImage; | ||
private Double starRating; | ||
private Integer reviewCount; | ||
private Integer price; | ||
private int totalPrice; | ||
private double longitude; | ||
private double latitude; | ||
|
||
public AccommodationSimpleInfoResponse(Long accommodationId, Boolean like, UserType host, String accommodationName, String mainImage, Double starRating, Integer reviewCount, Integer price, String coordinate) throws ParseException { | ||
this.accommodationId = accommodationId; | ||
this.like = like; | ||
this.superHost = host.isSuperHost(); | ||
this.accommodationName = accommodationName; | ||
this.mainImage = mainImage; | ||
this.starRating = starRating; | ||
this.reviewCount = reviewCount; | ||
this.price = price; | ||
this.totalPrice = 0; | ||
Point point = (Point) new WKTReader().read(coordinate); | ||
this.longitude = point.getY(); | ||
this.latitude = point.getX(); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
...a/team15/airbnb/accommodation/presentation/dto/SearchAccommodationsByOptionsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package team15.airbnb.accommodation.presentation.dto; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class SearchAccommodationsByOptionsResponse { | ||
|
||
/* | ||
Todo: 페이징 처리를 완료하면 hasNext값을 설정할 것. | ||
*/ | ||
private boolean hasNext; | ||
private AccommodationListResponse data; | ||
|
||
public SearchAccommodationsByOptionsResponse(AccommodationListResponse data) { | ||
this.data = data; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...java/team15/airbnb/accommodation/presentation/dto/SearchAccommodationsOptionsRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package team15.airbnb.accommodation.presentation.dto; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
@ToString | ||
public class SearchAccommodationsOptionsRequest{ | ||
|
||
private String location=""; | ||
private String checkIn; | ||
private String checkOut; | ||
private int minPrice; | ||
private int maxPrice = 1000000; | ||
private int adult; | ||
private int child; | ||
private int baby; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters