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);
}
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);
}
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));
}
Aggregations