Skip to content

Commit

Permalink
Merge pull request #124 from kookmin-sw/backend/develop/v3
Browse files Browse the repository at this point in the history
✨ 카드뷰에 이미지URL 추가
  • Loading branch information
J-Yong99 authored Apr 30, 2024
2 parents 5d30ed6 + 7e64d5d commit cff7a99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class CardView extends BaseEntity {

// STT
@Column(name = "stt")
@Lob
private String stt;

// happy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ public static class GetCardView {
@Schema(description = "분석 상태")
private final String recordFileStatus;

private List<String> imageUrls;

// fromEntity
public static GetCardView fromEntity(CardView cardView) {
public static GetCardView fromEntity(CardView cardView, List<String> imageUrls) {
return GetCardView.builder()
.Id(cardView.getId())
.tripFileId(cardView.getTripFile().getId())
Expand All @@ -90,6 +92,7 @@ public static GetCardView fromEntity(CardView cardView) {
.question(cardView.getQuestion())
.isLoved(cardView.getIsLoved())
.recordFileStatus(cardView.getRecordFileStatus())
.imageUrls(imageUrls)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public CardViewResponseDTO.GetCardView uploadRecord(CardViewRequestDTO.UploadRec
// tripFile, trip의 analyzingCount 증가
tripFileService.increaseAnalyzingCount(tripFile);
tripService.increaseAnalyzingCount(tripFile.getTrip());

return CardViewResponseDTO.GetCardView.fromEntity(cardViewRepository.save(cardView));
List<String> imageUrls = new ArrayList<>();
return CardViewResponseDTO.GetCardView.fromEntity(cardViewRepository.save(cardView), imageUrls);
}

private String createFileName(String originalFilename) {
Expand All @@ -122,7 +122,8 @@ public CardViewResponseDTO.GetAllCardView getAllCardView(Long userId, Long tripF
List<CardViewResponseDTO.GetCardView> rtnList = new ArrayList<>();
List<CardView> cardViews = cardViewRepository.findAllByTripFile_IdOrderByRecordedAt(tripFileId);
for (CardView cardView : cardViews) {
rtnList.add(CardViewResponseDTO.GetCardView.fromEntity(cardView));
List<String> imageUrls = imageFileService.getImageUrls(cardView);
rtnList.add(CardViewResponseDTO.GetCardView.fromEntity(cardView, imageUrls));
}
return CardViewResponseDTO.GetAllCardView.builder().cardViews(rtnList).build();
}
Expand Down Expand Up @@ -185,7 +186,8 @@ public CardViewResponseDTO.GetAllCardView getLikeCardView(Long userId) {
List<CardViewResponseDTO.GetCardView> rtnList = new ArrayList<>();
List<CardView> cardViews = cardViewRepository.findByTripFile_User_IdAndIsLovedOrderByRecordedAt(userId, true);
for (CardView cardView : cardViews) {
rtnList.add(CardViewResponseDTO.GetCardView.fromEntity(cardView));
List<String> imageUrls = imageFileService.getImageUrls(cardView);
rtnList.add(CardViewResponseDTO.GetCardView.fromEntity(cardView, imageUrls));
}
return CardViewResponseDTO.GetAllCardView.builder().cardViews(rtnList).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public void deleteImages(List<Long> images, Long userId) {
imageFileRepository.delete(image);
}
}

public List<String> getImageUrls(CardView cardView) {
List<ImageFile> imageFiles = imageFileRepository.findAllByCardView(cardView);
return imageFiles.stream().map(ImageFile::getFileUrl).toList();
}
}

0 comments on commit cff7a99

Please sign in to comment.