Skip to content

Commit

Permalink
refactor: modify etc
Browse files Browse the repository at this point in the history
  • Loading branch information
woogym committed Jul 1, 2024
1 parent 7331b11 commit e42ae80
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,6 +28,8 @@
public class ReviewController {

private final ReviewCreateService reviewCreateService;
private final ReviewSearchService reviewSeService;
private final ReviewSearchService reviewSearchService;

@PostMapping("/create")
@Operation(
Expand All @@ -45,4 +50,38 @@ public ResponseEntity<ApiResponseTemplate<ReviewCreateResponseDto>> 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<ApiResponseTemplate<List<ReviewCreateResponseDto>>> getAllReviews(Principal principal){

ApiResponseTemplate<List<ReviewCreateResponseDto>> 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<ApiResponseTemplate<List<ReviewCreateResponseDto>>> getReviewsByCategoryId(@PathVariable Long categoryId, Principal principal) {

ApiResponseTemplate<List<ReviewCreateResponseDto>> data = reviewSearchService.getReviewsByDepartmentCategory(categoryId);

return ResponseEntity.status(data.getStatus()).body(data);
}
}
Original file line number Diff line number Diff line change
@@ -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<String> imageUrls;
private LocalDateTime createAt;
private LocalDateTime modifiedAt;
private Long userId;
private DepartmentCategory departmentCategory;
private DetailCategory detailCategory;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Review, Long> {

List<Review> findByDepartmentCategoryId(Long departmentCategoryId);
}
Original file line number Diff line number Diff line change
@@ -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<List<ReviewCreateResponseDto>> getAllReviews(Principal principal) {
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 ApiResponseTemplate.<List<ReviewCreateResponseDto>>builder()
.status(200)
.success(true)
.message("리뷰 조회 성공")
.data(reviewCreateResponseDtos)
.build();
}

@Transactional(readOnly = true)
public ApiResponseTemplate<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 ApiResponseTemplate.<List<ReviewCreateResponseDto>>builder()
.status(200)
.success(true)
.message("리뷰 조회 성공")
.data(reviewCreateResponseDtos)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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();
}

Expand Down

0 comments on commit e42ae80

Please sign in to comment.