Skip to content

Commit

Permalink
Bugfix: fetch notifications query
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Feb 20, 2024
1 parent d40265d commit afcf789
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
import de.samply.db.model.Notification;
import de.samply.db.model.Project;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface NotificationRepository extends JpaRepository<Notification, Long> {

List<Notification> findAllByProjectOrderByTimestampDesc(Project project);
List<Notification> findAllByProjectAndBridgeheadOrBridgeheadIsNullOrderByTimestampDesc(Project project, String bridgehead);
List<Notification> findByProjectOrderByTimestampDesc(Project project);

@Query("SELECT n FROM Notification n WHERE n.project = :project AND (n.bridgehead = :bridgehead OR n.bridgehead IS NULL) " +
"ORDER BY n.timestamp DESC")
List<Notification> findByProjectAndBridgeheadOrBridgeheadIsNullOrderByTimestampDesc(Project project, String bridgehead);
}
4 changes: 2 additions & 2 deletions src/main/java/de/samply/notification/NotificationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public List<de.samply.frontend.dto.Notification> fetchUserVisibleNotifications(
List<String> bridgeheads = fetchUserVisibleBridgeheads(bridgheadOptional);
projects.forEach(project -> {
if (bridgeheads.isEmpty() && sessionUser.getUserOrganisationRoles().containsRole(OrganisationRole.PROJECT_MANAGER_ADMIN)) {
notificationRepository.findAllByProjectOrderByTimestampDesc(project);
result.addAll(notificationRepository.findByProjectOrderByTimestampDesc(project));
} else {
bridgeheads.forEach(bridgehead -> result.addAll(
notificationRepository.findAllByProjectAndBridgeheadOrBridgeheadIsNullOrderByTimestampDesc(project, bridgehead)));
notificationRepository.findByProjectAndBridgeheadOrBridgeheadIsNullOrderByTimestampDesc(project, bridgehead)));
}
});
return result.stream().map(notification ->
Expand Down

0 comments on commit afcf789

Please sign in to comment.