Skip to content
Open
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
2 changes: 1 addition & 1 deletion backend/mvnw.cmd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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)

Copy link
Copy Markdown
Member

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.

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();
}
}
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();
}
}
20 changes: 20 additions & 0 deletions backend/src/main/java/cloudpage/dto/CommentDto.java
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 backend/src/main/java/cloudpage/dto/CreateCommentRequest.java
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;
}
22 changes: 22 additions & 0 deletions backend/src/main/java/cloudpage/dto/NotificationDto.java
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;
}
44 changes: 44 additions & 0 deletions backend/src/main/java/cloudpage/model/Comment.java
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;
}
50 changes: 50 additions & 0 deletions backend/src/main/java/cloudpage/model/Notification.java
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;
}
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);
}
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);
}
Loading