/** DELETE /articles/:id -> delete the "id" article. */ @RequestMapping( value = "/articles/{id}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Void> deleteArticle(@PathVariable Long id) { log.debug("REST request to delete Article : {}", id); articleRepository.delete(id); return ResponseEntity.ok() .headers(HeaderUtil.createEntityDeletionAlert("article", id.toString())) .build(); }
/** POST /articles -> Create a new article. */ @RequestMapping( value = "/articles", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Article> createArticle(@RequestBody Article article) throws URISyntaxException { log.debug("REST request to save Article : {}", article); if (article.getId() != null) { return ResponseEntity.badRequest() .headers( HeaderUtil.createFailureAlert( "article", "idexists", "A new article cannot already have an ID")) .body(null); } article.setI18nTitle(I18n.setTranslationText(article.getI18nTitle(), article.getTitle())); article.setI18nText(I18n.setTranslationText(article.getI18nText(), article.getText())); Article result = articleRepository.save(article); return ResponseEntity.created(new URI("/api/articles/" + result.getId())) .headers(HeaderUtil.createEntityCreationAlert("article", result.getId().toString())) .body(result); }
/** PUT /articles -> Updates an existing article. */ @RequestMapping( value = "/articles", method = RequestMethod.PUT, produces = MediaType.APPLICATION_JSON_VALUE) @Timed public ResponseEntity<Article> updateArticle(@RequestBody Article article) throws URISyntaxException { log.debug("REST request to update Article : {}", article); if (article.getId() == null) { return createArticle(article); } Article result = articleRepository.findOne(article.getId()); result.setI18nTitle(I18n.setTranslationText(result.getI18nTitle(), article.getTitle())); result.setI18nText(I18n.setTranslationText(result.getI18nText(), article.getText())); result.setTitle(article.getTitle()); result.setText(article.getText()); result = articleRepository.save(result); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert("article", article.getId().toString())) .body(result); }