// Path: src/main/java/com/hantsylabs/restexample/springmvc/Constants.java
// public class Constants {
// 
//     /**
//      * prefix of REST API
//      */
//     public static final String URI_API_PREFIX = "/api";
// 
//     public static final String URI_SELF = "/me";
// 
//     public static final String URI_USERS = "/users";
// 
//     public static final String URI_POSTS = "/posts";
// 
//     public static final String URI_COMMENTS = "/comments";
// 
//     private Constants() {}
// 
// }
// 
// Path: src/main/java/com/hantsylabs/restexample/springmvc/service/BlogService.java
// @Service
// @Transactional
// public class BlogService {
// 
//     private static final Logger log = LoggerFactory.getLogger(BlogService.class);
// 
//     //@Inject
//     private PostRepository postRepository;
// 
//     //@Inject
//     private CommentRepository commentRepository;
// 
//     @Inject //no need in Spring 4.3
//     public BlogService(PostRepository postRepository, CommentRepository commentRepository) {
//         this.postRepository = postRepository;
//         this.commentRepository = commentRepository;
//     }
// 
//     public Page<PostDetails> searchPostsByCriteria(String q, Post.Status status, Pageable page) {
// 
//         log.debug("search posts by keyword@" + q + ", page @" + page);
// 
//         Page<Post> posts = postRepository.findAll(PostSpecifications.filterByKeywordAndStatus(q, status),
//                 page);
// 
//         if (log.isDebugEnabled()) {
//             log.debug("get posts size @" + posts.getTotalElements());
//         }
// 
//         return DTOUtils.mapPage(posts, PostDetails.class);
//     }
// 
//     public PostDetails savePost(PostForm form) {
// 
//         log.debug("save post @" + form);
// 
//         Post post = DTOUtils.map(form, Post.class);
// 
//         Post saved = postRepository.save(post);
// 
//         log.debug("saved post id is @" + saved);
// 
//         return DTOUtils.map(saved, PostDetails.class);
// 
//     }
// 
//     public PostDetails updatePost(Long id, PostForm form) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("updating post of @" + id + ", posst content @" + form);
// 
//         Post post = postRepository.findOne(id);
//         DTOUtils.mapTo(form, post);
// 
//         Post saved = postRepository.save(post);
// 
//         log.debug("updated post@" + saved);
// 
//         return DTOUtils.map(saved, PostDetails.class);
//     }
// 
//     public PostDetails findPostById(Long id) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("find post by id@" + id);
// 
//         Post post = postRepository.findOne(id);
// 
//         if (post == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         return DTOUtils.map(post, PostDetails.class);
//     }
// 
//     public Page<CommentDetails> findCommentsByPostId(Long id, Pageable page) {
// 
//         log.debug("find comments by post id@" + id);
// 
//         Page<Comment> comments = commentRepository.findByPostId(id, page);
// 
//         if (log.isDebugEnabled()) {
//             log.debug("found results@" + comments.getTotalElements());
//         }
// 
//         return DTOUtils.mapPage(comments, CommentDetails.class);
//     }
// 
//     public CommentDetails saveCommentOfPost(Long id, CommentForm fm) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("find post by id@" + id);
// 
//         Post post = postRepository.findOne(id);
// 
//         if (post == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         Comment comment = DTOUtils.map(fm, Comment.class);
// 
//         comment.setPost(post);
// 
//         comment = commentRepository.save(comment);
// 
//         if (log.isDebugEnabled()) {
//             log.debug("comment saved@" + comment);
//         }
// 
//         return DTOUtils.map(comment, CommentDetails.class);
//     }
// 
//     public void deletePostById(Long id) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("find post by id@" + id);
// 
//         Post post = postRepository.findOne(id);
// 
//         if (post == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         postRepository.delete(post);
//     }
// 
//     public void deleteCommentById(Long id) {
//         Assert.notNull(id, "comment id can not be null");
// 
//         if (log.isDebugEnabled()) {
//             log.debug("delete comment by id@" + id);
//         }
// 
//         Comment comment = commentRepository.findOne(id);
// 
//         if (comment == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         commentRepository.delete(comment);
//     }
// }


import com.hantsylabs.restexample.springmvc.Constants;
import com.hantsylabs.restexample.springmvc.service.BlogService;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
package com.hantsylabs.restexample.springmvc.api.post;


@RestController
@RequestMapping(value = Constants.URI_API_PREFIX + Constants.URI_COMMENTS)
public class CommentController {

    private static final Logger log = LoggerFactory
            .getLogger(CommentController.class);

    @Inject
// Path: src/main/java/com/hantsylabs/restexample/springmvc/Constants.java
// public class Constants {
// 
//     /**
//      * prefix of REST API
//      */
//     public static final String URI_API_PREFIX = "/api";
// 
//     public static final String URI_SELF = "/me";
// 
//     public static final String URI_USERS = "/users";
// 
//     public static final String URI_POSTS = "/posts";
// 
//     public static final String URI_COMMENTS = "/comments";
// 
//     private Constants() {}
// 
// }
// 
// Path: src/main/java/com/hantsylabs/restexample/springmvc/service/BlogService.java
// @Service
// @Transactional
// public class BlogService {
// 
//     private static final Logger log = LoggerFactory.getLogger(BlogService.class);
// 
//     //@Inject
//     private PostRepository postRepository;
// 
//     //@Inject
//     private CommentRepository commentRepository;
// 
//     @Inject //no need in Spring 4.3
//     public BlogService(PostRepository postRepository, CommentRepository commentRepository) {
//         this.postRepository = postRepository;
//         this.commentRepository = commentRepository;
//     }
// 
//     public Page<PostDetails> searchPostsByCriteria(String q, Post.Status status, Pageable page) {
// 
//         log.debug("search posts by keyword@" + q + ", page @" + page);
// 
//         Page<Post> posts = postRepository.findAll(PostSpecifications.filterByKeywordAndStatus(q, status),
//                 page);
// 
//         if (log.isDebugEnabled()) {
//             log.debug("get posts size @" + posts.getTotalElements());
//         }
// 
//         return DTOUtils.mapPage(posts, PostDetails.class);
//     }
// 
//     public PostDetails savePost(PostForm form) {
// 
//         log.debug("save post @" + form);
// 
//         Post post = DTOUtils.map(form, Post.class);
// 
//         Post saved = postRepository.save(post);
// 
//         log.debug("saved post id is @" + saved);
// 
//         return DTOUtils.map(saved, PostDetails.class);
// 
//     }
// 
//     public PostDetails updatePost(Long id, PostForm form) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("updating post of @" + id + ", posst content @" + form);
// 
//         Post post = postRepository.findOne(id);
//         DTOUtils.mapTo(form, post);
// 
//         Post saved = postRepository.save(post);
// 
//         log.debug("updated post@" + saved);
// 
//         return DTOUtils.map(saved, PostDetails.class);
//     }
// 
//     public PostDetails findPostById(Long id) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("find post by id@" + id);
// 
//         Post post = postRepository.findOne(id);
// 
//         if (post == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         return DTOUtils.map(post, PostDetails.class);
//     }
// 
//     public Page<CommentDetails> findCommentsByPostId(Long id, Pageable page) {
// 
//         log.debug("find comments by post id@" + id);
// 
//         Page<Comment> comments = commentRepository.findByPostId(id, page);
// 
//         if (log.isDebugEnabled()) {
//             log.debug("found results@" + comments.getTotalElements());
//         }
// 
//         return DTOUtils.mapPage(comments, CommentDetails.class);
//     }
// 
//     public CommentDetails saveCommentOfPost(Long id, CommentForm fm) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("find post by id@" + id);
// 
//         Post post = postRepository.findOne(id);
// 
//         if (post == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         Comment comment = DTOUtils.map(fm, Comment.class);
// 
//         comment.setPost(post);
// 
//         comment = commentRepository.save(comment);
// 
//         if (log.isDebugEnabled()) {
//             log.debug("comment saved@" + comment);
//         }
// 
//         return DTOUtils.map(comment, CommentDetails.class);
//     }
// 
//     public void deletePostById(Long id) {
//         Assert.notNull(id, "post id can not be null");
// 
//         log.debug("find post by id@" + id);
// 
//         Post post = postRepository.findOne(id);
// 
//         if (post == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         postRepository.delete(post);
//     }
// 
//     public void deleteCommentById(Long id) {
//         Assert.notNull(id, "comment id can not be null");
// 
//         if (log.isDebugEnabled()) {
//             log.debug("delete comment by id@" + id);
//         }
// 
//         Comment comment = commentRepository.findOne(id);
// 
//         if (comment == null) {
//             throw new ResourceNotFoundException(id);
//         }
// 
//         commentRepository.delete(comment);
//     }
// }


// Path: src/main/java/com/hantsylabs/restexample/springmvc/api/post/CommentController.java
import com.hantsylabs.restexample.springmvc.Constants;
import com.hantsylabs.restexample.springmvc.service.BlogService;
import javax.inject.Inject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

package com.hantsylabs.restexample.springmvc.api.post;


@RestController
@RequestMapping(value = Constants.URI_API_PREFIX + Constants.URI_COMMENTS)
public class CommentController {

    private static final Logger log = LoggerFactory
            .getLogger(CommentController.class);

    @Inject
    private BlogService blogService;