Search in sources :

Example 6 with Genre

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);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) Genre(com.furyviewer.domain.Genre) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with Genre

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;
}
Also used : Genre(com.furyviewer.domain.Genre) HashSet(java.util.HashSet)

Aggregations

Genre (com.furyviewer.domain.Genre)7 Timed (com.codahale.metrics.annotation.Timed)3 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1 HashSet (java.util.HashSet)1