Skip to content

Commit

Permalink
[refactor] weekly/5 충돌 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
wndlthsk committed Oct 4, 2024
2 parents 56c472e + 5f76bdf commit 979c245
Show file tree
Hide file tree
Showing 48 changed files with 1,335 additions and 381 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
# End of https://www.toptal.com/developers/gitignore/api/macos,java,intellij,gradle
24 changes: 24 additions & 0 deletions src/main/java/team7/inplace/global/exception/InplaceException.java
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);
}
}
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 src/main/java/team7/inplace/global/exception/code/ErrorCode.java
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 src/main/java/team7/inplace/place/application/PlaceService.java
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());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,20 @@ public record PlacesCoordinateCommand(
) {

}

public record PlacesFilterParamsCommand(
String categories,
String influencers
) {

public boolean isCategoryFilterExists() {
return categories != null
&& !categories.isEmpty();
}

public boolean isInfluencerFilterExists() {
return influencers != null
&& !influencers.isEmpty();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public static AddressInfo of(Address address) {
}
}

public static PlaceInfo of(Place place) {
public static PlaceInfo of(Place place, String influencerName) {
return new PlaceInfo(
place.getId(),
place.getName(),
AddressInfo.of(place.getAddress()),
place.getCategory().toString(),
null,
influencerName,
place.getCoordinate().getLongitude(),
place.getCoordinate().getLatitude(),
null
Expand Down
97 changes: 0 additions & 97 deletions src/main/java/team7/inplace/place/config/DataLoader.java

This file was deleted.

4 changes: 1 addition & 3 deletions src/main/java/team7/inplace/place/domain/Address.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Getter
public class Address {

Expand All @@ -22,5 +20,5 @@ public class Address {

@Column(nullable = false, length = 50)
private String address3;

}
2 changes: 0 additions & 2 deletions src/main/java/team7/inplace/place/domain/Coordinate.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Embeddable
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Getter
public class Coordinate {

Expand Down
8 changes: 3 additions & 5 deletions src/main/java/team7/inplace/place/domain/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,24 @@
import jakarta.persistence.Column;
import jakarta.persistence.Embeddable;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.ColumnDefault;

@Embeddable
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode
@Getter
public class Menu {

@Column(columnDefinition = "NUMBER")
@Column(columnDefinition = "NUMBER", nullable = false)
private Long price;

@ColumnDefault("false")
@Column
@Column(nullable = false)
private boolean recommend;

@Column(length = 50)
@Column(length = 50, nullable = false)
private String menuName;

}
13 changes: 7 additions & 6 deletions src/main/java/team7/inplace/place/domain/Place.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ public class Place {
private Coordinate coordinate;

@ElementCollection
@CollectionTable(name = "place_times", joinColumns = @JoinColumn(name = "place_id"))
private List<PlaceTime> timeList;
@CollectionTable(name = "place_open_times", joinColumns = @JoinColumn(name = "place_id", nullable = false))
private List<PlaceOpenTime> timeList;

@ElementCollection
@CollectionTable(name = "menus", joinColumns = @JoinColumn(name = "place_id"))
private List<Menu> menuList;

// influencerName, likes 기능은 추후 추가 예정
@CollectionTable(name = "place_close_times", joinColumns = @JoinColumn(name = "place_id", nullable = false))
private List<PlaceCloseTime> offdayList;

@ElementCollection
@CollectionTable(name = "menus", joinColumns = @JoinColumn(name = "place_id", nullable = false))
private List<Menu> menuList;
}
Loading

0 comments on commit 979c245

Please sign in to comment.