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
  @Test
  @Transactional
  public void updateNews() throws Exception {
    // Initialize the database
    newsRepository.saveAndFlush(news);

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

    // Update the news
    news.setTitle(UPDATED_TITLE);
    news.setDate(UPDATED_DATE);
    news.setContent(UPDATED_CONTENT);

    restNewsMockMvc
        .perform(
            put("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isOk());

    // Validate the News in the database
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeUpdate);
    News testNews = newss.get(newss.size() - 1);
    assertThat(testNews.getTitle()).isEqualTo(UPDATED_TITLE);
    assertThat(testNews.getDate()).isEqualTo(UPDATED_DATE);
    assertThat(testNews.getContent()).isEqualTo(UPDATED_CONTENT);
  }
Beispiel #3
0
  @Test
  @Transactional
  public void createNews() throws Exception {
    int databaseSizeBeforeCreate = newsRepository.findAll().size();

    // Create the News

    restNewsMockMvc
        .perform(
            post("/api/newss")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(news)))
        .andExpect(status().isCreated());

    // Validate the News in the database
    List<News> newss = newsRepository.findAll();
    assertThat(newss).hasSize(databaseSizeBeforeCreate + 1);
    News testNews = newss.get(newss.size() - 1);
    assertThat(testNews.getTitle()).isEqualTo(DEFAULT_TITLE);
    assertThat(testNews.getDate()).isEqualTo(DEFAULT_DATE);
    assertThat(testNews.getContent()).isEqualTo(DEFAULT_CONTENT);
  }