Search in sources :

Example 6 with HatredMovie

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

the class HatredMovieResource method createHatredMovie.

/**
 * POST  /hatred-movies : Create a new hatredMovie.
 *
 * @param hatredMovie the hatredMovie to create
 * @return the ResponseEntity with status 201 (Created) and with body the new hatredMovie, or with status 400 (Bad Request) if the hatredMovie has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/hatred-movies")
@Timed
public ResponseEntity<HatredMovie> createHatredMovie(@RequestBody HatredMovie hatredMovie) throws URISyntaxException {
    log.debug("REST request to save HatredMovie : {}", hatredMovie);
    if (hatredMovie.getId() != null) {
        throw new BadRequestAlertException("A new hatredMovie cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Optional<HatredMovie> existingHatredMovie = hatredMovieRepository.findByMovieAndUserLogin(hatredMovie.getMovie(), SecurityUtils.getCurrentUserLogin());
    if (existingHatredMovie.isPresent()) {
        hatredMovie.setId(existingHatredMovie.get().getId());
        hatredMovie.setHated(!existingHatredMovie.get().isHated());
    }
    hatredMovie.setDate(ZonedDateTime.now());
    hatredMovie.setUser(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get());
    HatredMovie result = hatredMovieRepository.save(hatredMovie);
    return ResponseEntity.created(new URI("/api/hatred-movies/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) HatredMovie(com.furyviewer.domain.HatredMovie) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with HatredMovie

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

the class HatredMovieResource method hateMovie.

@PostMapping("/hatred-movies/id/{idMovie}/hate")
@Timed
public ResponseEntity<HatredMovie> hateMovie(@PathVariable Long idMovie) throws URISyntaxException {
    log.debug("REST request to save FavouriteMovie : {}", idMovie);
    Movie m = movieRepository.findOne(idMovie);
    HatredMovie hm = new HatredMovie();
    hm.setMovie(m);
    hm.setHated(true);
    return createHatredMovie(hm);
}
Also used : HatredMovie(com.furyviewer.domain.HatredMovie) Movie(com.furyviewer.domain.Movie) HatredMovie(com.furyviewer.domain.HatredMovie) Timed(com.codahale.metrics.annotation.Timed)

Example 8 with HatredMovie

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

the class HatredMovieResource method getHatredMovieUse.

@GetMapping("/hatred-movies/{id}/user")
@Timed
public ResponseEntity<HatredMovie> getHatredMovieUse(@PathVariable Long id) {
    log.debug("REST request to get HatredMovie : {}", id);
    HatredMovie hatredMovie = hatredMovieRepository.findByUserAndMovieId(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get(), id);
    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(hatredMovie));
}
Also used : HatredMovie(com.furyviewer.domain.HatredMovie) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

HatredMovie (com.furyviewer.domain.HatredMovie)8 Timed (com.codahale.metrics.annotation.Timed)5 Test (org.junit.Test)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Movie (com.furyviewer.domain.Movie)1 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1