Search in sources :

Example 6 with BadRequestAlertException

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);
    }
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) User(com.furyviewer.domain.User) LoginAlreadyUsedException(com.furyviewer.web.rest.errors.LoginAlreadyUsedException) URI(java.net.URI) EmailAlreadyUsedException(com.furyviewer.web.rest.errors.EmailAlreadyUsedException) Secured(org.springframework.security.access.annotation.Secured) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with BadRequestAlertException

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);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) HatredArtist(com.furyviewer.domain.HatredArtist) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 8 with BadRequestAlertException

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);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) URI(java.net.URI) RateSeries(com.furyviewer.domain.RateSeries) Timed(com.codahale.metrics.annotation.Timed)

Example 9 with BadRequestAlertException

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);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) URI(java.net.URI) ReviewSeries(com.furyviewer.domain.ReviewSeries) Timed(com.codahale.metrics.annotation.Timed)

Example 10 with BadRequestAlertException

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);
}
Also used : BadRequestAlertException(com.furyviewer.web.rest.errors.BadRequestAlertException) RateMovie(com.furyviewer.domain.RateMovie) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)28 BadRequestAlertException (com.furyviewer.web.rest.errors.BadRequestAlertException)28 URI (java.net.URI)27 Artist (com.furyviewer.domain.Artist)2 ArtistType (com.furyviewer.domain.ArtistType)2 Achievement (com.furyviewer.domain.Achievement)1 AchievementsAchievs (com.furyviewer.domain.AchievementsAchievs)1 ChapterSeen (com.furyviewer.domain.ChapterSeen)1 Company (com.furyviewer.domain.Company)1 Country (com.furyviewer.domain.Country)1 Episode (com.furyviewer.domain.Episode)1 FavouriteArtist (com.furyviewer.domain.FavouriteArtist)1 FavouriteMovie (com.furyviewer.domain.FavouriteMovie)1 FavouriteSeries (com.furyviewer.domain.FavouriteSeries)1 Genre (com.furyviewer.domain.Genre)1 HatredArtist (com.furyviewer.domain.HatredArtist)1 HatredMovie (com.furyviewer.domain.HatredMovie)1 HatredSeries (com.furyviewer.domain.HatredSeries)1 Movie (com.furyviewer.domain.Movie)1 MovieStats (com.furyviewer.domain.MovieStats)1