use of com.furyviewer.web.rest.errors.BadRequestAlertException in project FuryViewer by TheDoctor-95.
the class UserResource method createUser.
/**
* POST /users : Creates a new user.
* <p>
* Creates a new user if the login and email are not already used, and sends an
* mail with an activation link.
* The user needs to be activated on creation.
*
* @param managedUserVM the user to create
* @return the ResponseEntity with status 201 (Created) and with body the new user, or with status 400 (Bad Request) if the login or email is already in use
* @throws URISyntaxException if the Location URI syntax is incorrect
* @throws BadRequestAlertException 400 (Bad Request) if the login or email is already in use
*/
@PostMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<User> createUser(@Valid @RequestBody ManagedUserVM managedUserVM) throws URISyntaxException {
log.debug("REST request to save User : {}", managedUserVM);
if (managedUserVM.getId() != null) {
throw new BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists");
// Lowercase the user login before comparing with database
} else if (userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase()).isPresent()) {
throw new LoginAlreadyUsedException();
} else if (userRepository.findOneByEmailIgnoreCase(managedUserVM.getEmail()).isPresent()) {
throw new EmailAlreadyUsedException();
} else {
User newUser = userService.createUser(managedUserVM);
mailService.sendCreationEmail(newUser);
return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin())).headers(HeaderUtil.createAlert("userManagement.created", newUser.getLogin())).body(newUser);
}
}
use of com.furyviewer.web.rest.errors.BadRequestAlertException in project FuryViewer by TheDoctor-95.
the class HatredArtistResource method createHatredArtist.
/**
* POST /hatred-artists : Create a new hatredArtist.
*
* @param hatredArtist the hatredArtist to create
* @return the ResponseEntity with status 201 (Created) and with body the new hatredArtist, or with status 400 (Bad Request) if the hatredArtist has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/hatred-artists")
@Timed
public ResponseEntity<HatredArtist> createHatredArtist(@RequestBody HatredArtist hatredArtist) throws URISyntaxException {
log.debug("REST request to save HatredArtist : {}", hatredArtist);
if (hatredArtist.getId() != null) {
throw new BadRequestAlertException("A new hatredArtist cannot already have an ID", ENTITY_NAME, "idexists");
}
Optional<HatredArtist> existingHatredArtist = hatredArtistRepository.findByArtistAndUserLogin(hatredArtist.getArtist(), SecurityUtils.getCurrentUserLogin());
if (existingHatredArtist.isPresent()) {
throw new BadRequestAlertException("Artista ya aƱadido en Hatred", ENTITY_NAME, "hatredExist");
}
hatredArtist.setDate(ZonedDateTime.now());
hatredArtist.setUser(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get());
HatredArtist result = hatredArtistRepository.save(hatredArtist);
return ResponseEntity.created(new URI("/api/hatred-artists/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.furyviewer.web.rest.errors.BadRequestAlertException in project FuryViewer by TheDoctor-95.
the class RateSeriesResource method createRateSeries.
/**
* POST /rate-series : Create a new rateSeries.
*
* @param rateSeries the rateSeries to create
* @return the ResponseEntity with status 201 (Created) and with body the new rateSeries, or with status 400 (Bad Request) if the rateSeries has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/rate-series")
@Timed
public ResponseEntity<RateSeries> createRateSeries(@RequestBody RateSeries rateSeries) throws URISyntaxException {
log.debug("REST request to save RateSeries : {}", rateSeries);
if (rateSeries.getId() != null) {
throw new BadRequestAlertException("A new rateSeries cannot already have an ID", ENTITY_NAME, "idexists");
}
RateSeries result = rateSeriesRepository.save(rateSeries);
return ResponseEntity.created(new URI("/api/rate-series/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.furyviewer.web.rest.errors.BadRequestAlertException in project FuryViewer by TheDoctor-95.
the class ReviewSeriesResource method createReviewSeries.
/**
* POST /review-series : Create a new reviewSeries.
*
* @param reviewSeries the reviewSeries to create
* @return the ResponseEntity with status 201 (Created) and with body the new reviewSeries, or with status 400 (Bad Request) if the reviewSeries has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/review-series")
@Timed
public ResponseEntity<ReviewSeries> createReviewSeries(@RequestBody ReviewSeries reviewSeries) throws URISyntaxException {
log.debug("REST request to save ReviewSeries : {}", reviewSeries);
if (reviewSeries.getId() != null) {
throw new BadRequestAlertException("A new reviewSeries cannot already have an ID", ENTITY_NAME, "idexists");
}
ReviewSeries result = reviewSeriesRepository.save(reviewSeries);
return ResponseEntity.created(new URI("/api/review-series/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.furyviewer.web.rest.errors.BadRequestAlertException in project FuryViewer by TheDoctor-95.
the class RateMovieResource method createRateMovie.
/**
* POST /rate-movies : Create a new rateMovie.
*
* @param rateMovie the rateMovie to create
* @return the ResponseEntity with status 201 (Created) and with body the new rateMovie, or with status 400 (Bad Request) if the rateMovie has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/rate-movies")
@Timed
public ResponseEntity<RateMovie> createRateMovie(@RequestBody RateMovie rateMovie) throws URISyntaxException {
log.debug("REST request to save RateMovie : {}", rateMovie);
if (rateMovie.getId() != null) {
throw new BadRequestAlertException("A new rateMovie cannot already have an ID", ENTITY_NAME, "idexists");
}
Optional<RateMovie> existingRateMovie = rateMovieRepository.findByMovieAndUserLogin(rateMovie.getMovie(), SecurityUtils.getCurrentUserLogin());
if (existingRateMovie.isPresent()) {
rateMovie.setId(existingRateMovie.get().getId());
}
rateMovie.setDate(ZonedDateTime.now());
rateMovie.setUser(userRepository.findOneByLogin(SecurityUtils.getCurrentUserLogin()).get());
RateMovie result = rateMovieRepository.save(rateMovie);
return ResponseEntity.created(new URI("/api/rate-movies/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Aggregations