Files
nahodka-back/src/main/java/com/krylov/refound/controller/ReviewsController.java
2026-07-31 01:08:53 +03:00

39 lines
1.3 KiB
Java

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<ReviewResponseDto> 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());
}
}