added reviews
This commit is contained in:
@@ -8,6 +8,7 @@ import java.util.List;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
@@ -29,10 +30,7 @@ public class PostController {
|
||||
private final PostService service;
|
||||
|
||||
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
||||
public PostRequest create(
|
||||
@ModelAttribute PostRequest request,
|
||||
@RequestPart(value = "image", required = false) MultipartFile image
|
||||
) {
|
||||
public PostRequest create(@ModelAttribute PostRequest request, @RequestPart(value = "image", required = false) MultipartFile image) {
|
||||
log.info(request.toString());
|
||||
return service.create(request, image);
|
||||
}
|
||||
|
||||
@@ -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