-
Notifications
You must be signed in to change notification settings - Fork 22
feat: implement comments on files and folders with @mentions and noti… #108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
priyanshuvishwakarma273403
wants to merge
1
commit into
Vault-Web:main
Choose a base branch
from
priyanshuvishwakarma273403:feat/comments-mentions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,097
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
backend/src/main/java/cloudpage/controller/CommentController.java
This file contains hidden or 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,55 @@ | ||
| package cloudpage.controller; | ||
|
|
||
| import cloudpage.dto.CommentDto; | ||
| import cloudpage.dto.CreateCommentRequest; | ||
| import cloudpage.service.CommentService; | ||
| import cloudpage.service.UserService; | ||
| import jakarta.validation.Valid; | ||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| /** Controller for CRUD actions on comments left on files/folders. */ | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/comments") | ||
| public class CommentController { | ||
|
|
||
| private final CommentService commentService; | ||
| private final UserService userService; | ||
|
|
||
| /** Adds a new comment on a file or folder. */ | ||
| @PostMapping | ||
| public ResponseEntity<CommentDto> addComment(@Valid @RequestBody CreateCommentRequest request) | ||
| throws IOException { | ||
| var user = userService.getCurrentUser(); | ||
| CommentDto comment = commentService.addComment(user, request); | ||
| return ResponseEntity.ok(comment); | ||
| } | ||
|
|
||
| /** Lists all comments on a specific file or folder. */ | ||
| @GetMapping | ||
| public ResponseEntity<List<CommentDto>> listComments( | ||
| @RequestParam String ownerUsername, @RequestParam String filePath) throws IOException { | ||
| var user = userService.getCurrentUser(); | ||
| List<CommentDto> comments = commentService.listComments(user, ownerUsername, filePath); | ||
| return ResponseEntity.ok(comments); | ||
| } | ||
|
|
||
| /** Deletes a comment by ID. */ | ||
| @DeleteMapping("/{id}") | ||
| public ResponseEntity<Void> deleteComment(@PathVariable Long id) { | ||
| var user = userService.getCurrentUser(); | ||
| commentService.deleteComment(user, id); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
backend/src/main/java/cloudpage/controller/NotificationController.java
This file contains hidden or 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 cloudpage.controller; | ||
|
|
||
| import cloudpage.dto.NotificationDto; | ||
| import cloudpage.service.NotificationService; | ||
| import cloudpage.service.UserService; | ||
| import java.util.List; | ||
| import lombok.RequiredArgsConstructor; | ||
| 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.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| /** Controller for retrieving and managing notifications. */ | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/notifications") | ||
| public class NotificationController { | ||
|
|
||
| private final NotificationService notificationService; | ||
| private final UserService userService; | ||
|
|
||
| /** Lists notifications for the current authenticated user. */ | ||
| @GetMapping | ||
| public ResponseEntity<List<NotificationDto>> listNotifications( | ||
| @RequestParam(required = false, defaultValue = "false") boolean unreadOnly) { | ||
| var user = userService.getCurrentUser(); | ||
| List<NotificationDto> notifications = | ||
| notificationService.getNotificationsForUser(user.getUsername(), unreadOnly); | ||
| return ResponseEntity.ok(notifications); | ||
| } | ||
|
|
||
| /** Marks a notification as read. */ | ||
| @PostMapping("/{id}/read") | ||
| public ResponseEntity<Void> markAsRead(@PathVariable Long id) { | ||
| var user = userService.getCurrentUser(); | ||
| notificationService.markAsRead(user.getUsername(), id); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| /** Marks all notifications for the current user as read. */ | ||
| @PostMapping("/read-all") | ||
| public ResponseEntity<Void> markAllAsRead() { | ||
| var user = userService.getCurrentUser(); | ||
| notificationService.markAllAsRead(user.getUsername()); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
| } |
This file contains hidden or 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,20 @@ | ||
| package cloudpage.dto; | ||
|
|
||
| import java.time.Instant; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class CommentDto { | ||
| private Long id; | ||
| private String ownerUsername; | ||
| private String filePath; | ||
| private String authorUsername; | ||
| private String content; | ||
| private Instant createdAt; | ||
| } |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/cloudpage/dto/CreateCommentRequest.java
This file contains hidden or 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,18 @@ | ||
| package cloudpage.dto; | ||
|
|
||
| import jakarta.validation.constraints.NotBlank; | ||
| import jakarta.validation.constraints.Size; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| public class CreateCommentRequest { | ||
| @NotBlank private String ownerUsername; | ||
|
|
||
| @NotBlank private String filePath; | ||
|
|
||
| @NotBlank | ||
| @Size(max = 8192) | ||
| private String content; | ||
| } |
This file contains hidden or 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,22 @@ | ||
| package cloudpage.dto; | ||
|
|
||
| import java.time.Instant; | ||
| import lombok.AllArgsConstructor; | ||
| import lombok.Getter; | ||
| import lombok.NoArgsConstructor; | ||
| import lombok.Setter; | ||
|
|
||
| @Getter | ||
| @Setter | ||
| @AllArgsConstructor | ||
| @NoArgsConstructor | ||
| public class NotificationDto { | ||
| private Long id; | ||
| private String recipientUsername; | ||
| private String type; | ||
| private String message; | ||
| private String filePath; | ||
| private String ownerUsername; | ||
| private boolean read; | ||
| private Instant createdAt; | ||
| } |
This file contains hidden or 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,44 @@ | ||
| package cloudpage.model; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Index; | ||
| import jakarta.persistence.Table; | ||
| import java.time.Instant; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** Entity representing a comment left on a file or folder in a user's cloud storage. */ | ||
| @Entity | ||
| @Table( | ||
| name = "comments", | ||
| indexes = { | ||
| @Index(name = "idx_comment_owner_path", columnList = "owner_username, file_path"), | ||
| @Index(name = "idx_comment_created_at", columnList = "created_at") | ||
| }) | ||
| @Getter | ||
| @Setter | ||
| public class Comment { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "owner_username", nullable = false) | ||
| private String ownerUsername; | ||
|
|
||
| @Column(name = "file_path", nullable = false, length = 4096) | ||
| private String filePath; | ||
|
|
||
| @Column(name = "author_username", nullable = false) | ||
| private String authorUsername; | ||
|
|
||
| @Column(nullable = false, length = 8192) | ||
| private String content; | ||
|
|
||
| @Column(name = "created_at", nullable = false) | ||
| private Instant createdAt; | ||
| } |
This file contains hidden or 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 cloudpage.model; | ||
|
|
||
| import jakarta.persistence.Column; | ||
| import jakarta.persistence.Entity; | ||
| import jakarta.persistence.GeneratedValue; | ||
| import jakarta.persistence.GenerationType; | ||
| import jakarta.persistence.Id; | ||
| import jakarta.persistence.Index; | ||
| import jakarta.persistence.Table; | ||
| import java.time.Instant; | ||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** Entity representing user notifications for mentions or other service events. */ | ||
| @Entity | ||
| @Table( | ||
| name = "notifications", | ||
| indexes = { | ||
| @Index(name = "idx_notification_recipient", columnList = "recipient_username"), | ||
| @Index(name = "idx_notification_created_at", columnList = "created_at") | ||
| }) | ||
| @Getter | ||
| @Setter | ||
| public class Notification { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| @Column(name = "recipient_username", nullable = false) | ||
| private String recipientUsername; | ||
|
|
||
| @Column(nullable = false) | ||
| private String type; | ||
|
|
||
| @Column(nullable = false, length = 4096) | ||
| private String message; | ||
|
|
||
| @Column(name = "file_path", nullable = false, length = 4096) | ||
| private String filePath; | ||
|
|
||
| @Column(name = "owner_username", nullable = false) | ||
| private String ownerUsername; | ||
|
|
||
| @Column(name = "is_read", nullable = false) | ||
| private boolean read; | ||
|
|
||
| @Column(name = "created_at", nullable = false) | ||
| private Instant createdAt; | ||
| } |
13 changes: 13 additions & 0 deletions
13
backend/src/main/java/cloudpage/repository/CommentRepository.java
This file contains hidden or 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,13 @@ | ||
| package cloudpage.repository; | ||
|
|
||
| import cloudpage.model.Comment; | ||
| import java.util.List; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| /** Repository interface for comments. */ | ||
| @Repository | ||
| public interface CommentRepository extends JpaRepository<Comment, Long> { | ||
| List<Comment> findByOwnerUsernameAndFilePathOrderByCreatedAtAsc( | ||
| String ownerUsername, String filePath); | ||
| } |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/cloudpage/repository/NotificationRepository.java
This file contains hidden or 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,18 @@ | ||
| package cloudpage.repository; | ||
|
|
||
| import cloudpage.model.Notification; | ||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| /** Repository interface for user notifications. */ | ||
| @Repository | ||
| public interface NotificationRepository extends JpaRepository<Notification, Long> { | ||
| List<Notification> findByRecipientUsernameOrderByCreatedAtDesc(String recipientUsername); | ||
|
|
||
| List<Notification> findByRecipientUsernameAndReadOrderByCreatedAtDesc( | ||
| String recipientUsername, boolean read); | ||
|
|
||
| Optional<Notification> findByIdAndRecipientUsername(Long id, String recipientUsername); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Commenting and mention notifications are not rate limited. Everywhere else in this codebase (upload, download, scan, share) writes are throttled, and here a single comment can create an unbounded number of notification rows for other users via many @mentions. Please route this through RateLimitFilter under a suitable category.