Add create function

This commit is contained in:
Dmitry Isaenko 2024-01-27 22:49:17 +03:00
parent 398bf16d56
commit 762bb8b97f

View file

@ -2,9 +2,13 @@ package ru.redrise.marinesco.library.api;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping; 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.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import ru.redrise.marinesco.data.GenreRepository; import ru.redrise.marinesco.data.GenreRepository;
@ -29,5 +33,10 @@ public class GenresApiController {
return genreRepository.findAll(pageRequest).getContent(); return genreRepository.findAll(pageRequest).getContent();
} }
@PostMapping(consumes = "application/json")
@ResponseStatus(HttpStatus.CREATED)
public Genre postGenre(@RequestBody Genre genre) {
return genreRepository.save(genre);
}
} }