Search in sources :

Example 1 with Genre

use of com.dubion.domain.Genre in project dubion by valsamiq.

the class GenreResource method updateGenre.

/**
 * PUT  /genres : Updates an existing genre.
 *
 * @param genre the genre to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated genre,
 * or with status 400 (Bad Request) if the genre is not valid,
 * or with status 500 (Internal Server Error) if the genre couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/genres")
@Timed
public ResponseEntity<Genre> updateGenre(@RequestBody Genre genre) throws URISyntaxException {
    log.debug("REST request to update Genre : {}", genre);
    if (genre.getId() == null) {
        return createGenre(genre);
    }
    Genre result = genreRepository.save(genre);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, genre.getId().toString())).body(result);
}
Also used : Genre(com.dubion.domain.Genre) NapsterGenre(com.dubion.service.dto.NapsterAPI.NapsterGenre) Timed(com.codahale.metrics.annotation.Timed)

Example 2 with Genre

use of com.dubion.domain.Genre in project dubion by valsamiq.

the class GenreResource method getGenre.

/**
 * GET  /genres/:id : get the "id" genre.
 *
 * @param id the id of the genre to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the genre, or with status 404 (Not Found)
 */
@GetMapping("/genres/{id}")
@Timed
public ResponseEntity<Genre> getGenre(@PathVariable Long id) {
    log.debug("REST request to get Genre : {}", id);
    Genre genre = genreRepository.findOne(id);
    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(genre));
}
Also used : Genre(com.dubion.domain.Genre) NapsterGenre(com.dubion.service.dto.NapsterAPI.NapsterGenre) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with Genre

use of com.dubion.domain.Genre in project dubion by valsamiq.

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.dubion.web.rest.errors.BadRequestAlertException) Genre(com.dubion.domain.Genre) NapsterGenre(com.dubion.service.dto.NapsterAPI.NapsterGenre) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with Genre

use of com.dubion.domain.Genre in project dubion by valsamiq.

the class NapsterDTOService method importGenres.

public List<Genre> importGenres() {
    NapsterGenre NapsterGenres = getGenres();
    List<Genre> genres = new ArrayList<>();
    for (com.dubion.service.dto.NapsterAPI.Genre.Genre t : NapsterGenres.getGenre()) {
        if (genreRepository.findByName(t.getName()) == null) {
            Genre s = new Genre();
            s.setName(t.getName());
            s = genreRepository.save(s);
            genres.add(s);
        } else {
            genres.add(genreRepository.findByName(t.getName()));
        }
    }
    return genres;
}
Also used : ArrayList(java.util.ArrayList) Genre(com.dubion.domain.Genre)

Aggregations

Genre (com.dubion.domain.Genre)4 Timed (com.codahale.metrics.annotation.Timed)3 NapsterGenre (com.dubion.service.dto.NapsterAPI.NapsterGenre)3 BadRequestAlertException (com.dubion.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1