Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ WHERE NOT (x)-[:Participated]->(a) AND lower(a.name) CONTAINS lower($activityNam
RETURN a,c,u
SKIP $offset LIMIT $limit
""")
List<ActivityEntity> getPaginationNotSubscribed(@Param("offset") int offset, @Param("limit")int limit,@Param("userID") String userID, @Param("activityName") String activityName);
List<ActivityEntity> getPaginationNotSubscribed(@Param("offset") int offset, @Param("limit") int limit,
@Param("userID") String userID, @Param("activityName") String activityName);

@Query("""
MATCH (u:User)
Expand All @@ -50,20 +51,24 @@ WHERE elementId(u) = $userID
List<ActivityEntity> getSubscribedActivities(@Param("userID") String userID);

@Query("""
MATCH (u:User)-[:Participated]->(a:Activity)<-[:`Related-To`]-(p:Post)
WHERE elementId(u)=$userID
SET a.streak=p.streak
RETURN a;
MATCH (u:User)-[:Participated]->(a:Activity)
WHERE elementId(u) = $userID
OPTIONAL MATCH (a)<-[:`Related-To`]-(p:Post)
WITH a, p
SET a.streak = coalesce(p.streak, 0)
RETURN DISTINCT a;
""")
List<ActivityEntity> getSubscribedActivitiesWithStreak(@Param("userID") String userID);

@Query("""
MATCH (u:User)-[:Participated]->(a:Activity)<-[:`Related-To`]-(p:Post)
MATCH (u:User)-[:Participated]->(a:Activity)
WHERE elementId(u) = $userID
AND lower(a.name) CONTAINS lower($activityName)
OPTIONAL MATCH (a)<-[:`Related-To`]-(p:Post)
WITH a, p
SET a.streak = coalesce(p.streak, 0)
SET a.streak = p.streak
RETURN DISTINCT a;

""")
List<ActivityEntity> getSubscribedActivitiesWithStreak(@Param("userID") String userID,
@Param("activityName") String activityName);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package es.iespuertodelacruz.routinefights.comment.domain;

import java.time.LocalDateTime;
import java.util.Objects;

import es.iespuertodelacruz.routinefights.post.domain.Post;
import es.iespuertodelacruz.routinefights.shared.utils.EntitiesTimestamps;
import es.iespuertodelacruz.routinefights.user.domain.User;

public class Comment extends EntitiesTimestamps {
private String id;
private String message;
private Post post;
private User user;
private Comment replingComment;

public Comment() {
}

public Comment(String id) {
this.id = id;
}

public Comment(String id, String message, LocalDateTime createdAt, LocalDateTime updatedAt,
LocalDateTime deletedAt, Post post, User user, Comment comment) {
super(createdAt, updatedAt, deletedAt);
this.id = id;
this.message = message;
this.post = post;
this.user = user;
this.replingComment = comment;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

public Post getPost() {
return post;
}

public void setPost(Post post) {
this.post = post;
}

public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

public Comment getReplingComment() {
return replingComment;
}

public void setReplingComment(Comment comment) {
this.replingComment = comment;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (!(o instanceof Comment))
return false;
Comment comment1 = (Comment) o;
return Objects.equals(id, comment1.id);
}

@Override
public int hashCode() {
return Objects.hash(id);
}

@Override
public String toString() {
return "Comment{" +
"id='" + id + '\'' +
", message='" + message + '\'' +
", createdAt=" + getCreatedAt() +
", updatedAt=" + getUpdatedAt() +
", deletedAt=" + getDeletedAt() +
", post=" + post +
", user=" + user +
", comment=" + replingComment +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package es.iespuertodelacruz.routinefights.comment.domain.ports.primary;


import java.util.List;

import es.iespuertodelacruz.routinefights.comment.domain.Comment;
import es.iespuertodelacruz.routinefights.user.domain.User;

public interface ICommentService {

Comment save(String message, User user, String postID, String replingID);
List<Comment> findByPostID(String postID);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package es.iespuertodelacruz.routinefights.comment.domain.ports.secondary;

import java.util.List;

import es.iespuertodelacruz.routinefights.comment.domain.Comment;

public interface ICommentRepository {
Comment comment(Comment comment);
List<Comment> findByPostID(String postID);
Comment findById(String commentID);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package es.iespuertodelacruz.routinefights.comment.domain.services;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.stereotype.Service;

import es.iespuertodelacruz.routinefights.comment.domain.Comment;
import es.iespuertodelacruz.routinefights.comment.domain.ports.primary.ICommentService;
import es.iespuertodelacruz.routinefights.comment.domain.ports.secondary.ICommentRepository;
import es.iespuertodelacruz.routinefights.post.domain.Post;
import es.iespuertodelacruz.routinefights.post.domain.ports.secondary.IPostRepository;
import es.iespuertodelacruz.routinefights.user.domain.User;
@Service
public class CommentService implements ICommentService {

private ICommentRepository commentRepository;
private IPostRepository postRepository;

public CommentService(ICommentRepository commentRepository, IPostRepository postRepository) {
this.commentRepository = commentRepository;
this.postRepository = postRepository;
}

@Override
public Comment save(String message, User user, String postID, String replingID) {
Comment comment = new Comment();
comment.setMessage(message);
comment.setCreatedAt(LocalDateTime.now());
comment.setUser(user);
Post post = postRepository.findById(postID);
if (post == null) {
throw new IllegalArgumentException("Post not found");
}
comment.setPost(post);
if (replingID != null) {
Comment replingComment = commentRepository.findById(replingID);
if (replingComment == null) {
throw new IllegalArgumentException("Repling comment not found");
}
comment.setReplingComment(replingComment);
}

return commentRepository.comment(comment);
}

@Override
public List<Comment> findByPostID(String postID) {
return commentRepository.findByPostID(postID);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.controllers;

import java.util.List;

import org.springframework.graphql.data.method.annotation.Argument;
import org.springframework.graphql.data.method.annotation.MutationMapping;
import org.springframework.graphql.data.method.annotation.QueryMapping;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;

import es.iespuertodelacruz.routinefights.comment.domain.ports.primary.ICommentService;
import es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.dtos.CommentInputV2;
import es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.dtos.CommentOutputV2;
import es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.mapper.CommentOutputV2Mapper;
import es.iespuertodelacruz.routinefights.user.domain.User;
import es.iespuertodelacruz.routinefights.user.domain.ports.primary.IUserService;

@Controller
@CrossOrigin
public class CommentControllerV2 {

private ICommentService commentService;
private CommentOutputV2Mapper commentOutputV2Mapper;
private IUserService userService;

public CommentControllerV2(ICommentService commentService,
CommentOutputV2Mapper commentOutputV2Mapper, IUserService userService) {
this.commentService = commentService;
this.commentOutputV2Mapper = commentOutputV2Mapper;
this.userService = userService;
}

@MutationMapping("postComment")
public CommentOutputV2 postComment(@Argument("commentInput") CommentInputV2 commentInput) {
User user = userService.findByEmailOnlyBase(SecurityContextHolder.getContext().getAuthentication().getName());
return commentOutputV2Mapper.toDTO(commentService.save(commentInput.message(), user,
commentInput.postID(), commentInput.replingID()));
}

@QueryMapping("getComments")
public List<CommentOutputV2> getComments(@Argument("postID") String postID) {
return commentOutputV2Mapper.toDTO(commentService.findByPostID(postID));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.dtos;

public record CommentInputV2(String message, String postID, String replingID) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.dtos;

import java.time.LocalDateTime;

import es.iespuertodelacruz.routinefights.user.infrastructure.adapters.primary.v2.dtos.UserOutputDTOV2;

public record CommentOutputV2(String id, String message, LocalDateTime createdAt, UserOutputDTOV2 user) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.mapper;

import java.util.List;

import org.mapstruct.Mapper;

import es.iespuertodelacruz.routinefights.comment.domain.Comment;
import es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.primary.v2.dtos.CommentOutputV2;
import es.iespuertodelacruz.routinefights.user.infrastructure.adapters.primary.v2.mappers.UserOutputV2Mapper;

@Mapper(componentModel = "spring",uses = UserOutputV2Mapper.class)
public interface CommentOutputV2Mapper {

CommentOutputV2 toDTO(Comment comment);

List<CommentOutputV2> toDTO(List<Comment> comment);

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.neo4j.core.schema.Id;
import org.springframework.data.neo4j.core.schema.Node;
import org.springframework.data.neo4j.core.schema.Relationship;
import org.springframework.data.neo4j.core.schema.TargetNode;

import es.iespuertodelacruz.routinefights.post.infrastructure.adapters.secondary.entities.PostEntity;
import es.iespuertodelacruz.routinefights.shared.utils.EntitiesTimestamps;
Expand All @@ -29,7 +30,8 @@ public class CommentEntity extends EntitiesTimestamps {
private UserEntity user;

@Relationship(type = "Replied_To", direction = Relationship.Direction.OUTGOING)
private CommentEntity comment;
@TargetNode()
private CommentEntity replingComment;

public CommentEntity() {
}
Expand All @@ -41,7 +43,7 @@ public CommentEntity(String id, String message, LocalDateTime createdAt, LocalDa
this.message = message;
this.post = post;
this.user = user;
this.comment = comment;
this.replingComment = comment;
}

public String getId() {
Expand Down Expand Up @@ -76,12 +78,12 @@ public void setUser(UserEntity user) {
this.user = user;
}

public CommentEntity getComment() {
return this.comment;
public CommentEntity getReplingComment() {
return this.replingComment;
}

public void setComment(CommentEntity comment) {
this.comment = comment;
public void setReplingComment(CommentEntity comment) {
this.replingComment = comment;
}

@Override
Expand Down Expand Up @@ -110,7 +112,7 @@ public String toString() {
", deletedAt='" + getDeletedAt() + "'" +
", post='" + getPost() + "'" +
", user='" + getUser() + "'" +
", comment='" + getComment() + "'" +
", comment='" + getReplingComment() + "'" +
"}";
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.secondary.mappers;

import java.util.List;

import org.mapstruct.Mapper;

import es.iespuertodelacruz.routinefights.comment.domain.Comment;
import es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.secondary.entities.CommentEntity;
import es.iespuertodelacruz.routinefights.post.infrastructure.adapters.secondary.mappers.PostEntityMapper;
import es.iespuertodelacruz.routinefights.user.infrastructure.adapters.secondary.mappers.IUserEntityMapper;

@Mapper(componentModel = "spring",
uses = {IUserEntityMapper.class, PostEntityMapper.class})
public interface CommentEntityMapper {

CommentEntity toEntity(Comment comment);

List<CommentEntity> toEntity(List<Comment> comment);

Comment toDomain(CommentEntity commentEntity);

List<Comment> toDomain(List<CommentEntity> commentEntity);


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.secondary.repositories;

import java.util.List;

import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.stereotype.Repository;

import es.iespuertodelacruz.routinefights.comment.infrastructure.adapters.secondary.entities.CommentEntity;

@Repository
public interface ICommentEntityRepository extends Neo4jRepository<CommentEntity, String> {
List<CommentEntity> findByPostId(String postID);
}
Loading