added reviews
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user