-
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.
- Loading branch information
Showing
42 changed files
with
1,344 additions
and
397 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
24 changes: 24 additions & 0 deletions
24
src/main/java/team7/inplace/global/exception/InplaceException.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,24 @@ | ||
package team7.inplace.global.exception; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
import team7.inplace.global.exception.code.ErrorCode; | ||
|
||
@Getter | ||
public class InplaceException extends RuntimeException { | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorCode; | ||
private final String errorMessage; | ||
|
||
private InplaceException(ErrorCode errorCode) { | ||
super(errorCode.message()); | ||
this.httpStatus = errorCode.httpStatus(); | ||
this.errorCode = errorCode.code(); | ||
this.errorMessage = errorCode.message(); | ||
} | ||
|
||
public static InplaceException of(ErrorCode errorCode) { | ||
return new InplaceException(errorCode); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.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,32 @@ | ||
package team7.inplace.global.exception.code; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public enum AuthorizationErrorCode implements ErrorCode { | ||
TOKEN_IS_EMPTY(HttpStatus.BAD_REQUEST, "A001", "Token is Empty"), | ||
INVALID_TOKEN(HttpStatus.BAD_REQUEST, "A002", "Invalid Token"), | ||
TOKEN_IS_EXPIRED(HttpStatus.BAD_REQUEST, "A003", "Token is Expired"); | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorCode; | ||
private final String message; | ||
|
||
@Override | ||
public HttpStatus httpStatus() { | ||
return httpStatus; | ||
} | ||
|
||
@Override | ||
public String code() { | ||
return errorCode; | ||
} | ||
|
||
@Override | ||
public String message() { | ||
return message; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/team7/inplace/global/exception/code/ErrorCode.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 team7.inplace.global.exception.code; | ||
|
||
import org.springframework.http.HttpStatus; | ||
|
||
public interface ErrorCode { | ||
|
||
HttpStatus httpStatus(); | ||
|
||
String code(); | ||
|
||
String message(); | ||
} |
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
Oops, something went wrong.