package com.krylov.refound.controller; import com.krylov.refound.dto.ReviewRequestDto; import com.krylov.refound.dto.ReviewResponseDto; import com.krylov.refound.service.ReviewService; import jakarta.validation.Valid; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.core.Authentication; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("/api/v1/reviews") @RequiredArgsConstructor public class ReviewsController { private final ReviewService reviewService; @GetMapping public List getAllReviews() { log.info("get all reviews"); return reviewService.getAllReviews(); } @PostMapping @PreAuthorize("isAuthenticated()") public ReviewResponseDto createReview(@Valid @RequestBody ReviewRequestDto request, Authentication authentication) { log.info("user {} create review {}", authentication.getName(), request); return reviewService.createReview(request, authentication.getName()); } }