use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResourceIntegrationTest method createEntity.
/**
* Create an entity for this test.
*
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Comment createEntity(EntityManager em) {
Comment comment = new Comment().text(DEFAULT_TEXT).creationDate(DEFAULT_CREATION_DATE);
// Add required entity
Post post = PostResourceIntTest.createEntity(em);
em.persist(post);
em.flush();
comment.setPost(post);
return comment;
}
use of com.baeldung.domain.Comment in project tutorials by eugenp.
the class CommentResource method updateComment.
/**
* PUT /comments : Updates an existing comment.
*
* @param comment the comment to update
* @return the ResponseEntity with status 200 (OK) and with body the updated comment,
* or with status 400 (Bad Request) if the comment is not valid,
* or with status 500 (Internal Server Error) if the comment couldnt be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/comments")
@Timed
public ResponseEntity<Comment> updateComment(@Valid @RequestBody Comment comment) throws URISyntaxException {
log.debug("REST request to update Comment : {}", comment);
if (comment.getId() == null) {
return createComment(comment);
}
Comment result = commentRepository.save(comment);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, comment.getId().toString())).body(result);
}
Aggregations