Search in sources :

Example 6 with FavouriteSeries

use of com.furyviewer.domain.FavouriteSeries in project FuryViewer by TheDoctor-95.

the class FavouriteSeriesResource method createFavouriteSeries.

/**
 * POST  /favourite-series : Create a new favouriteSeries.
 *
 * @param favouriteSeries the favouriteSeries to create
 * @return the ResponseEntity with status 201 (Created) and with body the new favouriteSeries, or with status 400 (Bad Request) if the favouriteSeries has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/favourite-series")
@Timed
public ResponseEntity<FavouriteSeries> createFavouriteSeries(@RequestBody FavouriteSeries favouriteSeries) throws URISyntaxException {
    log.debug("REST request to save FavouriteSeries : {}", favouriteSeries);
    if (favouriteSeries.getId() != null) {
        throw new BadRequestAlertException("A new favouriteSeries cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Optional<FavouriteSeries> existingFavouriteSeries = favouriteSeriesRepository.findBySeriesAndUserLogin(favouriteSeries.getSeries(), SecurityUtils.getCurrentUserLogin());
    if (existingFavouriteSeries.isPresent()) {
        throw new BadRequestAlertException("El serie ya esta aƱadida a favoritos", ENTITY_NAME, "favoriteExist");
    }
    favouriteSeries.setDate(ZonedDateTime.now());
    favouriteSeries.setUser(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get());
    FavouriteSeries result = favouriteSeriesRepository.save(favouriteSeries);
    return ResponseEntity.created(new URI("/api/favourite-series/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) FavouriteSeries(com.furyviewer.domain.FavouriteSeries) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with FavouriteSeries

use of com.furyviewer.domain.FavouriteSeries in project FuryViewer by TheDoctor-95.

the class FavouriteSeriesResource method favouriteSeries.

@PostMapping("/favourite-series/id/{idSeries}/liked")
@Timed
public ResponseEntity<FavouriteSeries> favouriteSeries(@PathVariable Long idSeries) throws URISyntaxException {
    log.debug("REST request to save FavouriteSeries : {}", idSeries);
    Series s = seriesRepository.findOne(idSeries);
    FavouriteSeries fS = new FavouriteSeries();
    fS.setSeries(s);
    fS.setLiked(true);
    return createFavouriteSeries(fS);
}
Also used : FavouriteSeries(com.furyviewer.domain.FavouriteSeries) Series(com.furyviewer.domain.Series) FavouriteSeries(com.furyviewer.domain.FavouriteSeries) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

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