forked from codesquad-members-2024/be-airdnb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
패키지 수정
- Loading branch information
Showing
22 changed files
with
219 additions
and
78 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
BE/src/main/java/team07/airbnb/domain/accommodation/AccomodationController.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,54 @@ | ||
package team07.airbnb.domain.accommodation; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import team07.airbnb.domain.accommodation.dto.AccomodationCreateRequest; | ||
import team07.airbnb.domain.accommodation.dto.AccomodationListResponse; | ||
import team07.airbnb.domain.accommodation.entity.AccomodationEntity; | ||
|
||
import java.util.List; | ||
|
||
@RequestMapping("/accomodation") | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class AccomodationController { | ||
private final AccomodationService accomodationService; | ||
|
||
|
||
@GetMapping | ||
public List<AccomodationEntity> findAll() { | ||
return accomodationService.findAllAccomodations(); | ||
} | ||
|
||
@GetMapping("/location") | ||
public List<AccomodationListResponse> findNeighbor( | ||
@RequestParam double longitude, | ||
@RequestParam double latitude, | ||
@RequestParam double distance) { | ||
|
||
return accomodationService.findNearbyAccomodations(longitude, latitude, distance); | ||
} | ||
|
||
@PostMapping | ||
public void createAccomodation(@RequestBody AccomodationCreateRequest createRequest){ | ||
|
||
} | ||
|
||
/** | ||
* 호스팅할 숙소 유형을 선택하세요. v | ||
* 숙소 건물 유형을 자세히 설명하세요. ? | ||
* 게스트가 숙소 공간을 단독으로 사용하는지 명확히 알려주세요. v | ||
* 숙소 위치를 입력해 주세요. v | ||
* 숙박 가능한 인원수를 결정하세요. v | ||
* 숙소 편의시설을 등록하세요. | ||
* 사진을 추가하고 정리하세요. v | ||
* 숙소 이름을 정하세요. v | ||
* 숙소 설명을 작성하세요. v | ||
* 1박당 요금을 설정하세요. | ||
*/ | ||
} |
3 changes: 2 additions & 1 deletion
3
.../accomodation/AccomodationRepository.java → ...accommodation/AccomodationRepository.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
5 changes: 3 additions & 2 deletions
5
...ain/accomodation/AccomodationService.java → ...in/accommodation/AccomodationService.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
18 changes: 18 additions & 0 deletions
18
BE/src/main/java/team07/airbnb/domain/accommodation/dto/AccomodationCreateRequest.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,18 @@ | ||
package team07.airbnb.domain.accommodation.dto; | ||
|
||
import team07.airbnb.domain.accommodation.property.RoomInformation; | ||
import team07.airbnb.domain.accommodation.property.AccommodationLocation; | ||
import team07.airbnb.domain.accommodation.property.AccomodationType; | ||
|
||
import java.util.List; | ||
|
||
public record AccomodationCreateRequest( | ||
AccomodationType type, | ||
RoomInformation roomInformation, | ||
AccommodationLocation address, | ||
String name, | ||
String description, | ||
List<String> images, | ||
int basePricePerDay | ||
) { | ||
} |
8 changes: 4 additions & 4 deletions
8
...odation/dto/AccomodationListResponse.java → ...odation/dto/AccomodationListResponse.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
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
2 changes: 1 addition & 1 deletion
2
.../airbnb/domain/accomodation/Pictures.java → ...domain/accommodation/entity/Pictures.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
2 changes: 1 addition & 1 deletion
2
...ation/property/AccommodationLocation.java → ...ation/property/AccommodationLocation.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
12 changes: 12 additions & 0 deletions
12
BE/src/main/java/team07/airbnb/domain/accommodation/property/AccomodationAmenity.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,12 @@ | ||
package team07.airbnb.domain.accommodation.property; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Entity | ||
public class AccomodationAmenity { | ||
@Id | ||
private String name; | ||
} |
2 changes: 1 addition & 1 deletion
2
...comodation/property/AccomodationType.java → ...ommodation/property/AccomodationType.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
14 changes: 14 additions & 0 deletions
14
BE/src/main/java/team07/airbnb/domain/accommodation/property/RoomInformation.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,14 @@ | ||
package team07.airbnb.domain.accommodation.property; | ||
|
||
import jakarta.persistence.Embeddable; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Embeddable | ||
public class RoomInformation { | ||
private int bedCount; | ||
private int bedroomCount; | ||
private int bathroomCount; | ||
private boolean isPrivate; | ||
private int maxOccupancy; | ||
} |
32 changes: 0 additions & 32 deletions
32
BE/src/main/java/team07/airbnb/domain/accomodation/AccomodationController.java
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
BE/src/main/java/team07/airbnb/domain/accomodation/property/AccomodationAmenity.java
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...airbnb/domain/product/DiscountPolicy.java → ...airbnb/domain/booking/DiscountPolicy.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
2 changes: 1 addition & 1 deletion
2
.../airbnb/domain/product/ProductStatus.java → ...bnb/domain/product/ProductController.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,4 +1,4 @@ | ||
package team07.airbnb.domain.product; | ||
|
||
public enum ProductStatus { | ||
public class ProductController { | ||
} |
12 changes: 12 additions & 0 deletions
12
BE/src/main/java/team07/airbnb/domain/product/ProductRepository.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,12 @@ | ||
package team07.airbnb.domain.product; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import team07.airbnb.domain.product.entity.ProductEntity; | ||
import team07.airbnb.domain.product.entity.ProductStatus; | ||
|
||
import java.util.List; | ||
|
||
public interface ProductRepository extends JpaRepository<ProductEntity, Long> { | ||
|
||
List<ProductEntity> findAllByAccomodationIdInAndStatus(List<Long> accomodationIds, ProductStatus status); | ||
} |
60 changes: 60 additions & 0 deletions
60
BE/src/main/java/team07/airbnb/domain/product/ProductService.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,60 @@ | ||
package team07.airbnb.domain.product; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import team07.airbnb.domain.accommodation.dto.AccomodationListResponse; | ||
import team07.airbnb.domain.accommodation.entity.AccomodationEntity; | ||
import team07.airbnb.domain.product.dto.ProductListResponse; | ||
import team07.airbnb.domain.product.entity.ProductEntity; | ||
|
||
import java.time.LocalDate; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
import static team07.airbnb.domain.product.entity.ProductStatus.OPEN; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ProductService { | ||
private final ProductRepository productRepository; | ||
|
||
public List<ProductListResponse> findAvailableInDateRange( | ||
List<AccomodationEntity> accommodations, LocalDate checkIn, LocalDate checkOut) { | ||
|
||
List<Long> accomodationIds = accommodations.stream().map(AccomodationEntity::getId).toList(); | ||
|
||
Map<Long, List<ProductEntity>> products = productRepository.findAllByAccomodationIdInAndStatus(accomodationIds, OPEN) | ||
.stream() | ||
.collect(Collectors.groupingBy(p -> p.getAccomodation().getId())); | ||
|
||
|
||
Map<Long, List<ProductEntity>> availableProducts = products.entrySet().stream() | ||
.filter(entry -> isAvailableInDateRange(entry.getValue(), checkIn, checkOut)) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
|
||
return availableProducts.keySet().stream().map(key -> { | ||
List<ProductEntity> productEntities = availableProducts.get(key); | ||
return new ProductListResponse( | ||
AccomodationListResponse.of(productEntities.get(0).getAccomodation()), | ||
(int) productEntities.stream().mapToInt(ProductEntity::getPrice).average().getAsDouble() | ||
); | ||
} | ||
).toList(); | ||
} | ||
|
||
private boolean isAvailableInDateRange(List<ProductEntity> products, LocalDate checkIn, LocalDate checkOut) { | ||
Set<LocalDate> dateSet = new HashSet<>(); | ||
for (LocalDate date = checkIn; !date.isAfter(checkOut); date = date.plusDays(1)) { | ||
dateSet.add(date); | ||
} | ||
|
||
for (ProductEntity product : products) { | ||
dateSet.remove(product.getDate()); | ||
} | ||
|
||
return dateSet.isEmpty(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
BE/src/main/java/team07/airbnb/domain/product/dto/ProductListResponse.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,9 @@ | ||
package team07.airbnb.domain.product.dto; | ||
|
||
import team07.airbnb.domain.accommodation.dto.AccomodationListResponse; | ||
|
||
public record ProductListResponse ( | ||
AccomodationListResponse accomodation, | ||
int price | ||
){ | ||
} |
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
5 changes: 5 additions & 0 deletions
5
BE/src/main/java/team07/airbnb/domain/product/entity/ProductStatus.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,5 @@ | ||
package team07.airbnb.domain.product.entity; | ||
|
||
public enum ProductStatus { | ||
OPEN | ||
} |
Oops, something went wrong.