-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #320 from COSC-499-W2023/BlurringS3OnProd
Final changes, Notification and Comments enabled
- Loading branch information
Showing
28 changed files
with
709 additions
and
78 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
app/Java/business/src/main/java/com/exzbt/business/comment/CommentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.exzbt.business.comment; | ||
|
||
import com.exzbt.business.comment.mappers.CommentDTO; | ||
import com.exzbt.business.comment.mappers.CommentRequest; | ||
import com.exzbt.business.notification.NotificationService; | ||
import com.exzbt.business.request.RequestService; | ||
import com.exzbt.business.request.mappers.RequestDetailsDTO; | ||
import com.exzbt.transaction.comments.api.CommentsTransactions; | ||
import com.exzbt.transaction.comments.impl.Comment; | ||
import com.exzbt.transaction.notifications.api.NotificationTransactions; | ||
import com.exzbt.transaction.notifications.impl.Notification; | ||
import com.exzbt.transaction.request.impl.Request; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
@Service | ||
@AllArgsConstructor | ||
public class CommentService { | ||
@Autowired | ||
private CommentsTransactions commentsTransactions; | ||
|
||
@Autowired | ||
private NotificationService notificationService; | ||
|
||
@Autowired | ||
private RequestService requestService; | ||
|
||
public List<CommentDTO> getCommentsByRequestId(String requestId) { | ||
List<Comment> comments = commentsTransactions.findByRequestId(requestId); | ||
return comments.stream() | ||
.map(comment -> new CommentDTO().convertDTO(comment)).toList(); | ||
} | ||
|
||
public void createComment(CommentRequest commentRequest) { | ||
RequestDetailsDTO requestDetails = requestService.getRequestByRequestId(commentRequest.getRequestId()); | ||
|
||
commentsTransactions.save(commentRequest.convertFromDTO()); | ||
|
||
String assigneeId = Objects.equals(commentRequest.getCreatorId(), requestDetails.getAssigneeId())? | ||
requestDetails.getCreatorId() : requestDetails.getAssigneeId(); | ||
|
||
notificationService.sendNotification(requestDetails.getTitle() + " - has a new comment!", | ||
assigneeId , commentRequest.getCreatorId(), new Date()); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
app/Java/business/src/main/java/com/exzbt/business/comment/mappers/CommentDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.exzbt.business.comment.mappers; | ||
|
||
import com.exzbt.transaction.comments.impl.Comment; | ||
import com.exzbt.transaction.notifications.impl.Notification; | ||
import jakarta.persistence.Column; | ||
import lombok.*; | ||
|
||
import java.util.Date; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
@Setter | ||
public class CommentDTO { | ||
private String commentId; | ||
private String sender; | ||
private String requestId; | ||
private String content; | ||
private Date created; | ||
|
||
public CommentDTO convertDTO(Comment comment) { | ||
this.setCommentId(comment.getCommentId()); | ||
this.setSender(comment.getSender()); | ||
this.setRequestId(comment.getRequestId()); | ||
this.setContent(comment.getContent()); | ||
this.setCreated(comment.getCreated()); | ||
return this; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
app/Java/business/src/main/java/com/exzbt/business/comment/mappers/CommentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.exzbt.business.comment.mappers; | ||
|
||
import com.exzbt.transaction.comments.impl.Comment; | ||
import lombok.*; | ||
|
||
import java.util.Date; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
@ToString | ||
@EqualsAndHashCode | ||
@Setter | ||
public class CommentRequest { | ||
private String sender; | ||
private String requestId; | ||
private String creatorId; | ||
private String content; | ||
private Date created; | ||
|
||
public Comment convertFromDTO() { | ||
Comment comment = new Comment(); | ||
comment.setContent(this.getContent()); | ||
comment.setCreated(new Date()); | ||
comment.setSender(this.getSender()); | ||
comment.setRequestId(this.getRequestId()); | ||
|
||
return comment; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...va/transaction/src/main/java/com/exzbt/transaction/comments/api/CommentsTransactions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.exzbt.transaction.comments.api; | ||
|
||
import com.exzbt.transaction.comments.impl.Comment; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@Transactional | ||
public interface CommentsTransactions extends JpaRepository<Comment, String> { | ||
List<Comment> findByRequestId(String requestId); | ||
} |
35 changes: 35 additions & 0 deletions
35
app/Java/transaction/src/main/java/com/exzbt/transaction/comments/impl/Comment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.exzbt.transaction.comments.impl; | ||
import jakarta.persistence.*; | ||
import lombok.*; | ||
import org.hibernate.annotations.GenericGenerator; | ||
|
||
import java.util.Date; | ||
|
||
@Entity | ||
@Table(name = "Comment") | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
@EqualsAndHashCode | ||
public class Comment { | ||
@Id | ||
@GeneratedValue(generator = "UUID") | ||
@GenericGenerator( | ||
name = "UUID", | ||
strategy = "org.hibernate.id.UUIDGenerator" | ||
) | ||
private String commentId; | ||
|
||
@Column(nullable = false) | ||
private String sender; | ||
|
||
@Column(nullable = false) | ||
private String requestId; | ||
|
||
@Column | ||
private String content; | ||
|
||
@Column(nullable = false) | ||
private Date created; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
app/Java/widget/src/main/java/com/exzbt/widget/comment/CommentCRUD.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.exzbt.widget.comment; | ||
|
||
import com.exzbt.business.comment.CommentService; | ||
import com.exzbt.business.comment.mappers.CommentDTO; | ||
import com.exzbt.business.comment.mappers.CommentRequest; | ||
import com.exzbt.business.notification.NotificationService; | ||
import com.exzbt.business.notification.mappers.NotificationDTO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("api/v1/comments") | ||
public class CommentCRUD { | ||
@Autowired | ||
private CommentService commentService; | ||
|
||
@GetMapping("{requestId}") | ||
public List<CommentDTO> getComments(@PathVariable("requestId") String requestId) { | ||
return commentService.getCommentsByRequestId(requestId); | ||
} | ||
|
||
@PostMapping("create/{requestId}") | ||
public void updateNotifications(@RequestBody CommentRequest request) { | ||
commentService.createComment(request); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.