Skip to content

Commit

Permalink
[FEAT] #220 - 카페 조회 시 List<CafeImageRes>가 아닌 List<String>으로 전달
Browse files Browse the repository at this point in the history
  • Loading branch information
kimahhh committed Jun 3, 2023
1 parent cacd0ea commit 52ccc90
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
7 changes: 3 additions & 4 deletions src/main/java/shop/cazait/domain/cafe/dto/GetCafesRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import lombok.Builder;
import lombok.Getter;
import shop.cazait.domain.cafe.entity.Cafe;
import shop.cazait.domain.cafeimage.dto.GetCafeImageRes;
import shop.cazait.domain.congestion.entity.CongestionStatus;

import java.util.List;
Expand Down Expand Up @@ -35,23 +34,23 @@ public class GetCafesRes {
private String latitude;
@JsonProperty
@Schema(description = "이미지 url")
private List<GetCafeImageRes> getCafeImageRes;
private List<String> cafeImages;
@JsonProperty
@Schema(description = "거리", example = "200m")
private int distance;
@JsonProperty
@Schema(description = "관심 카페 여부", example = "true")
private boolean favorite;

public static GetCafesRes of(Cafe cafe, List<GetCafeImageRes> getCafeImageRes, int distance, boolean favorite) {
public static GetCafesRes of(Cafe cafe, List<String> cafeImages, int distance, boolean favorite) {
return GetCafesRes.builder()
.cafeId(cafe.getId())
.congestionStatus(cafe.getCongestion().getCongestionStatus())
.name(cafe.getName())
.address(cafe.getAddress())
.longitude(cafe.getCoordinate().getLongitude())
.latitude(cafe.getCoordinate().getLatitude())
.getCafeImageRes(getCafeImageRes)
.cafeImages(cafeImages)
.distance(distance)
.favorite(favorite)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private List<GetCafesRes> readCafeList(List<Cafe> cafeList, String longitude, St
List<GetCafesRes> cafeResList = cafeList.stream()
.map(cafe -> {
boolean favorite = false;
List<GetCafeImageRes> getCafeImageResList = cafeImageService.readCafeImageList(cafe.getId());
List<String> getCafeImageResList = cafeImageService.readCafeImageOnlyList(cafe.getId());

int distance = DistanceService.distance(cafe.getCoordinate().getLatitude(),
cafe.getCoordinate().getLongitude(),
Expand All @@ -213,7 +213,7 @@ private List<GetCafesRes> readCafeList(Long userId, List<Cafe> cafeList, String
break;
}
}
List<GetCafeImageRes> getCafeImageResList = cafeImageService.readCafeImageList(cafe.getId());
List<String> getCafeImageResList = cafeImageService.readCafeImageOnlyList(cafe.getId());

int distance = DistanceService.distance(cafe.getCoordinate().getLatitude(),
cafe.getCoordinate().getLongitude(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ public List<GetCafeImageRes> readCafeImageList(Long cafeId) {
return getCafeImageResList;
}

public List<String> readCafeImageOnlyList(Long cafeId) {
List<CafeImage> cafeImageList = cafeImageRepository.findByCafeId(cafeId);
List<String> getCafeImageResList = new ArrayList<>();
for (CafeImage cafeImage : cafeImageList) {
getCafeImageResList.add(cafeImage.getImageUrl());
}
return getCafeImageResList;
}

public void deleteCafeImage(Long cafeImageId, Long masterId) throws CafeImageException {
CafeImage cafeImage = cafeImageRepository.findById(cafeImageId).orElseThrow(() -> new CafeImageException(ErrorStatus.NOT_EXIST_IMAGE));
Master master = masterRepository.findById(masterId).orElseThrow(() -> new CafeException(NOT_EXIST_MASTER));
Expand Down

0 comments on commit 52ccc90

Please sign in to comment.