Skip to content
This repository was archived by the owner on Nov 10, 2017. It is now read-only.

#14-#16 Backend:add post mongo repository service controller #21

Open
wants to merge 21 commits into
base: master
Choose a base branch
from

Conversation

olegbal
Copy link
Contributor

@olegbal olegbal commented Jun 17, 2017

No description provided.

import java.awt.print.Pageable;

@RestController
@RequestMapping(path = "/api/v1/posts")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

media type

return new ResponseEntity(HttpStatus.OK);
}

@RequestMapping(method = RequestMethod.GET, params = {"page", "size"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get by id

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

@Document(collection = "posts")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lombok

@olegbal olegbal changed the title #14 16 backend add post mongo repository service controller #14-#16 Backend:add post mongo repository service controller Jun 17, 2017
@@ -12,6 +12,6 @@

@RequestMapping(method = RequestMethod.GET)
public ResponseEntity getHelloMessage() {
return new ResponseEntity("Hello world!", HttpStatus.OK);
return new ResponseEntity<>("Hello world!", HttpStatus.OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For removing warning "Unchecked call"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok



@RestController
@RequiredArgsConstructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @Autowired on constructor for more visibility


@RequestMapping(method = RequestMethod.PUT, consumes = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity updatePost(@RequestBody Post post) {
return new ResponseEntity<>(postService.update(post), HttpStatus.NO_CONTENT);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why NO_CONTENT?

@RequestMapping(path = "/{id}", method = RequestMethod.DELETE)
public ResponseEntity deletePostById(@PathVariable String id) {
postService.deleteById(id);
return new ResponseEntity(HttpStatus.OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RequestMapping(method = RequestMethod.DELETE, consumes = {MediaType.APPLICATION_JSON_VALUE})
public ResponseEntity deletePost(@RequestBody Post post) {
postService.delete(post);
return new ResponseEntity(HttpStatus.OK);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why OK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private String topicId;
private String postMessage;

public Post() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why empty constructor? For what?

import java.util.List;

@Service
@RequiredArgsConstructor
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @Autowired over constructor


@Override
public Post create(Post post) {
post.setId(null);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Null?? For what?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For prevent updating of object with the same id as in request body. This method is only for creating new objects in db.

}

@Override
public Post create(Post post) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if post is null?


import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use star imports


@Test
public void createPostShouldReturnStatusCreated() throws Exception {
Post creatingPost = new Post();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Separate that

@Mock
private PostRepository postRepository;

PostService postService;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Package access?


@Test
public void getAllPostsShouldReturnPostsList() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do that empty lines, nowhere

@solairerove
Copy link
Member

why so long conversation, mmm?

@solairerove
Copy link
Member

use cherry pick to separate issues/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants