added image for post

This commit is contained in:
SlimusMinus
2026-06-01 01:57:16 +03:00
parent d4cb1ec2e3
commit 723e92baf1
9 changed files with 152 additions and 40 deletions

View File

@@ -1,24 +1,23 @@
package com.krylov.refound.controller;
import com.krylov.refound.dto.PostFilter;
import com.krylov.refound.dto.PostRequest;
import com.krylov.refound.dto.PostResponse;
import com.krylov.refound.entity.Post;
import com.krylov.refound.repository.PostRepository;
import com.krylov.refound.enums.PostType;
import com.krylov.refound.service.PostService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@@ -31,20 +30,38 @@ public class PostController {
private final PostService service;
@PostMapping
public PostRequest create(@RequestBody PostRequest request) {
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public PostRequest create(
@ModelAttribute PostRequest request,
@RequestPart(value = "image", required = false) MultipartFile image
) {
log.info(request.toString());
return service.create(request);
return service.create(request, image);
}
@GetMapping
public List<Post> getFeed() {
public List<PostResponse> getFeed() {
return service.getFeed();
}
@PutMapping("/{id}")
public PostResponse update(@PathVariable Long id, @RequestBody PostRequest request) {
return service.update(id, request);
@PutMapping(value = "/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public PostResponse update(
@PathVariable Long id,
@RequestParam String type,
@RequestParam String title,
@RequestParam(required = false) String description,
@RequestParam(required = false) String category,
@RequestParam(required = false) String phone,
@RequestParam(value = "image", required = false) MultipartFile image
) {
PostRequest request = new PostRequest();
request.setType(PostType.from(type));
request.setTitle(title);
request.setDescription(description);
request.setCategory(category);
request.setPhone(phone);
return service.update(id, request, image);
}
@DeleteMapping("/{id}")