Skip to content

Commit

Permalink
Merge pull request #3 from jjekrrq/main
Browse files Browse the repository at this point in the history
카테고리 하나로 리뷰 조회
  • Loading branch information
woogym authored Jun 29, 2024
2 parents 1f6f5f5 + 469a631 commit 7331b11
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.security.Principal;
Expand Down Expand Up @@ -45,4 +42,16 @@ public ResponseEntity<ApiResponseTemplate<ReviewCreateResponseDto>> createReview

return ResponseEntity.status(data.getStatus()).body(data);
}
// public ResponseEntity<ApiResponseTemplate<List<ReviewCreateResponseDto>>> getAllReviews(){
//
// }
@GetMapping("/get/all")
public List<ReviewCreateResponseDto> getAllReviews(){
return reviewCreateService.getAllReviews();
}

@GetMapping("/get/{categoryId}")
public List<ReviewCreateResponseDto> getReviewsByCategoryId(@PathVariable Long categoryId){
return reviewCreateService.getReviewsByDepartmentCategory(categoryId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
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<Review, Long> {
List<Review> findByDepartmentCategoryId(Long departmentCategoryId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,42 @@ private ReviewCreateResponseDto createReviewCreateResponseDto(Review review) {
.detailCategory(review.getDetailCategory())
.build();
}
public List<ReviewCreateResponseDto> getAllReviews(){
List<Review> reviews = reviewRepository.findAll();

List<ReviewCreateResponseDto> 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 reviewCreateResponseDtos;
}
public List<ReviewCreateResponseDto> getReviewsByDepartmentCategory(Long departmentCategoryId){
List<Review> reviews = reviewRepository.findByDepartmentCategoryId(departmentCategoryId);

List<ReviewCreateResponseDto> 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 reviewCreateResponseDtos;
}
}

0 comments on commit 7331b11

Please sign in to comment.