예제 #1
0
  /** POST /newss -> Create a new news. */
  @RequestMapping(
      value = "/newss",
      method = RequestMethod.POST,
      produces = MediaType.APPLICATION_JSON_VALUE)
  @Timed
  public ResponseEntity<News> createNews(@Valid @RequestBody News news) throws URISyntaxException {
    log.debug("REST request to save News : {}", news);
    if (news.getId() != null) {
      return ResponseEntity.badRequest()
          .headers(
              HeaderUtil.createFailureAlert(
                  "news", "idexists", "A new news cannot already have an ID"))
          .body(null);
    }
    News result = newsRepository.save(news);
    List<Subscription> subscriptions =
        subscriptionRepository
            .findAll()
            .stream()
            .filter(item -> (item.getIdMarketPlace().equals(result.getMarketPlace().getId())))
            .collect(Collectors.toList());
    String title = result.getMarketPlace().getName() + " vous a envoyé une News !";
    String content = result.getTitle() + "\n\n\n" + result.getContent();

    for (Subscription subscription : subscriptions) {
      mailService.sendEmail(subscription.getUser().getEmail(), title, content, false, false);
    }
    return ResponseEntity.created(new URI("/api/newss/" + result.getId()))
        .headers(HeaderUtil.createEntityCreationAlert("news", result.getId().toString()))
        .body(result);
  }
예제 #2
0
 /** DELETE /newss/:id -> delete the "id" news. */
 @RequestMapping(
     value = "/newss/{id}",
     method = RequestMethod.DELETE,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<Void> deleteNews(@PathVariable Long id) {
   log.debug("REST request to delete News : {}", id);
   newsRepository.delete(id);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityDeletionAlert("news", id.toString()))
       .build();
 }
예제 #3
0
 /** PUT /newss -> Updates an existing news. */
 @RequestMapping(
     value = "/newss",
     method = RequestMethod.PUT,
     produces = MediaType.APPLICATION_JSON_VALUE)
 @Timed
 public ResponseEntity<News> updateNews(@Valid @RequestBody News news) throws URISyntaxException {
   log.debug("REST request to update News : {}", news);
   if (news.getId() == null) {
     return createNews(news);
   }
   News result = newsRepository.save(news);
   return ResponseEntity.ok()
       .headers(HeaderUtil.createEntityUpdateAlert("news", news.getId().toString()))
       .body(result);
 }