use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResource method getComment.
/**
* GET /comments/:id : get the "id" comment.
*
* @param id the id of the comment to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the comment, or with status 404 (Not Found)
*/
@GetMapping("/comments/{id}")
@Timed
public ResponseEntity<Comment> getComment(@PathVariable Long id) {
log.debug("REST request to get Comment : {}", id);
Comment comment = commentRepository.findOne(id);
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(comment));
}
use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResource method getAllComments.
/**
* GET /comments : get all the comments.
*
* @param pageable the pagination information
* @return the ResponseEntity with status 200 (OK) and the list of comments in body
* @throws URISyntaxException if there is an error to generate the pagination HTTP headers
*/
@GetMapping("/comments")
@Timed
public ResponseEntity<List<Comment>> getAllComments(@ApiParam Pageable pageable) {
log.debug("REST request to get a page of Comments");
Page<Comment> page = commentRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/comments");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResource method createComment.
/**
* POST /comments : Create a new comment.
*
* @param comment the comment to create
* @return the ResponseEntity with status 201 (Created) and with body the new comment, or with status 400 (Bad Request) if the comment has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/comments")
@Timed
public ResponseEntity<Comment> createComment(@Valid @RequestBody Comment comment) throws URISyntaxException {
log.debug("REST request to save Comment : {}", comment);
if (comment.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new comment cannot already have an ID")).body(null);
}
Comment result = commentRepository.save(comment);
return ResponseEntity.created(new URI("/api/comments/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResourceIntegrationTest method updateComment.
@Test
@Transactional
public void updateComment() throws Exception {
// Initialize the database
commentRepository.saveAndFlush(comment);
int databaseSizeBeforeUpdate = commentRepository.findAll().size();
// Update the comment
Comment updatedComment = commentRepository.findOne(comment.getId());
updatedComment.text(UPDATED_TEXT).creationDate(UPDATED_CREATION_DATE);
restCommentMockMvc.perform(put("/api/comments").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedComment))).andExpect(status().isOk());
// Validate the Comment in the database
List<Comment> commentList = commentRepository.findAll();
assertThat(commentList).hasSize(databaseSizeBeforeUpdate);
Comment testComment = commentList.get(commentList.size() - 1);
assertThat(testComment.getText()).isEqualTo(UPDATED_TEXT);
assertThat(testComment.getCreationDate()).isEqualTo(UPDATED_CREATION_DATE);
}
use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResourceIntegrationTest method createComment.
@Test
@Transactional
public void createComment() throws Exception {
int databaseSizeBeforeCreate = commentRepository.findAll().size();
// Create the Comment
restCommentMockMvc.perform(post("/api/comments").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(comment))).andExpect(status().isCreated());
// Validate the Comment in the database
List<Comment> commentList = commentRepository.findAll();
assertThat(commentList).hasSize(databaseSizeBeforeCreate + 1);
Comment testComment = commentList.get(commentList.size() - 1);
assertThat(testComment.getText()).isEqualTo(DEFAULT_TEXT);
assertThat(testComment.getCreationDate()).isEqualTo(DEFAULT_CREATION_DATE);
}
Aggregations