use of com.baeldung.domain.Post in project tutorials by eugenp.
the class PostResource method getAllPosts.
/**
* GET /posts : get all the posts.
*
* @param pageable the pagination information
* @return the ResponseEntity with status 200 (OK) and the list of posts in body
* @throws URISyntaxException if there is an error to generate the pagination HTTP headers
*/
@GetMapping("/posts")
@Timed
public ResponseEntity<List<Post>> getAllPosts(@ApiParam Pageable pageable) {
log.debug("REST request to get a page of Posts");
Page<Post> page = postRepository.findAll(pageable);
HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/posts");
return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
use of com.baeldung.domain.Post in project tutorials by eugenp.
the class PostResource method getPost.
/**
* GET /posts/:id : get the "id" post.
*
* @param id the id of the post to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the post, or with status 404 (Not Found)
*/
@GetMapping("/posts/{id}")
@Timed
public ResponseEntity<Post> getPost(@PathVariable Long id) {
log.debug("REST request to get Post : {}", id);
Post post = postRepository.findOne(id);
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(post));
}
use of com.baeldung.domain.Post in project tutorials by eugenp.
the class PostResourceIntegrationTest method updatePost.
@Test
@Transactional
public void updatePost() throws Exception {
// Initialize the database
postRepository.saveAndFlush(post);
int databaseSizeBeforeUpdate = postRepository.findAll().size();
// Update the post
Post updatedPost = postRepository.findOne(post.getId());
updatedPost.title(UPDATED_TITLE).content(UPDATED_CONTENT).creationDate(UPDATED_CREATION_DATE);
restPostMockMvc.perform(put("/api/posts").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(updatedPost))).andExpect(status().isOk());
// Validate the Post in the database
List<Post> postList = postRepository.findAll();
assertThat(postList).hasSize(databaseSizeBeforeUpdate);
Post testPost = postList.get(postList.size() - 1);
assertThat(testPost.getTitle()).isEqualTo(UPDATED_TITLE);
assertThat(testPost.getContent()).isEqualTo(UPDATED_CONTENT);
assertThat(testPost.getCreationDate()).isEqualTo(UPDATED_CREATION_DATE);
}
use of com.baeldung.domain.Post in project tutorials by eugenp.
the class PostResourceIntegrationTest method createPost.
@Test
@Transactional
public void createPost() throws Exception {
int databaseSizeBeforeCreate = postRepository.findAll().size();
// Create the Post
restPostMockMvc.perform(post("/api/posts").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(post))).andExpect(status().isCreated());
// Validate the Post in the database
List<Post> postList = postRepository.findAll();
assertThat(postList).hasSize(databaseSizeBeforeCreate + 1);
Post testPost = postList.get(postList.size() - 1);
assertThat(testPost.getTitle()).isEqualTo(DEFAULT_TITLE);
assertThat(testPost.getContent()).isEqualTo(DEFAULT_CONTENT);
assertThat(testPost.getCreationDate()).isEqualTo(DEFAULT_CREATION_DATE);
}
use of com.baeldung.domain.Post in project tutorials by eugenp.
the class PostResourceIntegrationTest 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 Post createEntity(EntityManager em) {
Post post = new Post().title(DEFAULT_TITLE).content(DEFAULT_CONTENT).creationDate(DEFAULT_CREATION_DATE);
// Add required entity
User creator = UserResourceIntTest.createEntity(em);
em.persist(creator);
em.flush();
post.setCreator(creator);
return post;
}
Aggregations