use of com.furyviewer.domain.FavouriteMovie in project FuryViewer by TheDoctor-95.
the class FavouriteMovieResourceIntTest method createFavouriteMovie.
@Test
@Transactional
public void createFavouriteMovie() throws Exception {
int databaseSizeBeforeCreate = favouriteMovieRepository.findAll().size();
// Create the FavouriteMovie
restFavouriteMovieMockMvc.perform(post("/api/favourite-movies").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(favouriteMovie))).andExpect(status().isCreated());
// Validate the FavouriteMovie in the database
List<FavouriteMovie> favouriteMovieList = favouriteMovieRepository.findAll();
assertThat(favouriteMovieList).hasSize(databaseSizeBeforeCreate + 1);
FavouriteMovie testFavouriteMovie = favouriteMovieList.get(favouriteMovieList.size() - 1);
assertThat(testFavouriteMovie.isLiked()).isEqualTo(DEFAULT_LIKED);
assertThat(testFavouriteMovie.getDate()).isEqualTo(DEFAULT_DATE);
}
use of com.furyviewer.domain.FavouriteMovie in project FuryViewer by TheDoctor-95.
the class FavouriteMovieResourceIntTest method equalsVerifier.
@Test
@Transactional
public void equalsVerifier() throws Exception {
TestUtil.equalsVerifier(FavouriteMovie.class);
FavouriteMovie favouriteMovie1 = new FavouriteMovie();
favouriteMovie1.setId(1L);
FavouriteMovie favouriteMovie2 = new FavouriteMovie();
favouriteMovie2.setId(favouriteMovie1.getId());
assertThat(favouriteMovie1).isEqualTo(favouriteMovie2);
favouriteMovie2.setId(2L);
assertThat(favouriteMovie1).isNotEqualTo(favouriteMovie2);
favouriteMovie1.setId(null);
assertThat(favouriteMovie1).isNotEqualTo(favouriteMovie2);
}
use of com.furyviewer.domain.FavouriteMovie in project FuryViewer by TheDoctor-95.
the class FavouriteMovieResource method createFavouriteMovie.
/**
* POST /favourite-movies : Create a new favouriteMovie.
*
* @param favouriteMovie the favouriteMovie to create
* @return the ResponseEntity with status 201 (Created) and with body the new favouriteMovie, or with status 400 (Bad Request) if the favouriteMovie has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/favourite-movies")
@Timed
public ResponseEntity<FavouriteMovie> createFavouriteMovie(@RequestBody FavouriteMovie favouriteMovie) throws URISyntaxException {
log.debug("REST request to save FavouriteMovie : {}", favouriteMovie);
if (favouriteMovie.getId() != null) {
throw new BadRequestAlertException("A new favouriteMovie cannot already have an ID", ENTITY_NAME, "idexists");
}
Optional<FavouriteMovie> favoriteMovieExisting = favouriteMovieRepository.findByMovieAndUserLogin(favouriteMovie.getMovie(), SecurityUtils.getCurrentUserLogin());
if (favoriteMovieExisting.isPresent()) {
favouriteMovie = favoriteMovieExisting.get();
favouriteMovie.setLiked(!favouriteMovie.isLiked());
} else {
favouriteMovie.setLiked(true);
}
favouriteMovie.setDate(ZonedDateTime.now());
favouriteMovie.setUser(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get());
FavouriteMovie result = favouriteMovieRepository.save(favouriteMovie);
return ResponseEntity.created(new URI("/api/favourite-movies/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.furyviewer.domain.FavouriteMovie in project FuryViewer by TheDoctor-95.
the class FavouriteMovieResourceIntTest method updateFavouriteMovie.
@Test
@Transactional
public void updateFavouriteMovie() throws Exception {
// Initialize the database
favouriteMovieRepository.saveAndFlush(favouriteMovie);
int databaseSizeBeforeUpdate = favouriteMovieRepository.findAll().size();
// Update the favouriteMovie
FavouriteMovie updatedFavouriteMovie = favouriteMovieRepository.findOne(favouriteMovie.getId());
updatedFavouriteMovie.liked(UPDATED_LIKED).date(UPDATED_DATE);
restFavouriteMovieMockMvc.perform(put("/api/favourite-movies").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedFavouriteMovie))).andExpect(status().isOk());
// Validate the FavouriteMovie in the database
List<FavouriteMovie> favouriteMovieList = favouriteMovieRepository.findAll();
assertThat(favouriteMovieList).hasSize(databaseSizeBeforeUpdate);
FavouriteMovie testFavouriteMovie = favouriteMovieList.get(favouriteMovieList.size() - 1);
assertThat(testFavouriteMovie.isLiked()).isEqualTo(UPDATED_LIKED);
assertThat(testFavouriteMovie.getDate()).isEqualTo(UPDATED_DATE);
}
use of com.furyviewer.domain.FavouriteMovie in project FuryViewer by TheDoctor-95.
the class FavouriteMovieResource method getFavUserMovie.
@GetMapping("/favourite-movies/movieId/{id}")
@Timed
public ResponseEntity<FavouriteMovie> getFavUserMovie(@PathVariable Long id) {
log.debug("REST request to get FavouriteMovie : {}", id);
FavouriteMovie fm = favouriteMovieRepository.findByUserAndMovieId(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get(), id);
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(fm));
}
Aggregations