use of com.furyviewer.domain.Genre in project FuryViewer by TheDoctor-95.
the class GenreResource method createGenre.
/**
* POST /genres : Create a new genre.
*
* @param genre the genre to create
* @return the ResponseEntity with status 201 (Created) and with body the new genre, or with status 400 (Bad Request) if the genre has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/genres")
@Timed
public ResponseEntity<Genre> createGenre(@RequestBody Genre genre) throws URISyntaxException {
log.debug("REST request to save Genre : {}", genre);
if (genre.getId() != null) {
throw new BadRequestAlertException("A new genre cannot already have an ID", ENTITY_NAME, "idexists");
}
Genre result = genreRepository.save(genre);
return ResponseEntity.created(new URI("/api/genres/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.furyviewer.domain.Genre in project FuryViewer by TheDoctor-95.
the class GenreService method importGenre.
/**
* Metodo que se encarga de convertir un String en los objetos de la clase Genre necesarios.
* @param genreList String | Contiene el nombre de los genre.
* @return Set | Set que contiene la informacion de los genres.
*/
public Set<Genre> importGenre(String genreList) {
Set<Genre> genreListArray = new HashSet<>();
if (stringApiCorrectorService.eraserNA(genreList) != null) {
String[] genres = genreList.split(", ");
for (String genreStr : genres) {
Optional<Genre> genreOptional = genreRepository.findByName(genreStr);
Genre genre;
if (genreOptional.isPresent()) {
genre = genreOptional.get();
} else {
genre = new Genre();
genre.setName(genreStr);
genre = genreRepository.save(genre);
}
genreListArray.add(genre);
}
}
return genreListArray;
}
Aggregations