From da72bb50b75f242d7f930a8237127bb4224e522d Mon Sep 17 00:00:00 2001 From: Prateek Shroff Date: Sat, 2 Jan 2021 14:29:29 -0800 Subject: [PATCH 1/5] Initial Service Skeleton --- build.gradle | 3 ++ gradle.properties | 2 + src/main/java/TechVault/Application.java | 14 +++++- .../services/comments/CommentService.java | 12 +++++ .../services/comments/CommentServiceImpl.java | 22 +++++++++ .../controller/CommentController.java | 46 +++++++++++++++++++ .../services/comments/model/Comment.java | 39 ++++++++++++++++ .../comments/model/CommentResponse.java | 29 ++++++++++++ .../comments/persistance/CommentDao.java | 14 ++++++ .../comments/persistance/CommentDaoImpl.java | 21 +++++++++ .../persistance/CommentRepository.java | 9 ++++ 11 files changed, 209 insertions(+), 2 deletions(-) create mode 100644 src/main/java/TechVault/services/comments/CommentService.java create mode 100644 src/main/java/TechVault/services/comments/CommentServiceImpl.java create mode 100644 src/main/java/TechVault/services/comments/controller/CommentController.java create mode 100644 src/main/java/TechVault/services/comments/model/Comment.java create mode 100644 src/main/java/TechVault/services/comments/model/CommentResponse.java create mode 100644 src/main/java/TechVault/services/comments/persistance/CommentDao.java create mode 100644 src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java create mode 100644 src/main/java/TechVault/services/comments/persistance/CommentRepository.java diff --git a/build.gradle b/build.gradle index a89a491..1c69e7c 100644 --- a/build.gradle +++ b/build.gradle @@ -43,7 +43,10 @@ dependencies { compile group: 'org.springframework.boot', name: 'spring-boot', version: springBootVersion compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion compile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion + compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: springBootVersion compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: springSleuthVersion + compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: springMongoDataVersion + compile group: 'org.mongodb', name: 'mongodb-driver-sync', version: javaMongoDriverVersion compile group: 'javax.el', name: 'javax.el-api', version: javaxElApiVersion compile group: 'org.glassfish', name: 'javax.el', version: glassfishVersion providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: javaxServletVersion diff --git a/gradle.properties b/gradle.properties index 48be8ce..686edf4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,6 +13,8 @@ javaxElApiVersion=3.0.1-b06 glassfishVersion=3.0.0 javaxServletVersion=3.1.0 tomcatVersion=7.0.63 +springMongoDataVersion=3.0.3.RELEASE +javaMongoDriverVersion=4.0.5 # Version and base tags can be overridden at build time. TechVaultVersion=0.1.0 \ No newline at end of file diff --git a/src/main/java/TechVault/Application.java b/src/main/java/TechVault/Application.java index 7385ead..3c02f13 100644 --- a/src/main/java/TechVault/Application.java +++ b/src/main/java/TechVault/Application.java @@ -2,10 +2,20 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; -@SpringBootApplication -public class Application { +@SpringBootApplication(scanBasePackages="TechVault") +public class Application { public static void main(String[] args) { + System.out.println("Starting Application....."); SpringApplication.run(Application.class, args); } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + } \ No newline at end of file diff --git a/src/main/java/TechVault/services/comments/CommentService.java b/src/main/java/TechVault/services/comments/CommentService.java new file mode 100644 index 0000000..28001e4 --- /dev/null +++ b/src/main/java/TechVault/services/comments/CommentService.java @@ -0,0 +1,12 @@ +package TechVault.services.comments; + +import java.util.List; + +import TechVault.services.comments.model.Comment; + +public interface CommentService { + + public List getComments (String postId); + + public void addComment(String postId, String userId, String comment); +} diff --git a/src/main/java/TechVault/services/comments/CommentServiceImpl.java b/src/main/java/TechVault/services/comments/CommentServiceImpl.java new file mode 100644 index 0000000..ec2c2bc --- /dev/null +++ b/src/main/java/TechVault/services/comments/CommentServiceImpl.java @@ -0,0 +1,22 @@ +package TechVault.services.comments; + +import java.util.List; + +import TechVault.services.comments.model.Comment; + +public class CommentActionsImpl implements CommentActions { + + @Override + public List getComments(String postId) { + // TODO Auto-generated method stub + + return null; + } + + @Override + public void addComment(String postId, String userId, String comment) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/TechVault/services/comments/controller/CommentController.java b/src/main/java/TechVault/services/comments/controller/CommentController.java new file mode 100644 index 0000000..0115135 --- /dev/null +++ b/src/main/java/TechVault/services/comments/controller/CommentController.java @@ -0,0 +1,46 @@ +package TechVault.services.comments.controller; + +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + + + +@Validated +@RestController +@RequestMapping("comment") +public class CommentController { + + /** + * To the the profile of the user corresponding to the user id. + * @return A Response entity which will have all the user details. + */ + @RequestMapping(method = RequestMethod.GET, value = "/{blog_id}") + public ResponseEntity getCommentsForBlog() { + HttpHeaders responseHeaders = new HttpHeaders(); + //CommentResponse cr = new CommentResponse(UUID.randomUUID(), UUID.randomUUID(),(long) 123, new Timestamp(System.currentTimeMillis())); + return new ResponseEntity<>(cr, HttpStatus.OK); + } + + /** + * To the the profile of the user corresponding to the user id. + * @return A Response entity which will have all the user details. + */ + @RequestMapping(method = RequestMethod.POST, value = "/{blog_id}") + public ResponseEntity postCommentsForBlog() { + HttpHeaders responseHeaders = new HttpHeaders(); + List x = new ArrayList<>(); + x.add("asdasd"); + x.add("1121e"); + return new ResponseEntity<>(x, responseHeaders, HttpStatus.OK); + } +} diff --git a/src/main/java/TechVault/services/comments/model/Comment.java b/src/main/java/TechVault/services/comments/model/Comment.java new file mode 100644 index 0000000..73a6fc2 --- /dev/null +++ b/src/main/java/TechVault/services/comments/model/Comment.java @@ -0,0 +1,39 @@ +package TechVault.services.comments.model; + +import java.sql.Timestamp; +import java.util.UUID; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +@Document(collection = "comments") +@Builder +@Getter +@Setter +public class Comment { + @Id + @Field(name = "commentId") + private UUID commentId; + + @Field(name = "postId") + private UUID postId; + + @Field(name = "parentCommentId") + private UUID parentCommentId; + + @Field(name = "userId") + private long userId; + + @JsonFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss") + @Field(name = "postedTime") + private Timestamp postedTime; + + @Field(name = "comment") + private String comment; + +} diff --git a/src/main/java/TechVault/services/comments/model/CommentResponse.java b/src/main/java/TechVault/services/comments/model/CommentResponse.java new file mode 100644 index 0000000..9272f13 --- /dev/null +++ b/src/main/java/TechVault/services/comments/model/CommentResponse.java @@ -0,0 +1,29 @@ +package TechVault.services.comments; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; + +import java.sql.Timestamp; +import java.util.List; +import java.util.UUID; + +@Data +@RequiredArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class CommentResponse { + public CommentResponse(UUID randomUUID, UUID randomUUID2, long l, Timestamp timestamp) { + } + + private UUID commentId; + private UUID postId; + private long userId; + private Timestamp postedTime; + private String comment; + private List childComments; + + @JsonIgnore + private HttpStatus status; +} diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDao.java b/src/main/java/TechVault/services/comments/persistance/CommentDao.java new file mode 100644 index 0000000..63a29e2 --- /dev/null +++ b/src/main/java/TechVault/services/comments/persistance/CommentDao.java @@ -0,0 +1,14 @@ +package TechVault.services.comments.persistance; + +import java.util.List; + +import TechVault.services.comments.model.Comment; + +public interface CommentDao { + + public List getCommentsByBlog(String blogUUID); + + public String addCommenttoBlog(String blogUUID, String parentCommentId, long userId, String comment); + + +} diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java new file mode 100644 index 0000000..ea787e8 --- /dev/null +++ b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java @@ -0,0 +1,21 @@ +package TechVault.services.comments.persistance; + +import java.util.List; + +import TechVault.services.comments.model.Comment; + +public class CommentDaoImpl implements CommentDao { + + @Override + public List getCommentsByBlog(String blogUUID) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String addCommenttoBlog(String blogUUID, String parentCommentId, long userId, String comment) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/main/java/TechVault/services/comments/persistance/CommentRepository.java b/src/main/java/TechVault/services/comments/persistance/CommentRepository.java new file mode 100644 index 0000000..13b7a9d --- /dev/null +++ b/src/main/java/TechVault/services/comments/persistance/CommentRepository.java @@ -0,0 +1,9 @@ +package TechVault.services.comments.persistance; + +import TechVault.services.comments.model.Comment; +import org.springframework.data.mongodb.repository.MongoRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface CommentRepository extends MongoRepository { +} \ No newline at end of file From ca34aa145728962074ffaa741c943370988adae2 Mon Sep 17 00:00:00 2001 From: Prateek Shroff Date: Sat, 2 Jan 2021 17:00:53 -0800 Subject: [PATCH 2/5] added config --- src/main/java/TechVault/Application.java | 2 ++ .../services/comments/CommentService.java | 4 +-- .../services/comments/CommentServiceImpl.java | 18 +++++++--- .../controller/CommentController.java | 31 ++++++++++++---- .../services/comments/model/Comment.java | 6 ++-- .../comments/model/CommentResponse.java | 2 +- .../comments/persistance/CommentDaoImpl.java | 20 +++++++++++ .../persistance/CommentPersistenceConfig.java | 36 +++++++++++++++++++ src/main/resources/application.properties | 4 ++- 9 files changed, 105 insertions(+), 18 deletions(-) create mode 100644 src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java diff --git a/src/main/java/TechVault/Application.java b/src/main/java/TechVault/Application.java index 3c02f13..002bf22 100644 --- a/src/main/java/TechVault/Application.java +++ b/src/main/java/TechVault/Application.java @@ -4,8 +4,10 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; @SpringBootApplication(scanBasePackages="TechVault") +@EnableMongoRepositories(basePackages = "TechVault") public class Application { public static void main(String[] args) { System.out.println("Starting Application....."); diff --git a/src/main/java/TechVault/services/comments/CommentService.java b/src/main/java/TechVault/services/comments/CommentService.java index 28001e4..bd3ec80 100644 --- a/src/main/java/TechVault/services/comments/CommentService.java +++ b/src/main/java/TechVault/services/comments/CommentService.java @@ -2,11 +2,11 @@ import java.util.List; -import TechVault.services.comments.model.Comment; +import TechVault.services.comments.model.CommentResponse; public interface CommentService { - public List getComments (String postId); + public List getComments (String postId); public void addComment(String postId, String userId, String comment); } diff --git a/src/main/java/TechVault/services/comments/CommentServiceImpl.java b/src/main/java/TechVault/services/comments/CommentServiceImpl.java index ec2c2bc..a40725b 100644 --- a/src/main/java/TechVault/services/comments/CommentServiceImpl.java +++ b/src/main/java/TechVault/services/comments/CommentServiceImpl.java @@ -1,13 +1,22 @@ package TechVault.services.comments; import java.util.List; +import java.util.UUID; -import TechVault.services.comments.model.Comment; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -public class CommentActionsImpl implements CommentActions { +import TechVault.services.comments.model.CommentResponse; +import TechVault.services.comments.persistance.CommentDao; + +@Service +public class CommentServiceImpl implements CommentService { + + @Autowired + private CommentDao commentDao; @Override - public List getComments(String postId) { + public List getComments(String postId) { // TODO Auto-generated method stub return null; @@ -15,8 +24,7 @@ public List getComments(String postId) { @Override public void addComment(String postId, String userId, String comment) { - // TODO Auto-generated method stub - + commentDao.addCommenttoBlog(postId, UUID.randomUUID().toString(), Long.valueOf(userId), comment); } } diff --git a/src/main/java/TechVault/services/comments/controller/CommentController.java b/src/main/java/TechVault/services/comments/controller/CommentController.java index 0115135..408f96f 100644 --- a/src/main/java/TechVault/services/comments/controller/CommentController.java +++ b/src/main/java/TechVault/services/comments/controller/CommentController.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.UUID; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import TechVault.services.comments.CommentService; + @Validated @@ -20,6 +23,9 @@ @RequestMapping("comment") public class CommentController { + @Autowired + private CommentService commentService; + /** * To the the profile of the user corresponding to the user id. * @return A Response entity which will have all the user details. @@ -28,19 +34,32 @@ public class CommentController { public ResponseEntity getCommentsForBlog() { HttpHeaders responseHeaders = new HttpHeaders(); //CommentResponse cr = new CommentResponse(UUID.randomUUID(), UUID.randomUUID(),(long) 123, new Timestamp(System.currentTimeMillis())); - return new ResponseEntity<>(cr, HttpStatus.OK); + return new ResponseEntity<>( HttpStatus.OK); } /** * To the the profile of the user corresponding to the user id. * @return A Response entity which will have all the user details. */ + // @RequestMapping(method = RequestMethod.POST, value = "/{blog_id}") + // public ResponseEntity postCommentsForBlog() { + // HttpHeaders responseHeaders = new HttpHeaders(); + // List x = new ArrayList<>(); + // x.add("asdasd"); + // x.add("1121e"); + // return new ResponseEntity<>(x, responseHeaders, HttpStatus.OK); + // } + @RequestMapping(method = RequestMethod.POST, value = "/{blog_id}") - public ResponseEntity postCommentsForBlog() { + public ResponseEntity postCommentsForTest() { + commentService.addComment(UUID.randomUUID().toString(), "12345", "This is a test comment"); + return new ResponseEntity<>("SUCCESS", HttpStatus.OK); + } + + @RequestMapping(method = RequestMethod.GET, value = "/") + public ResponseEntity test() { HttpHeaders responseHeaders = new HttpHeaders(); - List x = new ArrayList<>(); - x.add("asdasd"); - x.add("1121e"); - return new ResponseEntity<>(x, responseHeaders, HttpStatus.OK); + //CommentResponse cr = new CommentResponse(UUID.randomUUID(), UUID.randomUUID(),(long) 123, new Timestamp(System.currentTimeMillis())); + return new ResponseEntity<>( "Hitting", HttpStatus.OK); } } diff --git a/src/main/java/TechVault/services/comments/model/Comment.java b/src/main/java/TechVault/services/comments/model/Comment.java index 73a6fc2..af5b0e2 100644 --- a/src/main/java/TechVault/services/comments/model/Comment.java +++ b/src/main/java/TechVault/services/comments/model/Comment.java @@ -18,13 +18,13 @@ public class Comment { @Id @Field(name = "commentId") - private UUID commentId; + private String commentId; @Field(name = "postId") - private UUID postId; + private String postId; @Field(name = "parentCommentId") - private UUID parentCommentId; + private String parentCommentId; @Field(name = "userId") private long userId; diff --git a/src/main/java/TechVault/services/comments/model/CommentResponse.java b/src/main/java/TechVault/services/comments/model/CommentResponse.java index 9272f13..295ac30 100644 --- a/src/main/java/TechVault/services/comments/model/CommentResponse.java +++ b/src/main/java/TechVault/services/comments/model/CommentResponse.java @@ -1,4 +1,4 @@ -package TechVault.services.comments; +package TechVault.services.comments.model; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java index ea787e8..c6ea5f6 100644 --- a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java +++ b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java @@ -1,11 +1,19 @@ package TechVault.services.comments.persistance; import java.util.List; +import java.util.UUID; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import TechVault.services.comments.model.Comment; +@Component public class CommentDaoImpl implements CommentDao { + @Autowired + private CommentRepository commentRepository; + @Override public List getCommentsByBlog(String blogUUID) { // TODO Auto-generated method stub @@ -15,6 +23,18 @@ public List getCommentsByBlog(String blogUUID) { @Override public String addCommenttoBlog(String blogUUID, String parentCommentId, long userId, String comment) { // TODO Auto-generated method stub + System.out.println("inside commentDAO"); + commentRepository.save(Comment.builder() + .parentCommentId(parentCommentId) + .userId(userId) + .postId(blogUUID) + .build()); + + + System.out.println("printing............"); + + commentRepository.findAll().forEach(u -> System.out.println(u.getPostId())); + return null; } diff --git a/src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java b/src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java new file mode 100644 index 0000000..5736112 --- /dev/null +++ b/src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java @@ -0,0 +1,36 @@ +package TechVault.services.comments.persistance; + +import java.util.Collection; +import java.util.Collections; + +import com.mongodb.ConnectionString; +import com.mongodb.MongoClientSettings; +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; + +import org.springframework.context.annotation.Configuration; +import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; + +@Configuration +public class CommentPersistenceConfig extends AbstractMongoClientConfiguration { + + @Override + protected String getDatabaseName() { + return "comments"; + } + + @Override + public MongoClient mongoClient() { + ConnectionString connectionString = new ConnectionString("mongodb+srv://prateek:p@cluster0.kf3n4.mongodb.net/TechVault?retryWrites=true&w=majority"); + MongoClientSettings mongoClientSettings = MongoClientSettings.builder() + .applyConnectionString(connectionString) + .build(); + + return MongoClients.create(mongoClientSettings); + } + + @Override + public Collection getMappingBasePackages() { + return Collections.singleton("TechVault"); + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 211105d..7a66560 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,2 +1,4 @@ #spring.application.name: TechVault -server.port= 8080 \ No newline at end of file +server.port= 8080 +spring.data.mongodb.uri=mongodb+srv://wenqi:p@cluster0.kf3n4.mongodb.net/TechVault?retryWrites=true&w=majority +spring.data.mongodb.database=TechVault \ No newline at end of file From 9610ac4b660cd0205218ac3e6a14a5e820053258 Mon Sep 17 00:00:00 2001 From: Prateek Shroff Date: Sun, 3 Jan 2021 02:24:55 -0800 Subject: [PATCH 3/5] Cleaned API for posting comments, added logging, --- build.gradle | 1 + gradle.properties | 1 + src/main/java/TechVault/Application.java | 1 - .../PersistenceConfig.java} | 7 +-- .../services/comments/CommentService.java | 2 +- .../services/comments/CommentServiceImpl.java | 4 +- .../controller/CommentController.java | 38 ++++++++------- .../services/comments/model/Comment.java | 9 ++-- .../comments/persistance/CommentDao.java | 2 +- .../comments/persistance/CommentDaoImpl.java | 13 ++--- src/main/resources/logback-spring.xml | 47 +++++++++++++++++++ 11 files changed, 84 insertions(+), 41 deletions(-) rename src/main/java/TechVault/{services/comments/persistance/CommentPersistenceConfig.java => config/PersistenceConfig.java} (86%) create mode 100644 src/main/resources/logback-spring.xml diff --git a/build.gradle b/build.gradle index 1c69e7c..15c48fe 100644 --- a/build.gradle +++ b/build.gradle @@ -47,6 +47,7 @@ dependencies { compile group: 'org.springframework.cloud', name: 'spring-cloud-starter-sleuth', version: springSleuthVersion compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: springMongoDataVersion compile group: 'org.mongodb', name: 'mongodb-driver-sync', version: javaMongoDriverVersion + compile group: 'com.google.code.gson', name: 'gson', version: gsonVersion compile group: 'javax.el', name: 'javax.el-api', version: javaxElApiVersion compile group: 'org.glassfish', name: 'javax.el', version: glassfishVersion providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: javaxServletVersion diff --git a/gradle.properties b/gradle.properties index 686edf4..3d7e98b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,6 +15,7 @@ javaxServletVersion=3.1.0 tomcatVersion=7.0.63 springMongoDataVersion=3.0.3.RELEASE javaMongoDriverVersion=4.0.5 +gsonVersion=2.8.6 # Version and base tags can be overridden at build time. TechVaultVersion=0.1.0 \ No newline at end of file diff --git a/src/main/java/TechVault/Application.java b/src/main/java/TechVault/Application.java index 002bf22..99a26e6 100644 --- a/src/main/java/TechVault/Application.java +++ b/src/main/java/TechVault/Application.java @@ -19,5 +19,4 @@ public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { return new PersistenceExceptionTranslationPostProcessor(); } - } \ No newline at end of file diff --git a/src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java b/src/main/java/TechVault/config/PersistenceConfig.java similarity index 86% rename from src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java rename to src/main/java/TechVault/config/PersistenceConfig.java index 5736112..e6369bf 100644 --- a/src/main/java/TechVault/services/comments/persistance/CommentPersistenceConfig.java +++ b/src/main/java/TechVault/config/PersistenceConfig.java @@ -1,4 +1,4 @@ -package TechVault.services.comments.persistance; +package TechVault.config; import java.util.Collection; import java.util.Collections; @@ -12,11 +12,11 @@ import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; @Configuration -public class CommentPersistenceConfig extends AbstractMongoClientConfiguration { +public class PersistenceConfig extends AbstractMongoClientConfiguration { @Override protected String getDatabaseName() { - return "comments"; + return "TechVault"; } @Override @@ -33,4 +33,5 @@ public MongoClient mongoClient() { public Collection getMappingBasePackages() { return Collections.singleton("TechVault"); } + } diff --git a/src/main/java/TechVault/services/comments/CommentService.java b/src/main/java/TechVault/services/comments/CommentService.java index bd3ec80..d7efd5e 100644 --- a/src/main/java/TechVault/services/comments/CommentService.java +++ b/src/main/java/TechVault/services/comments/CommentService.java @@ -8,5 +8,5 @@ public interface CommentService { public List getComments (String postId); - public void addComment(String postId, String userId, String comment); + public void addComment(String contentId, String parentCommentId, String userName, String comment); } diff --git a/src/main/java/TechVault/services/comments/CommentServiceImpl.java b/src/main/java/TechVault/services/comments/CommentServiceImpl.java index a40725b..69dd84c 100644 --- a/src/main/java/TechVault/services/comments/CommentServiceImpl.java +++ b/src/main/java/TechVault/services/comments/CommentServiceImpl.java @@ -23,8 +23,8 @@ public List getComments(String postId) { } @Override - public void addComment(String postId, String userId, String comment) { - commentDao.addCommenttoBlog(postId, UUID.randomUUID().toString(), Long.valueOf(userId), comment); + public void addComment(String contentId, String parentCommentId, String userName, String comment) { + commentDao.addComment(contentId, parentCommentId, userName, comment); } } diff --git a/src/main/java/TechVault/services/comments/controller/CommentController.java b/src/main/java/TechVault/services/comments/controller/CommentController.java index 408f96f..b184388 100644 --- a/src/main/java/TechVault/services/comments/controller/CommentController.java +++ b/src/main/java/TechVault/services/comments/controller/CommentController.java @@ -1,27 +1,28 @@ package TechVault.services.comments.controller; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import TechVault.services.comments.CommentService; - - @Validated @RestController @RequestMapping("comment") public class CommentController { + private static final Logger logger = LoggerFactory.getLogger("SampleLogger"); @Autowired private CommentService commentService; @@ -41,18 +42,19 @@ public ResponseEntity getCommentsForBlog() { * To the the profile of the user corresponding to the user id. * @return A Response entity which will have all the user details. */ - // @RequestMapping(method = RequestMethod.POST, value = "/{blog_id}") - // public ResponseEntity postCommentsForBlog() { - // HttpHeaders responseHeaders = new HttpHeaders(); - // List x = new ArrayList<>(); - // x.add("asdasd"); - // x.add("1121e"); - // return new ResponseEntity<>(x, responseHeaders, HttpStatus.OK); - // } - - @RequestMapping(method = RequestMethod.POST, value = "/{blog_id}") - public ResponseEntity postCommentsForTest() { - commentService.addComment(UUID.randomUUID().toString(), "12345", "This is a test comment"); + @RequestMapping(method = RequestMethod.POST, value = "/postComment", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity postComment(@RequestBody String commentJson) { + //contentId, String parentCommentId, String userName, String comment + JsonObject commentBody = JsonParser.parseString(commentJson).getAsJsonObject(); + try { + commentService.addComment(commentBody.get("contentId").getAsString(), + commentBody.get("parentCommentId").getAsString(), + commentBody.get("userName").getAsString(), + commentBody.get("comment").getAsString()); + } catch (Exception e) { + logger.error("Error while posting comments", e); + return new ResponseEntity<>("ERROR", HttpStatus.INTERNAL_SERVER_ERROR); + } return new ResponseEntity<>("SUCCESS", HttpStatus.OK); } diff --git a/src/main/java/TechVault/services/comments/model/Comment.java b/src/main/java/TechVault/services/comments/model/Comment.java index af5b0e2..e4c9f72 100644 --- a/src/main/java/TechVault/services/comments/model/Comment.java +++ b/src/main/java/TechVault/services/comments/model/Comment.java @@ -1,7 +1,6 @@ package TechVault.services.comments.model; import java.sql.Timestamp; -import java.util.UUID; import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Builder; @@ -20,14 +19,14 @@ public class Comment { @Field(name = "commentId") private String commentId; - @Field(name = "postId") - private String postId; + @Field(name = "contentId") + private String contentId; @Field(name = "parentCommentId") private String parentCommentId; - @Field(name = "userId") - private long userId; + @Field(name = "userName") + private String userName; @JsonFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss") @Field(name = "postedTime") diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDao.java b/src/main/java/TechVault/services/comments/persistance/CommentDao.java index 63a29e2..f112fcc 100644 --- a/src/main/java/TechVault/services/comments/persistance/CommentDao.java +++ b/src/main/java/TechVault/services/comments/persistance/CommentDao.java @@ -8,7 +8,7 @@ public interface CommentDao { public List getCommentsByBlog(String blogUUID); - public String addCommenttoBlog(String blogUUID, String parentCommentId, long userId, String comment); + public String addComment(String contentId, String parentCommentId, String userName, String comment); } diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java index c6ea5f6..26a95ba 100644 --- a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java +++ b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java @@ -21,20 +21,13 @@ public List getCommentsByBlog(String blogUUID) { } @Override - public String addCommenttoBlog(String blogUUID, String parentCommentId, long userId, String comment) { - // TODO Auto-generated method stub - System.out.println("inside commentDAO"); + public String addComment(String contentId, String parentCommentId, String userName, String comment) { commentRepository.save(Comment.builder() .parentCommentId(parentCommentId) - .userId(userId) - .postId(blogUUID) + .userName(userName) + .contentId(contentId) .build()); - - System.out.println("printing............"); - - commentRepository.findAll().forEach(u -> System.out.println(u.getPostId())); - return null; } diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml new file mode 100644 index 0000000..68aea23 --- /dev/null +++ b/src/main/resources/logback-spring.xml @@ -0,0 +1,47 @@ + + + + + + + + + %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable + + + + + + ${LOGS}/spring-boot-logger.log + + %d %p %C{1.} [%t] %m%n + + + + + ${LOGS}/archived/spring-boot-logger-%d{yyyy-MM-dd}.%i.log + + + 10MB + + + + + + + + + + + + + + + + + \ No newline at end of file From 4a5bc6b5261ec34da966604d04be8c9aa87d4740 Mon Sep 17 00:00:00 2001 From: Prateek Shroff Date: Sat, 16 Jan 2021 17:12:44 -0800 Subject: [PATCH 4/5] Added getComments API and worked on previous comments --- build.gradle | 1 + gradle.properties | 1 + .../TechVault/config/PersistenceConfig.java | 12 +++++- .../services/comments/CommentService.java | 2 +- .../services/comments/CommentServiceImpl.java | 31 +++++++++++--- .../controller/CommentController.java | 31 +++++++------- .../services/comments/model/Comment.java | 9 ++-- .../comments/model/CommentResponse.java | 30 +++++++------ .../comments/persistance/CommentDaoImpl.java | 34 --------------- .../CommentDao.java | 7 ++-- .../comments/persistence/CommentDaoImpl.java | 42 +++++++++++++++++++ .../CommentRepository.java | 6 ++- src/main/resources/logback-spring.xml | 2 +- 13 files changed, 124 insertions(+), 84 deletions(-) delete mode 100644 src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java rename src/main/java/TechVault/services/comments/{persistance => persistence}/CommentDao.java (52%) create mode 100644 src/main/java/TechVault/services/comments/persistence/CommentDaoImpl.java rename src/main/java/TechVault/services/comments/{persistance => persistence}/CommentRepository.java (62%) diff --git a/build.gradle b/build.gradle index 15c48fe..bf723e3 100644 --- a/build.gradle +++ b/build.gradle @@ -48,6 +48,7 @@ dependencies { compile group: 'org.springframework.data', name: 'spring-data-mongodb', version: springMongoDataVersion compile group: 'org.mongodb', name: 'mongodb-driver-sync', version: javaMongoDriverVersion compile group: 'com.google.code.gson', name: 'gson', version: gsonVersion + compile group: 'com.google.guava', name: 'guava', version: guavaVersion compile group: 'javax.el', name: 'javax.el-api', version: javaxElApiVersion compile group: 'org.glassfish', name: 'javax.el', version: glassfishVersion providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: javaxServletVersion diff --git a/gradle.properties b/gradle.properties index 3d7e98b..2baa5dd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,6 +16,7 @@ tomcatVersion=7.0.63 springMongoDataVersion=3.0.3.RELEASE javaMongoDriverVersion=4.0.5 gsonVersion=2.8.6 +guavaVersion=11.0.2 # Version and base tags can be overridden at build time. TechVaultVersion=0.1.0 \ No newline at end of file diff --git a/src/main/java/TechVault/config/PersistenceConfig.java b/src/main/java/TechVault/config/PersistenceConfig.java index e6369bf..eb39b0c 100644 --- a/src/main/java/TechVault/config/PersistenceConfig.java +++ b/src/main/java/TechVault/config/PersistenceConfig.java @@ -8,20 +8,28 @@ import com.mongodb.client.MongoClient; import com.mongodb.client.MongoClients; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration; @Configuration public class PersistenceConfig extends AbstractMongoClientConfiguration { + + @Value("${spring.data.mongodb.database}") + private String dbName; + + @Value("${spring.data.mongodb.uri}") + private String uri; @Override protected String getDatabaseName() { - return "TechVault"; + return dbName; } @Override public MongoClient mongoClient() { - ConnectionString connectionString = new ConnectionString("mongodb+srv://prateek:p@cluster0.kf3n4.mongodb.net/TechVault?retryWrites=true&w=majority"); + //"mongodb+srv://prateek:p@cluster0.kf3n4.mongodb.net/TechVault?retryWrites=true&w=majority" + ConnectionString connectionString = new ConnectionString(uri); MongoClientSettings mongoClientSettings = MongoClientSettings.builder() .applyConnectionString(connectionString) .build(); diff --git a/src/main/java/TechVault/services/comments/CommentService.java b/src/main/java/TechVault/services/comments/CommentService.java index d7efd5e..c19fa7e 100644 --- a/src/main/java/TechVault/services/comments/CommentService.java +++ b/src/main/java/TechVault/services/comments/CommentService.java @@ -6,7 +6,7 @@ public interface CommentService { - public List getComments (String postId); + public List getComments (String contentId); public void addComment(String contentId, String parentCommentId, String userName, String comment); } diff --git a/src/main/java/TechVault/services/comments/CommentServiceImpl.java b/src/main/java/TechVault/services/comments/CommentServiceImpl.java index 69dd84c..a96a93e 100644 --- a/src/main/java/TechVault/services/comments/CommentServiceImpl.java +++ b/src/main/java/TechVault/services/comments/CommentServiceImpl.java @@ -1,13 +1,19 @@ package TechVault.services.comments; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.UUID; +import com.google.common.base.Strings; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import TechVault.services.comments.model.Comment; import TechVault.services.comments.model.CommentResponse; -import TechVault.services.comments.persistance.CommentDao; +import TechVault.services.comments.persistence.CommentDao; @Service public class CommentServiceImpl implements CommentService { @@ -16,10 +22,25 @@ public class CommentServiceImpl implements CommentService { private CommentDao commentDao; @Override - public List getComments(String postId) { - // TODO Auto-generated method stub - - return null; + public List getComments(String contentId) { + + List comments = commentDao.getCommentsByBlog(contentId); + Map map = new HashMap<>(); + List result = new ArrayList<>(); + for (Comment comment : comments) { + CommentResponse commentResponse = new CommentResponse(comment); + if (Strings.isNullOrEmpty(comment.getParentCommentId())) { + result.add(commentResponse); + } + map.put(comment.getCommentId(), commentResponse); + } + for (Comment comment : comments) { + if (!Strings.isNullOrEmpty(comment.getParentCommentId())) { + CommentResponse parent = map.get(comment.getParentCommentId()); + parent.getChildComments().add(map.get(comment.getCommentId())); + } + } + return result; } @Override diff --git a/src/main/java/TechVault/services/comments/controller/CommentController.java b/src/main/java/TechVault/services/comments/controller/CommentController.java index b184388..78d1bd7 100644 --- a/src/main/java/TechVault/services/comments/controller/CommentController.java +++ b/src/main/java/TechVault/services/comments/controller/CommentController.java @@ -1,5 +1,7 @@ package TechVault.services.comments.controller; +import java.util.List; + import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -11,18 +13,20 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import TechVault.services.comments.CommentService; +import TechVault.services.comments.model.CommentResponse; @Validated @RestController @RequestMapping("comment") public class CommentController { - private static final Logger logger = LoggerFactory.getLogger("SampleLogger"); + private static final Logger LOGGER = LoggerFactory.getLogger(CommentController.class); @Autowired private CommentService commentService; @@ -31,11 +35,16 @@ public class CommentController { * To the the profile of the user corresponding to the user id. * @return A Response entity which will have all the user details. */ - @RequestMapping(method = RequestMethod.GET, value = "/{blog_id}") - public ResponseEntity getCommentsForBlog() { - HttpHeaders responseHeaders = new HttpHeaders(); - //CommentResponse cr = new CommentResponse(UUID.randomUUID(), UUID.randomUUID(),(long) 123, new Timestamp(System.currentTimeMillis())); - return new ResponseEntity<>( HttpStatus.OK); + @RequestMapping(method = RequestMethod.GET, value = "/{contentId}") + public ResponseEntity getComments(@PathVariable String contentId) { + List comments = null; + try { + comments = commentService.getComments(contentId); + } catch (Exception e) { + LOGGER.error("Unable to get comments ", e); + return new ResponseEntity<>("ERROR", HttpStatus.INTERNAL_SERVER_ERROR); + } + return new ResponseEntity<>(comments, HttpStatus.OK); } /** @@ -44,7 +53,7 @@ public ResponseEntity getCommentsForBlog() { */ @RequestMapping(method = RequestMethod.POST, value = "/postComment", produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity postComment(@RequestBody String commentJson) { - //contentId, String parentCommentId, String userName, String comment + JsonObject commentBody = JsonParser.parseString(commentJson).getAsJsonObject(); try { commentService.addComment(commentBody.get("contentId").getAsString(), @@ -52,16 +61,10 @@ public ResponseEntity postComment(@RequestBody String commentJson) { commentBody.get("userName").getAsString(), commentBody.get("comment").getAsString()); } catch (Exception e) { - logger.error("Error while posting comments", e); + LOGGER.error("Error while posting comments", e); return new ResponseEntity<>("ERROR", HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>("SUCCESS", HttpStatus.OK); } - @RequestMapping(method = RequestMethod.GET, value = "/") - public ResponseEntity test() { - HttpHeaders responseHeaders = new HttpHeaders(); - //CommentResponse cr = new CommentResponse(UUID.randomUUID(), UUID.randomUUID(),(long) 123, new Timestamp(System.currentTimeMillis())); - return new ResponseEntity<>( "Hitting", HttpStatus.OK); - } } diff --git a/src/main/java/TechVault/services/comments/model/Comment.java b/src/main/java/TechVault/services/comments/model/Comment.java index e4c9f72..ea81c95 100644 --- a/src/main/java/TechVault/services/comments/model/Comment.java +++ b/src/main/java/TechVault/services/comments/model/Comment.java @@ -1,12 +1,10 @@ package TechVault.services.comments.model; -import java.sql.Timestamp; - -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Builder; import lombok.Getter; import lombok.Setter; import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.index.Indexed; import org.springframework.data.mongodb.core.mapping.Document; import org.springframework.data.mongodb.core.mapping.Field; @@ -16,9 +14,9 @@ @Setter public class Comment { @Id - @Field(name = "commentId") private String commentId; + @Indexed @Field(name = "contentId") private String contentId; @@ -28,9 +26,8 @@ public class Comment { @Field(name = "userName") private String userName; - @JsonFormat(pattern = "yyyy-mm-dd'T'HH:mm:ss") @Field(name = "postedTime") - private Timestamp postedTime; + private String postedTime; @Field(name = "comment") private String comment; diff --git a/src/main/java/TechVault/services/comments/model/CommentResponse.java b/src/main/java/TechVault/services/comments/model/CommentResponse.java index 295ac30..1c1a3e1 100644 --- a/src/main/java/TechVault/services/comments/model/CommentResponse.java +++ b/src/main/java/TechVault/services/comments/model/CommentResponse.java @@ -1,29 +1,27 @@ package TechVault.services.comments.model; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; + +import lombok.AllArgsConstructor; import lombok.Data; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpStatus; -import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; -import java.util.UUID; @Data -@RequiredArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) +@AllArgsConstructor public class CommentResponse { - public CommentResponse(UUID randomUUID, UUID randomUUID2, long l, Timestamp timestamp) { - } - private UUID commentId; - private UUID postId; - private long userId; - private Timestamp postedTime; + public CommentResponse (Comment comment ) { + this(comment.getCommentId(), comment.getContentId(), + comment.getUserName(), comment.getPostedTime(), comment.getComment(), + new ArrayList<>()); + } + + private String commentId; + private String contentId; + private String userName; + private String postedTime; private String comment; private List childComments; - - @JsonIgnore - private HttpStatus status; } diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java b/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java deleted file mode 100644 index 26a95ba..0000000 --- a/src/main/java/TechVault/services/comments/persistance/CommentDaoImpl.java +++ /dev/null @@ -1,34 +0,0 @@ -package TechVault.services.comments.persistance; - -import java.util.List; -import java.util.UUID; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Component; - -import TechVault.services.comments.model.Comment; - -@Component -public class CommentDaoImpl implements CommentDao { - - @Autowired - private CommentRepository commentRepository; - - @Override - public List getCommentsByBlog(String blogUUID) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String addComment(String contentId, String parentCommentId, String userName, String comment) { - commentRepository.save(Comment.builder() - .parentCommentId(parentCommentId) - .userName(userName) - .contentId(contentId) - .build()); - - return null; - } - -} diff --git a/src/main/java/TechVault/services/comments/persistance/CommentDao.java b/src/main/java/TechVault/services/comments/persistence/CommentDao.java similarity index 52% rename from src/main/java/TechVault/services/comments/persistance/CommentDao.java rename to src/main/java/TechVault/services/comments/persistence/CommentDao.java index f112fcc..772a55b 100644 --- a/src/main/java/TechVault/services/comments/persistance/CommentDao.java +++ b/src/main/java/TechVault/services/comments/persistence/CommentDao.java @@ -1,4 +1,4 @@ -package TechVault.services.comments.persistance; +package TechVault.services.comments.persistence; import java.util.List; @@ -8,7 +8,6 @@ public interface CommentDao { public List getCommentsByBlog(String blogUUID); - public String addComment(String contentId, String parentCommentId, String userName, String comment); - - + public void addComment(String contentId, String parentCommentId, String userName, String comment); + } diff --git a/src/main/java/TechVault/services/comments/persistence/CommentDaoImpl.java b/src/main/java/TechVault/services/comments/persistence/CommentDaoImpl.java new file mode 100644 index 0000000..8fc6baa --- /dev/null +++ b/src/main/java/TechVault/services/comments/persistence/CommentDaoImpl.java @@ -0,0 +1,42 @@ +package TechVault.services.comments.persistence; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import TechVault.services.comments.model.Comment; + + +@Component +public class CommentDaoImpl implements CommentDao { + + private static final Logger LOGGER = LoggerFactory.getLogger(CommentDaoImpl.class); + private static final DateTimeFormatter formatter = DateTimeFormatter.ISO_LOCAL_DATE_TIME; + + @Autowired + private CommentRepository commentRepository; + + @Override + public List getCommentsByBlog(String contentId) { + return commentRepository.findByContentIdOrderByPostedTimeDesc(contentId); + } + + @Override + public void addComment(String contentId, String parentCommentId, String userName, String comment) { + commentRepository.save(Comment.builder() + .parentCommentId(parentCommentId) + .userName(userName) + .contentId(contentId) + .comment(comment) + .postedTime(LocalDateTime.now().format(formatter)) + .build()); + + LOGGER.info("Successfully save comment for user: {} and contentId: {}", userName, contentId); + } + +} diff --git a/src/main/java/TechVault/services/comments/persistance/CommentRepository.java b/src/main/java/TechVault/services/comments/persistence/CommentRepository.java similarity index 62% rename from src/main/java/TechVault/services/comments/persistance/CommentRepository.java rename to src/main/java/TechVault/services/comments/persistence/CommentRepository.java index 13b7a9d..56e84cb 100644 --- a/src/main/java/TechVault/services/comments/persistance/CommentRepository.java +++ b/src/main/java/TechVault/services/comments/persistence/CommentRepository.java @@ -1,9 +1,13 @@ -package TechVault.services.comments.persistance; +package TechVault.services.comments.persistence; import TechVault.services.comments.model.Comment; + +import java.util.List; + import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.stereotype.Repository; @Repository public interface CommentRepository extends MongoRepository { + public List findByContentIdOrderByPostedTimeDesc(String contentId); } \ No newline at end of file diff --git a/src/main/resources/logback-spring.xml b/src/main/resources/logback-spring.xml index 68aea23..cc090c5 100644 --- a/src/main/resources/logback-spring.xml +++ b/src/main/resources/logback-spring.xml @@ -39,7 +39,7 @@ - + From 42399c4d153ab4e4904daa5c22aa9f016f8de39f Mon Sep 17 00:00:00 2001 From: Prateek Shroff Date: Sat, 6 Feb 2021 16:14:01 -0800 Subject: [PATCH 5/5] Added lombok annotationProcessor to build file --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index bf723e3..428daaf 100644 --- a/build.gradle +++ b/build.gradle @@ -52,6 +52,7 @@ dependencies { compile group: 'javax.el', name: 'javax.el-api', version: javaxElApiVersion compile group: 'org.glassfish', name: 'javax.el', version: glassfishVersion providedCompile group: 'javax.servlet', name: 'javax.servlet-api', version: javaxServletVersion + annotationProcessor 'org.projectlombok:lombok:1.18.16' tomcat "org.apache.tomcat.embed:tomcat-embed-core:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-logging-juli:${tomcatVersion}", "org.apache.tomcat.embed:tomcat-embed-jasper:${tomcatVersion}"