-
Notifications
You must be signed in to change notification settings - Fork 2
Feature/ip 97 api i baza powiadomien #47
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
072af1a
feature(notification): create notification entity and enum for types.
mtrznadel24 676ae81
feature(notification): fill in Notification entity, create event reco…
mtrznadel24 fcf521a
feature(notification): Create event records and NotificationControlle…
mtrznadel24 0772ce4
feature(notification): Implement ApplicationEventPublisher in other s…
mtrznadel24 7733169
test(notification): add NotificationService tests
mtrznadel24 e4d4b4d
test(notification): Create interface for event records making Notific…
mtrznadel24 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
27 changes: 27 additions & 0 deletions
27
...ain/java/pl/edu/agh/project_manager/controller/dto/notification/NotificationResponse.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,27 @@ | ||
| package pl.edu.agh.project_manager.controller.dto.notification; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.notification.Notification; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| public record NotificationResponse( | ||
| UUID id, | ||
| NotificationType type, | ||
| String message, | ||
| boolean isRead, | ||
| UUID referenceId, | ||
| LocalDateTime createdAt | ||
| ) { | ||
| public static NotificationResponse from(Notification notification) { | ||
| return new NotificationResponse( | ||
| notification.getId(), | ||
| notification.getType(), | ||
| notification.getMessage(), | ||
| notification.isRead(), | ||
| notification.getReferenceId(), | ||
| notification.getCreatedAt() | ||
| ); | ||
| } | ||
| } |
58 changes: 58 additions & 0 deletions
58
.../main/java/pl/edu/agh/project_manager/controller/notification/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,58 @@ | ||
| package pl.edu.agh.project_manager.controller.notification; | ||
|
|
||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.data.web.PageableDefault; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
| import org.springframework.web.bind.annotation.*; | ||
| import pl.edu.agh.project_manager.controller.dto.PagedResponse; | ||
| import pl.edu.agh.project_manager.controller.dto.notification.NotificationResponse; | ||
| import pl.edu.agh.project_manager.security.UserPrincipal; | ||
| import pl.edu.agh.project_manager.service.notification.NotificationService; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| @RestController | ||
| @RequestMapping("/api/notifications") | ||
| @RequiredArgsConstructor | ||
| public class NotificationController { | ||
|
|
||
| private final NotificationService notificationService; | ||
|
|
||
| @GetMapping | ||
| public ResponseEntity<PagedResponse<NotificationResponse>> getUserNotifications( | ||
| @RequestParam(defaultValue = "true") boolean unreadOnly, | ||
| @PageableDefault(size = 20) Pageable pageable, | ||
| @AuthenticationPrincipal UserPrincipal userPrincipal | ||
| ) { | ||
| return ResponseEntity.ok( | ||
| notificationService.getNotificationsForUser( | ||
| userPrincipal.userId(), | ||
| pageable.getPageNumber(), | ||
| pageable.getPageSize(), | ||
| unreadOnly | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
| @PatchMapping("/{notificationId}/mark-as-read") | ||
| @PreAuthorize("@notificationAccess.canMarkAsRead(#notificationId, authentication.principal)") | ||
| public ResponseEntity<Void> markAsRead( | ||
| @PathVariable UUID notificationId, | ||
| @AuthenticationPrincipal UserPrincipal userPrincipal | ||
| ) { | ||
| notificationService.markAsRead(notificationId, userPrincipal.userId()); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
|
|
||
| @PatchMapping("/mark-all-as-read") | ||
| public ResponseEntity<Void> markAllAsRead( | ||
| @AuthenticationPrincipal UserPrincipal userPrincipal | ||
| ) { | ||
| notificationService.markAllAsRead(userPrincipal.userId()); | ||
| return ResponseEntity.noContent().build(); | ||
| } | ||
|
|
||
| } | ||
49 changes: 49 additions & 0 deletions
49
...ger/src/main/java/pl/edu/agh/project_manager/domain/entity/notification/Notification.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,49 @@ | ||
| package pl.edu.agh.project_manager.domain.entity.notification; | ||
|
|
||
| import jakarta.persistence.*; | ||
| import lombok.*; | ||
| import org.hibernate.annotations.CreationTimestamp; | ||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.time.LocalDateTime; | ||
| import java.util.UUID; | ||
|
|
||
| @Entity | ||
| @Table(name = "notifications", indexes = { | ||
| @Index(name = "idx_notification_recipient_created", columnList = "recipient_id, created_at") | ||
| }) | ||
| @Getter | ||
| @Setter | ||
| @NoArgsConstructor | ||
| @AllArgsConstructor | ||
| @Builder | ||
| public class Notification { | ||
|
|
||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.UUID) | ||
| @Column(name = "id", nullable = false) | ||
| private UUID id; | ||
|
|
||
| @ManyToOne(fetch = FetchType.LAZY, optional = false) | ||
| @JoinColumn(name = "recipient_id", nullable = false) | ||
| private User recipient; | ||
|
|
||
| @Enumerated(EnumType.STRING) | ||
| @Column(name = "type", length = 50, nullable = false) | ||
| private NotificationType type; | ||
|
|
||
| @Column(name = "message", length = 255, nullable = false) | ||
| private String message; | ||
|
|
||
| @Column(name = "is_read", nullable = false) | ||
| @Builder.Default | ||
| private boolean isRead = false; | ||
|
|
||
| @Column(name = "reference_id") | ||
|
mtrznadel24 marked this conversation as resolved.
|
||
| private UUID referenceId; | ||
|
|
||
| @CreationTimestamp | ||
| @Column(name = "created_at", nullable = false, updatable = false) | ||
| private LocalDateTime 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
15 changes: 15 additions & 0 deletions
15
...oject-manager/src/main/java/pl/edu/agh/project_manager/domain/enums/NotificationType.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,15 @@ | ||
| package pl.edu.agh.project_manager.domain.enums; | ||
|
|
||
| public enum NotificationType { | ||
|
|
||
| ASSIGNMENT_REQUESTED, | ||
| ASSIGNMENT_ACCEPTED, | ||
| ASSIGNMENT_REJECTED, | ||
|
|
||
| QUALIFICATION_REQUESTED, | ||
| QUALIFICATION_ACCEPTED, | ||
| QUALIFICATION_REJECTED, | ||
|
|
||
| SYSTEM_NEW_EMPLOYEE | ||
|
|
||
| } |
23 changes: 23 additions & 0 deletions
23
...anager/src/main/java/pl/edu/agh/project_manager/domain/event/AssignmentAcceptedEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record AssignmentAcceptedEvent( | ||
| UUID assignmentId, | ||
| User recipient, String | ||
| message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return assignmentId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.ASSIGNMENT_ACCEPTED; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...anager/src/main/java/pl/edu/agh/project_manager/domain/event/AssignmentRejectedEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record AssignmentRejectedEvent( | ||
| UUID assignmentId, | ||
| User recipient, | ||
| String message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return assignmentId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.ASSIGNMENT_REJECTED; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...nager/src/main/java/pl/edu/agh/project_manager/domain/event/AssignmentRequestedEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record AssignmentRequestedEvent( | ||
| UUID assignmentId, | ||
| User recipient, | ||
| String message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return assignmentId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.ASSIGNMENT_REQUESTED; | ||
| } | ||
| } |
13 changes: 13 additions & 0 deletions
13
...ject-manager/src/main/java/pl/edu/agh/project_manager/domain/event/NotificationEvent.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 pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public interface NotificationEvent { | ||
| User recipient(); | ||
| String message(); | ||
| UUID referenceId(); | ||
| NotificationType type(); | ||
| } |
23 changes: 23 additions & 0 deletions
23
...ger/src/main/java/pl/edu/agh/project_manager/domain/event/QualificationAcceptedEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record QualificationAcceptedEvent( | ||
| UUID qualificationId, | ||
| User recipient, | ||
| String message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return qualificationId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.QUALIFICATION_ACCEPTED; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...ger/src/main/java/pl/edu/agh/project_manager/domain/event/QualificationRejectedEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record QualificationRejectedEvent( | ||
| UUID qualificationId, | ||
| User recipient, | ||
| String message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return qualificationId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.QUALIFICATION_REJECTED; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...er/src/main/java/pl/edu/agh/project_manager/domain/event/QualificationRequestedEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record QualificationRequestedEvent( | ||
| UUID qualificationId, | ||
| User recipient, | ||
| String message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return qualificationId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.QUALIFICATION_REQUESTED; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...manager/src/main/java/pl/edu/agh/project_manager/domain/event/SystemNewEmployeeEvent.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,23 @@ | ||
| package pl.edu.agh.project_manager.domain.event; | ||
|
|
||
| import pl.edu.agh.project_manager.domain.entity.user.User; | ||
| import pl.edu.agh.project_manager.domain.enums.NotificationType; | ||
|
|
||
| import java.util.UUID; | ||
|
|
||
| public record SystemNewEmployeeEvent( | ||
| UUID employeeId, | ||
| User recipient, | ||
| String message | ||
| ) implements NotificationEvent { | ||
|
|
||
| @Override | ||
| public UUID referenceId() { | ||
| return employeeId; | ||
| } | ||
|
|
||
| @Override | ||
| public NotificationType type() { | ||
| return NotificationType.SYSTEM_NEW_EMPLOYEE; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.