From 762bb8b97fdb6b3c9511a1c08150e62519651331 Mon Sep 17 00:00:00 2001 From: Dmitry Isaenko Date: Sat, 27 Jan 2024 22:49:17 +0300 Subject: [PATCH] Add create function --- .../marinesco/library/api/GenresApiController.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/ru/redrise/marinesco/library/api/GenresApiController.java b/src/main/java/ru/redrise/marinesco/library/api/GenresApiController.java index 87e368a..6a7a8c9 100644 --- a/src/main/java/ru/redrise/marinesco/library/api/GenresApiController.java +++ b/src/main/java/ru/redrise/marinesco/library/api/GenresApiController.java @@ -2,9 +2,13 @@ package ru.redrise.marinesco.library.api; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort; +import org.springframework.http.HttpStatus; 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.RequestParam; +import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.bind.annotation.RestController; import ru.redrise.marinesco.data.GenreRepository; @@ -29,5 +33,10 @@ public class GenresApiController { return genreRepository.findAll(pageRequest).getContent(); } - + @PostMapping(consumes = "application/json") + @ResponseStatus(HttpStatus.CREATED) + public Genre postGenre(@RequestBody Genre genre) { + return genreRepository.save(genre); + } + }