added reviews

This commit is contained in:
SlimusMinus
2026-06-23 00:09:57 +03:00
parent c80cbdf976
commit c49f2d108b
11 changed files with 181 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
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;
@RestController
@RequestMapping("/api/v1/reviews")
@RequiredArgsConstructor
@Slf4j
public class ReviewsController {
private final ReviewService reviewService;
@GetMapping
public List<ReviewResponseDto> getAllReviews() {
List<ReviewResponseDto> allReviews = reviewService.getAllReviews();
log.info("Got all reviews: {}", allReviews);
return allReviews;
}
@PostMapping
@PreAuthorize("isAuthenticated()")
public ReviewResponseDto createReview(@Valid @RequestBody ReviewRequestDto request, Authentication authentication) {
// Взять имя пользователя из authentication
return reviewService.createReview(request, authentication.getName());
}
}