-
Notifications
You must be signed in to change notification settings - Fork 2
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
Feat/#7 place - 카테고리, 인플루언서 필터링을 적용시켰어요!
- Loading branch information
Showing
21 changed files
with
860 additions
and
332 deletions.
There are no files selected for viewing
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
74 changes: 65 additions & 9 deletions
74
src/main/java/team7/inplace/place/application/PlaceService.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,33 +1,89 @@ | ||
package team7.inplace.place.application; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.stereotype.Service; | ||
import team7.inplace.place.application.command.PlacesCommand.PlacesCoordinateCommand; | ||
import team7.inplace.place.application.command.PlacesCommand.PlacesFilterParamsCommand; | ||
import team7.inplace.place.application.dto.PlaceInfo; | ||
import team7.inplace.place.domain.Place; | ||
import team7.inplace.place.persistence.PlaceRepository; | ||
import team7.inplace.video.domain.Video; | ||
import team7.inplace.video.persistence.VideoRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PlaceService { | ||
|
||
private final PlaceRepository placeRepository; | ||
|
||
private final VideoRepository videoRepository; | ||
|
||
public Page<PlaceInfo> getPlacesWithinRadius( | ||
PlacesCoordinateCommand placesCoordinateCommand) { | ||
PlacesCoordinateCommand placesCoordinateCommand, | ||
PlacesFilterParamsCommand placesFilterParamsCommand) { | ||
|
||
// categories와 influencers 필터 처리 | ||
List<String> categoryFilters = null; | ||
List<String> influencerFilters = null; | ||
|
||
// 필터 값이 있을 경우에만 split 처리 | ||
if (placesFilterParamsCommand.isCategoryFilterExists()) { | ||
categoryFilters = Arrays.stream(placesFilterParamsCommand.categories().split(",")) | ||
.toList(); | ||
} | ||
|
||
if (placesFilterParamsCommand.isInfluencerFilterExists()) { | ||
influencerFilters = Arrays.stream(placesFilterParamsCommand.influencers().split(",")) | ||
.toList(); | ||
} | ||
|
||
// 주어진 좌표로 장소를 찾고, 해당 페이지의 결과를 가져옵니다. | ||
Page<Place> placesPage = getPlacesByDistance(placesCoordinateCommand); | ||
Page<Place> placesPage = getPlacesByDistance(placesCoordinateCommand, categoryFilters, | ||
influencerFilters); | ||
|
||
return placesPage.map(PlaceInfo::of); | ||
// Place ID 목록 추출 | ||
List<Long> placeIds = placesPage.getContent().stream() | ||
.map(Place::getId) | ||
.toList(); | ||
|
||
// influencer 조회와 PlaceInfo 변환 | ||
List<Video> videos = videoRepository.findByPlaceIdIn(placeIds); | ||
Map<Long, String> placeIdToInfluencerName = videos.stream() | ||
.collect(Collectors.toMap( | ||
video -> video.getPlace().getId(), | ||
video -> video.getInfluencer().getName() | ||
)); | ||
|
||
// PlaceInfo 생성 | ||
List<PlaceInfo> placeInfos = placesPage.getContent().stream() | ||
.map(place -> { | ||
// map에서 조회되지 않은 placeId는 null로 처리 | ||
String influencerName = placeIdToInfluencerName.getOrDefault(place.getId(), null); | ||
return PlaceInfo.of(place, influencerName); | ||
}) | ||
.toList(); | ||
|
||
// PlaceInfo 리스트를 Page로 변환하여 반환 | ||
return new PageImpl<>(placeInfos, placesPage.getPageable(), placesPage.getTotalElements()); | ||
} | ||
|
||
private Page<Place> getPlacesByDistance(PlacesCoordinateCommand comm) { | ||
return placeRepository.getPlacesByDistance( | ||
comm.latitude(), | ||
comm.longitude(), | ||
comm.pageable()); | ||
|
||
private Page<Place> getPlacesByDistance( | ||
PlacesCoordinateCommand placesCoordinateCommand, | ||
List<String> categoryFilters, | ||
List<String> influencerFilters | ||
) { | ||
return placeRepository.getPlacesByDistanceAndFilters( | ||
placesCoordinateCommand.latitude(), | ||
placesCoordinateCommand.longitude(), | ||
categoryFilters, | ||
influencerFilters, | ||
placesCoordinateCommand.pageable()); | ||
} | ||
|
||
} |
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
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
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
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
25 changes: 25 additions & 0 deletions
25
src/main/java/team7/inplace/place/domain/PlaceCloseTime.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,25 @@ | ||
package team7.inplace.place.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Embeddable; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.hibernate.annotations.ColumnDefault; | ||
|
||
@Embeddable | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class PlaceCloseTime { | ||
|
||
@Column(length = 50, nullable = false) | ||
private String holidayName; | ||
|
||
@Column(length = 50, nullable = false) | ||
private String weekAndDay; | ||
|
||
@ColumnDefault("false") | ||
@Column(nullable = false) | ||
private boolean temporaryHolidays; | ||
} |
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
Oops, something went wrong.