-
Notifications
You must be signed in to change notification settings - Fork 0
#14-#16 Backend:add post mongo repository service controller #21
base: master
Are you sure you want to change the base?
#14-#16 Backend:add post mongo repository service controller #21
Conversation
…dd PostController tests without implementation.
import java.awt.print.Pageable; | ||
|
||
@RestController | ||
@RequestMapping(path = "/api/v1/posts") |
There was a problem hiding this comment.
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"}) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lombok
… to controller. Make responseEntity type generic.
… postcontroller.
@@ -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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
|
||
|
||
@RestController | ||
@RequiredArgsConstructor |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why OK?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why OK?
There was a problem hiding this comment.
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() { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Null?? For what?
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.*; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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() { | ||
|
There was a problem hiding this comment.
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
….MockMvcRequestBuilders.* and add only using imports of this package.
… Remove warnings.
… Remove warnings.
… Remove warnings.
why so long conversation, mmm? |
use cherry pick to separate issues/ |
No description provided.