diff --git a/src/main/java/com/loafle/overflow/module/notification/dao/NotificationDAO.java b/src/main/java/com/loafle/overflow/module/notification/dao/NotificationDAO.java index 7c1f0c8..7e6ecd8 100644 --- a/src/main/java/com/loafle/overflow/module/notification/dao/NotificationDAO.java +++ b/src/main/java/com/loafle/overflow/module/notification/dao/NotificationDAO.java @@ -19,4 +19,7 @@ public interface NotificationDAO extends JpaRepository { @Query("SELECT n FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL") Page findAllUnconfirmedByMember(@Param("member") Member member, Pageable pageRequest); + + @Query("SELECT COUNT(n) FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL") + int findAllUnconfirmedCountByMember(@Param("member") Member member); } diff --git a/src/main/java/com/loafle/overflow/module/notification/model/Notification.java b/src/main/java/com/loafle/overflow/module/notification/model/Notification.java index 15a9bc8..6986be9 100644 --- a/src/main/java/com/loafle/overflow/module/notification/model/Notification.java +++ b/src/main/java/com/loafle/overflow/module/notification/model/Notification.java @@ -67,7 +67,7 @@ public class Notification { } @Temporal(TemporalType.TIMESTAMP) - @Column(name = "CREATE_DATE", nullable = true) + @Column(name = "CONFIRM_DATE", nullable = true) public Date getConfirmDate() { return confirmDate; } diff --git a/src/main/java/com/loafle/overflow/module/notification/service/NotificationService.java b/src/main/java/com/loafle/overflow/module/notification/service/NotificationService.java index 0d97110..5086399 100644 --- a/src/main/java/com/loafle/overflow/module/notification/service/NotificationService.java +++ b/src/main/java/com/loafle/overflow/module/notification/service/NotificationService.java @@ -1,13 +1,12 @@ package com.loafle.overflow.module.notification.service; +import com.loafle.overflow.commons.model.PageParams; +import com.loafle.overflow.commons.utils.PageUtil; import com.loafle.overflow.module.member.model.Member; import com.loafle.overflow.module.notification.dao.NotificationDAO; import com.loafle.overflow.module.notification.model.Notification; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; /** @@ -23,15 +22,15 @@ public class NotificationService { return this.notificationDAO.save(notification); } - public Page readAllByMember(Member member, int pageNo, int countPerPage) { - Pageable pageRequest = - new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id")); - return this.notificationDAO.findAllByMember(member, pageRequest); + public Page readAllByMember(Member member, PageParams pageParams) { + return this.notificationDAO.findAllByMember(member, PageUtil.getPageRequest(pageParams)); } - public Page readAllUnconfirmedByMember(Member member, int pageNo, int countPerPage) { - Pageable pageRequest = - new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id")); - return this.notificationDAO.findAllUnconfirmedByMember(member, pageRequest); + public Page readAllUnconfirmedByMember(Member member, PageParams pageParams) { + return this.notificationDAO.findAllUnconfirmedByMember(member, PageUtil.getPageRequest(pageParams)); + } + + public int readUnconfirmedCount(Member member) { + return this.notificationDAO.findAllUnconfirmedCountByMember(member); } } diff --git a/src/main/resources/init.sql b/src/main/resources/init.sql index 60cd16b..c972204 100644 --- a/src/main/resources/init.sql +++ b/src/main/resources/init.sql @@ -1065,66 +1065,67 @@ INSERT INTO public.history (id,create_date,message,domain_id,member_id,probe_id, INSERT INTO public.history (id,create_date,message,domain_id,member_id,probe_id,type_id) VALUES ( 100,'2017-08-24 18:33:27.217','Test History 99',1,1,1,3); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -1,'2017-08-25 16:58:48.430','Message0','Title0',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -2,NULL,'Message1','Title1',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -3,'2017-08-25 16:58:48.520','Message2','Title2',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -4,NULL,'Message3','Title3',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -5,'2017-08-25 16:58:48.540','Message4','Title4',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -6,NULL,'Message5','Title5',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -7,'2017-08-25 16:58:48.566','Message6','Title6',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -8,NULL,'Message7','Title7',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -9,'2017-08-25 16:58:48.596','Message8','Title8',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -10,NULL,'Message9','Title9',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -11,'2017-08-25 16:58:48.628','Message10','Title10',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -12,NULL,'Message11','Title11',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -13,'2017-08-25 16:58:48.661','Message12','Title12',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -14,NULL,'Message13','Title13',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -15,'2017-08-25 16:58:48.682','Message14','Title14',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -16,NULL,'Message15','Title15',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -17,'2017-08-25 16:58:48.710','Message16','Title16',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -18,NULL,'Message17','Title17',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -19,'2017-08-25 16:58:48.734','Message18','Title18',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -20,NULL,'Message19','Title19',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -21,'2017-08-25 16:58:48.755','Message20','Title20',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -22,NULL,'Message21','Title21',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -23,'2017-08-25 16:58:48.778','Message22','Title22',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -24,NULL,'Message23','Title23',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -25,'2017-08-25 16:58:48.804','Message24','Title24',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -26,NULL,'Message25','Title25',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -27,'2017-08-25 16:58:48.829','Message26','Title26',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -28,NULL,'Message27','Title27',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -29,'2017-08-25 16:58:48.850','Message28','Title28',1); -INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES ( -30,NULL,'Message29','Title29',1); + +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +1,'2017-08-29 16:39:16.198','2017-08-29 16:39:17.756','Message0','Title0',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +2,'2017-08-29 16:39:16.285','2017-08-29 16:39:17.789','Message1','Title1',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +3,'2017-08-29 16:39:16.306','2017-08-29 16:39:17.807','Message2','Title2',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +4,'2017-08-29 16:39:16.322','2017-08-29 16:39:17.822','Message3','Title3',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +5,'2017-08-29 16:39:16.336','2017-08-29 16:39:17.837','Message4','Title4',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +6,'2017-08-29 16:39:16.350','2017-08-29 16:39:17.852','Message5','Title5',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +7,'2017-08-29 16:39:16.365','2017-08-29 16:39:17.864','Message6','Title6',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +8,'2017-08-29 16:39:16.377','2017-08-29 16:39:17.877','Message7','Title7',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +9,'2017-08-29 16:39:16.391','2017-08-29 16:39:17.890','Message8','Title8',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +10,'2017-08-29 16:39:16.403','2017-08-29 16:39:17.904','Message9','Title9',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +11,'2017-08-29 16:39:16.417','2017-08-29 16:39:17.916','Message10','Title10',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +12,'2017-08-29 16:39:16.430','2017-08-29 16:39:17.929','Message11','Title11',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +13,'2017-08-29 16:39:16.442','2017-08-29 16:39:17.941','Message12','Title12',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +14,'2017-08-29 16:39:16.454','2017-08-29 16:39:17.953','Message13','Title13',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +15,'2017-08-29 16:39:16.467','2017-08-29 16:39:17.966','Message14','Title14',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +16,'2017-08-29 16:39:16.479','2017-08-29 16:39:17.979','Message15','Title15',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +17,'2017-08-29 16:39:16.493','2017-08-29 16:39:17.994','Message16','Title16',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +18,'2017-08-29 16:39:16.508','2017-08-29 16:39:18.008','Message17','Title17',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +19,'2017-08-29 16:39:16.522','2017-08-29 16:39:18.020','Message18','Title18',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +20,'2017-08-29 16:39:16.533','2017-08-29 16:39:18.031','Message19','Title19',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +21,NULL,'2017-08-29 16:39:18.042','Message20','Title20',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +22,NULL,'2017-08-29 16:39:18.051','Message21','Title21',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +23,NULL,'2017-08-29 16:39:18.062','Message22','Title22',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +24,NULL,'2017-08-29 16:39:18.072','Message23','Title23',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +25,NULL,'2017-08-29 16:39:18.083','Message24','Title24',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +26,NULL,'2017-08-29 16:39:18.096','Message25','Title25',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +27,NULL,'2017-08-29 16:39:18.108','Message26','Title26',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +28,NULL,'2017-08-29 16:39:18.118','Message27','Title27',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +29,NULL,'2017-08-29 16:39:18.130','Message28','Title28',1); +INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES ( +30,NULL,'2017-08-29 16:39:18.143','Message29','Title29',1); diff --git a/src/test/java/com/loafle/overflow/module/notification/service/NotificationServiceTest.java b/src/test/java/com/loafle/overflow/module/notification/service/NotificationServiceTest.java index f93ee6c..e38e880 100644 --- a/src/test/java/com/loafle/overflow/module/notification/service/NotificationServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/notification/service/NotificationServiceTest.java @@ -3,12 +3,9 @@ package com.loafle.overflow.module.notification.service; import com.loafle.overflow.module.member.model.Member; import com.loafle.overflow.module.notification.model.Notification; import com.loafle.overflow.spring.AppConfigTest; -import org.junit.Assert; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -24,33 +21,32 @@ public class NotificationServiceTest { private NotificationService notificationService; @Test - @Ignore public void testRegist() { for (int i=0; i<30; i++) { Notification n = new Notification(); n.setMember(new Member(1)); n.setTitle("Title"+i); n.setMessage("Message"+i); - if((i%2)==0) { + if(i<20) { n.setConfirmDate(new Date()); } this.notificationService.regist(n); } } - @Test - @Ignore - public void testReadAll() { - this.testRegist(); - Page notis = this.notificationService.readAllByMember(new Member(1), 0, 10); - Assert.assertEquals(30, notis.getTotalElements()); - } - - @Test - @Ignore - public void testReadAllUnread() { - this.testRegist(); - Page notis = this.notificationService.readAllUnconfirmedByMember(new Member(1), 0, 10); - Assert.assertEquals(15, notis.getTotalElements()); - } +// @Test +// @Ignore +// public void testReadAll() { +// this.testRegist(); +// Page notis = this.notificationService.readAllByMember(new Member(1), 0, 10); +// Assert.assertEquals(30, notis.getTotalElements()); +// } +// +// @Test +// @Ignore +// public void testReadAllUnread() { +// this.testRegist(); +// Page notis = this.notificationService.readAllUnconfirmedByMember(new Member(1), 0, 10); +// Assert.assertEquals(15, notis.getTotalElements()); +// } }