Search in sources :

Example 6 with Comment

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;
}
Also used : Comment(com.baeldung.domain.Comment) Post(com.baeldung.domain.Post)

Example 7 with 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);
}
Also used : Comment(com.baeldung.domain.Comment) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Comment (com.baeldung.domain.Comment)7 Timed (com.codahale.metrics.annotation.Timed)4 Test (org.junit.Test)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)2 Transactional (org.springframework.transaction.annotation.Transactional)2 Post (com.baeldung.domain.Post)1 URI (java.net.URI)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1