Skip to content

Commit

Permalink
Merge branch 'feat/#60' into develop
Browse files Browse the repository at this point in the history
# Conflicts:
#	outbound/src/main/java/com/pocket/outbound/repository/album/AlbumRepository.java
  • Loading branch information
Jeongh00 committed Nov 6, 2024
2 parents 368efb2 + f8baabe commit 8827ccd
Show file tree
Hide file tree
Showing 18 changed files with 258 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.photobooth;

public record PhotoBoothVisitedDto(
Long photoboothId,
String name,
Integer month,
Integer date
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pocket.domain.dto.review;

public record ReviewMypageDetailDto(
Long reviewId,
String imageUrl,
Integer month,
Integer date,
String photoboothName,
Double rating
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.dto.review;

import java.util.List;

public record ReviewMypageDto(
int reviewCount,
List<ReviewMypageDetailDto> reviewMypageDetailDtoList
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pocket.domain.port.photobooth;

import com.pocket.domain.dto.photobooth.PhotoBoothVisitedDto;

import java.util.List;

public interface PhotoBoothVisitedPort {

List<PhotoBoothVisitedDto> getVisitedPhotoBooths(String userEmail);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.port.review;

import com.pocket.domain.dto.review.ReviewMypageDto;

public interface ReviewMypagePort {

ReviewMypageDto reviewMypage(String userEmail);

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package com.pocket.domain.service.photobooth;

import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.dto.photobooth.PhotoBoothModalDto;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.dto.photobooth.*;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.domain.port.photobooth.*;
import com.pocket.domain.usecase.photobooth.*;
Expand All @@ -16,13 +13,14 @@

@Service
@RequiredArgsConstructor
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase {
public class PhotoBoothService implements PhotoBoothFindUseCase, PhotoBoothGetNameUseCase, PhotoBoothGetRatingUseCase, PhotoBoothSearchUseCase, PhotoBoothGetModalUseCase, PhotoBoothVisitedUseCase {

private final PhotoBoothFindPort photoBoothFindPort;
private final PhotoBoothGetRatingPort photoBoothGetRatingPort;
private final PhotoBoothGetNamePort photoBoothGetNamePort;
private final PhotoBoothSearchPort photoBoothSearchPort;
private final PhotoBoothGetModalPort photoBoothGetModalPort;
private final PhotoBoothVisitedPort photoBoothVisitedPort;

public PhotoBoothFindResponseDto findPhotoBoothResponse(Long id) {
return photoBoothFindPort.findById(id);
Expand All @@ -47,4 +45,9 @@ public List<PhotoBoothSearchDto> searchPhotoBooth(String keyword) {
public PhotoBoothModalDto getPhotoBoothModal(Long photoboothId) {
return photoBoothGetModalPort.getPhotoBoothModal(photoboothId);
}

@Override
public List<PhotoBoothVisitedDto> getVisitedPhotoBooths(String userEmail) {
return photoBoothVisitedPort.getVisitedPhotoBooths(userEmail);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

@DomainService
@RequiredArgsConstructor
public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUseCase, ReviewGetRecentUseCase, ReviewGetAllImagesUseCase, ReviewBoothFeatureCountUseCase, ReviewPhotoFeatureCountUseCase, ReviewGetBoothFeatureUseCase, ReviewGetPhotoFeatureUseCase, ReviewGetAllUseCase
public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUseCase, ReviewGetRecentUseCase, ReviewGetAllImagesUseCase, ReviewBoothFeatureCountUseCase, ReviewPhotoFeatureCountUseCase, ReviewGetBoothFeatureUseCase, ReviewGetPhotoFeatureUseCase, ReviewGetAllUseCase, ReviewMypageUseCase


{

Expand All @@ -28,6 +29,7 @@ public class ReviewService implements ReviewRegisterUseCase, ReviewGet6ImagesUse
private final ReviewGetPhotoFeaturePort reviewGetPhotoFeaturePort;
private final ReviewGetAllPort reviewGetAllPort;
private final FileDownloadPort fileDownloadPort;
private final ReviewMypagePort reviewMypagePort;

@Override
public ReviewRegisterResponseDto registerReviewResponse(ReviewRegisterRequestDto reviewRegisterRequestDto, String name) {
Expand Down Expand Up @@ -119,4 +121,21 @@ public ReviewGetResponseDto getAllReviews(Long photoboothId, Pageable pageable)

return new ReviewGetResponseDto(response.reviewCount(), reviewPreviewsWithPresignedUrls);
}

@Override
public ReviewMypageDto reviewMypage(String userEmail) {
ReviewMypageDto response = reviewMypagePort.reviewMypage(userEmail);
List<ReviewMypageDetailDto> reviewMypageWithPresignedUrls = response.reviewMypageDetailDtoList().stream().map(review -> {
String presignedUrl = review.imageUrl().isEmpty() ? "" : fileDownloadPort.getDownloadPresignedUrl(review.imageUrl());
return new ReviewMypageDetailDto(
review.reviewId(),
presignedUrl,
review.month(),
review.date(),
review.photoboothName(),
review.rating()
);
}) .collect(Collectors.toList());
return new ReviewMypageDto(response.reviewCount(), reviewMypageWithPresignedUrls);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.pocket.domain.usecase.photobooth;

import com.pocket.domain.dto.photobooth.PhotoBoothVisitedDto;

import java.util.List;

public interface PhotoBoothVisitedUseCase {

List<PhotoBoothVisitedDto> getVisitedPhotoBooths(String userEmail);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.pocket.domain.usecase.review;

import com.pocket.domain.dto.review.ReviewMypageDto;

public interface ReviewMypageUseCase {

ReviewMypageDto reviewMypage(String userEmail);

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.pocket.inbounds.photobooth.presentation;

import com.pocket.core.exception.common.ApplicationResponse;
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.dto.photobooth.PhotoBoothModalDto;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.dto.photobooth.*;
import com.pocket.domain.dto.user.UserInfoDTO;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import com.pocket.domain.port.photobooth.PhotoBoothGetNamePort;
import com.pocket.domain.usecase.photobooth.*;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
Expand All @@ -24,6 +23,7 @@ public class PhotoBoothController implements PhotoBoothControllerDocs {
private final PhotoBoothGetNameUseCase photoBoothGetNameUseCase;
private final PhotoBoothSearchUseCase photoBoothSearchUseCase;
private final PhotoBoothGetModalUseCase photoBoothGetModalUseCase;
private final PhotoBoothVisitedUseCase photoBoothVisitedUseCase;

@GetMapping("{id}")
public ApplicationResponse<PhotoBoothFindResponseDto> getPhotoBoothById(@PathVariable("id") Long id) {
Expand Down Expand Up @@ -66,4 +66,12 @@ public ApplicationResponse<PhotoBoothModalDto> getPhotoBoothModal(@PathVariable(
PhotoBoothModalDto response = photoBoothGetModalUseCase.getPhotoBoothModal(id);
return ApplicationResponse.ok(response);
}

@GetMapping("/visited")
public ApplicationResponse<List<PhotoBoothVisitedDto>> getPhotoBoothVisited(
@AuthenticationPrincipal UserInfoDTO user
) {
List<PhotoBoothVisitedDto> response = photoBoothVisitedUseCase.getVisitedPhotoBooths(user.email());
return ApplicationResponse.ok(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@

import com.nimbusds.oauth2.sdk.ErrorResponse;
import com.pocket.core.exception.common.ApplicationResponse;
import com.pocket.domain.dto.photobooth.NearPhotoBoothInfo;
import com.pocket.domain.dto.photobooth.PhotoBoothFindResponseDto;
import com.pocket.domain.dto.photobooth.PhotoBoothModalDto;
import com.pocket.domain.dto.photobooth.PhotoBoothSearchDto;
import com.pocket.domain.dto.photobooth.*;
import com.pocket.domain.dto.user.UserInfoDTO;
import com.pocket.domain.entity.photobooth.PhotoBoothBrand;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;

Expand Down Expand Up @@ -93,4 +92,16 @@ ApplicationResponse<PhotoBoothModalDto> getPhotoBoothModal(
@PathVariable("id") Long id
);

@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))})
})
@Operation(summary = "방문한 포토부스 조회", description = "앨범에는 저장됐지만, 리뷰가 작성되지 않은 포토부스 조회")
ApplicationResponse<List<PhotoBoothVisitedDto>> getPhotoBoothVisited(
@AuthenticationPrincipal UserInfoDTO user
);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class ReviewController implements ReviewControllerDocs {
private final ReviewGetBoothFeatureUseCase reviewGetBoothFeatureUseCase;
private final ReviewGetPhotoFeatureUseCase reviewGetPhotoFeatureUseCase;
private final ReviewGetAllUseCase reviewGetAllUseCase;
private final ReviewMypageUseCase reviewMypageUseCase;

@PostMapping
public ApplicationResponse<ReviewRegisterResponseDto> postReview(
Expand Down Expand Up @@ -98,4 +99,12 @@ public ApplicationResponse<ReviewGetResponseDto> getAllReviews(
return ApplicationResponse.ok(response);
}

@GetMapping("/mypage")
public ApplicationResponse<ReviewMypageDto> getReviewMypage(
@AuthenticationPrincipal UserInfoDTO user
) {
ReviewMypageDto response = reviewMypageUseCase.reviewMypage(user.email());
return ApplicationResponse.ok(response);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,17 @@ ApplicationResponse<ReviewGetResponseDto> getAllReviews(
@ParameterObject Pageable pageable
);


@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "400", description = "BAD REQUEST",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))}),
@ApiResponse(responseCode = "500", description = "INTERNAL SERVER ERROR",
content = {@Content(schema = @Schema(implementation = ErrorResponse.class))})
})
@Operation(summary = "마이페이지 나의 리뷰 조회", description = "나의 리뷰 조회(날짜, 이름, 별점)")
ApplicationResponse<ReviewMypageDto> getReviewMypage(
@AuthenticationPrincipal UserInfoDTO user
);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.pocket.outbound.adapter.photobooth.adapter;

import com.pocket.core.aop.annotation.AdapterService;
import com.pocket.domain.dto.photobooth.PhotoBoothVisitedDto;
import com.pocket.domain.port.photobooth.PhotoBoothVisitedPort;
import com.pocket.outbound.entity.album.JpaAlbum;
import com.pocket.outbound.entity.photobooth.JpaPhotoBooth;
import com.pocket.outbound.entity.review.JpaReview;
import com.pocket.outbound.repository.album.AlbumRepository;
import com.pocket.outbound.repository.review.ReviewRepository;
import lombok.RequiredArgsConstructor;

import java.time.LocalDate;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@AdapterService
@RequiredArgsConstructor
public class PhotoBoothVisitedAdapter implements PhotoBoothVisitedPort {

private final AlbumRepository albumRepository;
private final ReviewRepository reviewRepository;

@Override
public List<PhotoBoothVisitedDto> getVisitedPhotoBooths(String userEmail) {
List<JpaAlbum> allAlbums = albumRepository.findByJpaUser_User_Email(userEmail);
List<JpaReview> allReviews = reviewRepository.findByJpaUser_User_Email(userEmail);

// 모든 JpaPhotoBooth를 추출하여 Set으로 변환
Set<JpaPhotoBooth> reviewPhotoBooths = allReviews.stream()
.map(JpaReview::getPhotoBooth)
.collect(Collectors.toSet());

// allAlbums에서 reviewPhotoBooths에 없는 JpaPhotoBooth만 필터링하여 리스트로 수집
List<PhotoBoothVisitedDto> photoBoothVisitedDtos = allAlbums.stream()
.filter(album -> !reviewPhotoBooths.contains(album.getPhotoBooth()))
.map(album -> {
JpaPhotoBooth jpaPhotoBooth = album.getPhotoBooth();
Long photoboothId = jpaPhotoBooth.getId();
String name = jpaPhotoBooth.getPhotoBooth().getName();

// JpaAlbum의 createdAt 필드에서 월과 일 정보 추출
LocalDate createdAt = album.getImage().getCreatedAt().toLocalDate();
Integer month = createdAt.getMonthValue();
Integer date = createdAt.getDayOfMonth();

return new PhotoBoothVisitedDto(photoboothId, name, month, date);
})
.collect(Collectors.toList());

return photoBoothVisitedDtos;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.pocket.outbound.adapter.review.adapter;


import com.pocket.core.aop.annotation.AdapterService;
import com.pocket.domain.dto.review.ReviewMypageDetailDto;
import com.pocket.domain.dto.review.ReviewMypageDto;
import com.pocket.domain.port.review.ReviewMypagePort;
import com.pocket.outbound.entity.review.JpaReview;
import com.pocket.outbound.entity.review.JpaReviewImage;
import com.pocket.outbound.repository.review.ReviewImageRepository;
import com.pocket.outbound.repository.review.ReviewRepository;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import static com.amazonaws.services.ec2.model.ResourceType.Image;

@AdapterService
@RequiredArgsConstructor
public class ReviewMypageAdapter implements ReviewMypagePort {

private final ReviewRepository reviewRepository;
private final ReviewImageRepository reviewImageRepository;

@Override
public ReviewMypageDto reviewMypage(String userEmail) {
List<JpaReview> jpaReviews = reviewRepository.findByJpaUser_User_Email(userEmail);

List<ReviewMypageDetailDto> reviewMypageDetailDtos = new ArrayList<>();

for (JpaReview jpaReview : jpaReviews) {

JpaReviewImage reviewImage = reviewImageRepository.findTop1ByReviewIdOrderByReviewIdDesc(jpaReview.getId());
String imageUrl = (reviewImage != null && reviewImage.getImage() != null) ? reviewImage.getImage().getImageUrl() : "";


reviewMypageDetailDtos.add(new ReviewMypageDetailDto(
jpaReview.getId(),
imageUrl,
jpaReview.getReview().getCreatedAt().getMonthValue(),
jpaReview.getReview().getCreatedAt().getDayOfMonth(),
jpaReview.getPhotoBooth().getPhotoBooth().getName(),
jpaReview.getPhotoBooth().getRating().doubleValue()
));
}

return new ReviewMypageDto(jpaReviews.size(), reviewMypageDetailDtos);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public interface AlbumRepository extends JpaRepository<JpaAlbum, Long> {

List<JpaAlbum> findByJpaUserUserEmail(String userEmail);

List<JpaAlbum> findByJpaUser_User_Email(String email);

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public interface ReviewImageRepository extends JpaRepository<JpaReviewImage, Lon

List<JpaReviewImage> findTop6ByReviewPhotoBoothIdOrderByReviewIdDesc(Long photoboothId);

JpaReviewImage findTop1ByReviewIdOrderByReviewIdDesc(Long reviewId);

int countByReviewPhotoBoothId(Long photoboothId);

List<JpaReviewImage> findByReviewId(Long reviewId);
Expand Down
Loading

0 comments on commit 8827ccd

Please sign in to comment.