wkigenyi commented on code in PR #2730:
URL: https://github.com/apache/fineract/pull/2730#discussion_r1015899866


##########
fineract-provider/src/main/java/org/apache/fineract/notification/domain/NotificationMapperRepository.java:
##########
@@ -18,6 +18,25 @@
  */
 package org.apache.fineract.notification.domain;
 
+import java.util.Collection;
 import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.data.repository.query.Param;
+import org.springframework.transaction.annotation.Transactional;
 
-public interface NotificationMapperRepository extends 
JpaRepository<NotificationMapper, Long> {}
+public interface NotificationMapperRepository extends 
JpaRepository<NotificationMapper, Long> {
+
+    @Transactional
+    @Modifying(flushAutomatically = true)
+    @Query("UPDATE NotificationMapper n SET n.isRead = true WHERE n.userId.id 
= :userId")
+    void markAllNotificationsForAUserAsRead(@Param("userId") Long userId);
+
+    @Transactional
+    @Modifying(flushAutomatically = true)
+    @Query("UPDATE NotificationMapper n SET n.isRead = true WHERE n.userId.id 
= :userId AND n.notification.id = :notificationId")
+    void markASingleNotificationForAUserAsRead(@Param("userId") Long userId, 
@Param("notificationId") Long notificationId);
+
+    @Query("SELECT n FROM NotificationMapper n WHERE n.userId.id = :userId AND 
n.isRead=false")

Review Comment:
   The alternative I thought of was to extract the Object (NotificationMapper) 
then setIsRead = true, and set other fields too and then save. Another 
alternative I thought of involved DTO. I thought this maintaining this 2 liner 
will execute quicker, plus it takes care the ownership issue raised below 
without writing many lines.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to