diff --git a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/controller/review/ReviewController.java b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/controller/review/ReviewController.java index 20b3a67..383dcf7 100644 --- a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/controller/review/ReviewController.java +++ b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/controller/review/ReviewController.java @@ -3,12 +3,15 @@ import com.skhuthon.skhuthon_0th_team9.app.dto.review.requestDto.ReviewCreateRequestDto; import com.skhuthon.skhuthon_0th_team9.app.dto.review.responseDto.ReviewCreateResponseDto; import com.skhuthon.skhuthon_0th_team9.app.service.review.ReviewCreateService; +import com.skhuthon.skhuthon_0th_team9.app.service.review.ReviewSearchService; import com.skhuthon.skhuthon_0th_team9.global.common.dto.ApiResponseTemplate; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestPart; @@ -25,6 +28,8 @@ public class ReviewController { private final ReviewCreateService reviewCreateService; + private final ReviewSearchService reviewSeService; + private final ReviewSearchService reviewSearchService; @PostMapping("/create") @Operation( @@ -45,4 +50,38 @@ public ResponseEntity> createReview return ResponseEntity.status(data.getStatus()).body(data); } + + @GetMapping("/get/all") + @Operation( + summary = "모든 리뷰 조회", + description = "모든 리뷰를 조회합니다.", + responses = { + @ApiResponse(responseCode = "200", description = "리뷰 조회 성공"), + @ApiResponse(responseCode = "403", description = "url문제 or 관리자 문의"), + @ApiResponse(responseCode = "500", description = "토큰 문제 or 관리자 문의") + } + ) + public ResponseEntity>> getAllReviews(Principal principal){ + + ApiResponseTemplate> data = reviewSearchService.getAllReviews(principal); + + return ResponseEntity.status(data.getStatus()).body(data); + } + + @GetMapping("/get/{categoryId}") + @Operation( + summary = "카테고리별 리뷰 조회", + description = "카테고리별 리뷰를 조회합니다.", + responses = { + @ApiResponse(responseCode = "200", description = "리뷰 조회 성공"), + @ApiResponse(responseCode = "403", description = "url문제 or 관리자 문의"), + @ApiResponse(responseCode = "500", description = "토큰 문제 or 관리자 문의") + } + ) + public ResponseEntity>> getReviewsByCategoryId(@PathVariable Long categoryId, Principal principal) { + + ApiResponseTemplate> data = reviewSearchService.getReviewsByDepartmentCategory(categoryId); + + return ResponseEntity.status(data.getStatus()).body(data); + } } diff --git a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/dto/review/responseDto/ReviewSearchResponseDto.java b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/dto/review/responseDto/ReviewSearchResponseDto.java new file mode 100644 index 0000000..8dfbc2f --- /dev/null +++ b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/dto/review/responseDto/ReviewSearchResponseDto.java @@ -0,0 +1,25 @@ +package com.skhuthon.skhuthon_0th_team9.app.dto.review.responseDto; + +import com.skhuthon.skhuthon_0th_team9.app.domain.category.DepartmentCategory; +import com.skhuthon.skhuthon_0th_team9.app.domain.category.DetailCategory; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; +import java.util.List; + +@Getter +@Builder +public class ReviewSearchResponseDto { + + private Long id; + private String title; + private String description; + private List imageUrls; + private LocalDateTime createAt; + private LocalDateTime modifiedAt; + private Long userId; + private DepartmentCategory departmentCategory; + private DetailCategory detailCategory; + +} diff --git a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/repository/ReviewRepository.java b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/repository/ReviewRepository.java index 625a98d..d2658e8 100644 --- a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/repository/ReviewRepository.java +++ b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/repository/ReviewRepository.java @@ -3,5 +3,9 @@ import com.skhuthon.skhuthon_0th_team9.app.domain.review.Review; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface ReviewRepository extends JpaRepository { + + List findByDepartmentCategoryId(Long departmentCategoryId); } diff --git a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/service/review/ReviewSearchService.java b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/service/review/ReviewSearchService.java new file mode 100644 index 0000000..547bff5 --- /dev/null +++ b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/app/service/review/ReviewSearchService.java @@ -0,0 +1,72 @@ +package com.skhuthon.skhuthon_0th_team9.app.service.review; + +import com.skhuthon.skhuthon_0th_team9.app.domain.review.Review; +import com.skhuthon.skhuthon_0th_team9.app.dto.review.responseDto.ReviewCreateResponseDto; +import com.skhuthon.skhuthon_0th_team9.app.repository.ReviewRepository; +import com.skhuthon.skhuthon_0th_team9.global.common.dto.ApiResponseTemplate; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.security.Principal; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +public class ReviewSearchService { + + private final ReviewRepository reviewRepository; + + @Transactional(readOnly = true) + public ApiResponseTemplate> getAllReviews(Principal principal) { + List reviews = reviewRepository.findAll(); + + List reviewCreateResponseDtos = reviews.stream() + .map(review -> ReviewCreateResponseDto.builder() + .id(review.getId()) + .title(review.getTitle()) + .description(review.getDescription()) + .imageUrls(review.getImageUrls()) + .createAt(review.getCreateAt()) + .modifiedAt(review.getModifiedAt()) + .userId(review.getUser().getId()) + .departmentCategory(review.getDepartmentCategory()) + .detailCategory(review.getDetailCategory()) + .build()) + .collect(Collectors.toList()); + + return ApiResponseTemplate.>builder() + .status(200) + .success(true) + .message("리뷰 조회 성공") + .data(reviewCreateResponseDtos) + .build(); + } + + @Transactional(readOnly = true) + public ApiResponseTemplate> getReviewsByDepartmentCategory(Long departmentCategoryId){ + List reviews = reviewRepository.findByDepartmentCategoryId(departmentCategoryId); + + List reviewCreateResponseDtos = reviews.stream() + .map(review -> ReviewCreateResponseDto.builder() + .id(review.getId()) + .title(review.getTitle()) + .description(review.getDescription()) + .imageUrls(review.getImageUrls()) + .createAt(review.getCreateAt()) + .modifiedAt(review.getModifiedAt()) + .userId(review.getUser().getId()) + .departmentCategory(review.getDepartmentCategory()) + .detailCategory(review.getDetailCategory()) + .build()) + .collect(Collectors.toList()); + + return ApiResponseTemplate.>builder() + .status(200) + .success(true) + .message("리뷰 조회 성공") + .data(reviewCreateResponseDtos) + .build(); + } +} diff --git a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/global/jwt/TokenProvider.java b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/global/jwt/TokenProvider.java index 3917468..9d08781 100644 --- a/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/global/jwt/TokenProvider.java +++ b/Skhuthon_0th_TEAM9/src/main/java/com/skhuthon/skhuthon_0th_team9/global/jwt/TokenProvider.java @@ -46,7 +46,7 @@ public String createAccessToken(String subject, UserAccessLevel userAccessLevel) .claim("userLevel", userAccessLevel) .setIssuedAt(now) .setExpiration(tokenExpiredTime) - .signWith(key, SignatureAlgorithm.HS512) + .signWith(key, SignatureAlgorithm.HS256) .compact(); } @@ -59,7 +59,7 @@ public String createRefreshToken(String subject, UserAccessLevel userAccessLevel .claim("userLevel", userAccessLevel) .setIssuedAt(now) .setExpiration(tokenExpiredTime) - .signWith(key, SignatureAlgorithm.HS512) + .signWith(key, SignatureAlgorithm.HS256) .compact(); }