Beispiel #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);
  }
Beispiel #2
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);
 }
Beispiel #3
0
  @Test
  @Transactional
  public void getNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    // Get the news
    restNewsMockMvc
        .perform(get("/api/newss/{id}", news.getId()))
        .andExpect(status().isOk())
        .andExpect(content().contentType(MediaType.APPLICATION_JSON))
        .andExpect(jsonPath("$.id").value(news.getId().intValue()))
        .andExpect(jsonPath("$.title").value(DEFAULT_TITLE.toString()))
        .andExpect(jsonPath("$.date").value(DEFAULT_DATE_STR))
        .andExpect(jsonPath("$.content").value(DEFAULT_CONTENT.toString()));
  }
Beispiel #4
0
  @Test
  @Transactional
  public void deleteNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

    int databaseSizeBeforeDelete = newsRepository.findAll().size();

    // Get the news
    restNewsMockMvc
        .perform(delete("/api/newss/{id}", news.getId()).accept(TestUtil.APPLICATION_JSON_UTF8))
        .andExpect(status().isOk());

    // Validate the database is empty
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeDelete - 1);
  }