51 lines
1.8 KiB
Java
51 lines
1.8 KiB
Java
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.repository.PostRepository;
|
|
import com.krylov.refound.service.PostService;
|
|
import java.util.List;
|
|
import lombok.RequiredArgsConstructor;
|
|
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.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.RequestPart;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/posts")
|
|
@RequiredArgsConstructor
|
|
public class PostController {
|
|
|
|
private final PostService service;
|
|
|
|
@PostMapping(consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
public PostResponse create(@RequestPart("data") PostRequest request, @RequestPart(value = "files", required = false) List<MultipartFile> files) {
|
|
return service.create(request, files);
|
|
}
|
|
|
|
@GetMapping
|
|
public Page<PostResponse> getFeed(PostFilter filter, Pageable pageable) {
|
|
return service.getFeed(filter, pageable);
|
|
}
|
|
|
|
@PutMapping("/{id}")
|
|
public PostResponse update(@PathVariable Long id, @RequestBody PostRequest request) {
|
|
return service.update(id, request);
|
|
}
|
|
|
|
@DeleteMapping("/{id}")
|
|
public void delete(@PathVariable Long id) {
|
|
service.delete(id);
|
|
}
|
|
}
|