diff --git a/.gitignore b/.gitignore index 2bc08f85..04f1560a 100644 --- a/.gitignore +++ b/.gitignore @@ -207,4 +207,4 @@ gradle-app.setting # CommandLineRunner for loading dummy data src/main/java/team7/inplace/place/config/DataLoader.java -# End of https://www.toptal.com/developers/gitignore/api/macos,java,intellij,gradle \ No newline at end of file +# End of https://www.toptal.com/developers/gitignore/api/macos,java,intellij,gradle diff --git a/src/main/java/team7/inplace/global/exception/InplaceException.java b/src/main/java/team7/inplace/global/exception/InplaceException.java new file mode 100644 index 00000000..9508d222 --- /dev/null +++ b/src/main/java/team7/inplace/global/exception/InplaceException.java @@ -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); + } +} diff --git a/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java b/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java new file mode 100644 index 00000000..640aaccf --- /dev/null +++ b/src/main/java/team7/inplace/global/exception/code/AuthorizationErrorCode.java @@ -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; + } +} diff --git a/src/main/java/team7/inplace/global/exception/code/ErrorCode.java b/src/main/java/team7/inplace/global/exception/code/ErrorCode.java new file mode 100644 index 00000000..71f91bfc --- /dev/null +++ b/src/main/java/team7/inplace/global/exception/code/ErrorCode.java @@ -0,0 +1,12 @@ +package team7.inplace.global.exception.code; + +import org.springframework.http.HttpStatus; + +public interface ErrorCode { + + HttpStatus httpStatus(); + + String code(); + + String message(); +} diff --git a/src/main/java/team7/inplace/place/application/PlaceService.java b/src/main/java/team7/inplace/place/application/PlaceService.java index 911618b7..1fc5f560 100644 --- a/src/main/java/team7/inplace/place/application/PlaceService.java +++ b/src/main/java/team7/inplace/place/application/PlaceService.java @@ -1,12 +1,20 @@ 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 @@ -14,20 +22,68 @@ public class PlaceService { private final PlaceRepository placeRepository; + private final VideoRepository videoRepository; + public Page getPlacesWithinRadius( - PlacesCoordinateCommand placesCoordinateCommand) { + PlacesCoordinateCommand placesCoordinateCommand, + PlacesFilterParamsCommand placesFilterParamsCommand) { + + // categories와 influencers 필터 처리 + List categoryFilters = null; + List influencerFilters = null; + + // 필터 값이 있을 경우에만 split 처리 + if (placesFilterParamsCommand.isCategoryFilterExists()) { + categoryFilters = Arrays.stream(placesFilterParamsCommand.categories().split(",")) + .toList(); + } + + if (placesFilterParamsCommand.isInfluencerFilterExists()) { + influencerFilters = Arrays.stream(placesFilterParamsCommand.influencers().split(",")) + .toList(); + } // 주어진 좌표로 장소를 찾고, 해당 페이지의 결과를 가져옵니다. - Page placesPage = getPlacesByDistance(placesCoordinateCommand); + Page placesPage = getPlacesByDistance(placesCoordinateCommand, categoryFilters, + influencerFilters); - return placesPage.map(PlaceInfo::of); + // Place ID 목록 추출 + List placeIds = placesPage.getContent().stream() + .map(Place::getId) + .toList(); + + // influencer 조회와 PlaceInfo 변환 + List