From 5315c931c3fd260408aeed8a67e0b15985be088b Mon Sep 17 00:00:00 2001 From: idon1nab <99960721+idon1nab@users.noreply.github.com> Date: Wed, 8 May 2024 11:49:05 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=EC=9D=B4=EC=A0=84=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=AA=A8=EB=91=90=20=EB=B6=88=EB=9F=AC=EC=98=A4?= =?UTF-8?q?=EA=B8=B0=20=EC=9C=84=ED=95=9C=20findAllNotify()=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../secretfriends/notify/dto/NotifyDTO.java | 12 +++++++---- .../notify/repository/NotifyRepository.java | 8 ++++++++ .../notify/service/NotifyService.java | 6 ++++-- .../notify/service/NotifyServiceImpl.java | 20 ++++++++++++++++++- src/main/resources/application.yml | 2 +- .../repository/NotifyRepositoryTests.java | 4 ++-- .../service/NotifyServiceTests.java | 9 +++++++-- 7 files changed, 49 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/dallili/secretfriends/notify/dto/NotifyDTO.java b/src/main/java/org/dallili/secretfriends/notify/dto/NotifyDTO.java index 424f953..3e7d79d 100644 --- a/src/main/java/org/dallili/secretfriends/notify/dto/NotifyDTO.java +++ b/src/main/java/org/dallili/secretfriends/notify/dto/NotifyDTO.java @@ -2,16 +2,14 @@ import com.fasterxml.jackson.annotation.JsonFormat; import jakarta.validation.constraints.NotNull; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; import org.dallili.secretfriends.notify.domain.Notify; import java.time.LocalDateTime; @Data @Builder +@Getter @AllArgsConstructor @NoArgsConstructor @@ -33,4 +31,10 @@ public class NotifyDTO { public enum NotifyType{ NEWDIARY, REPLY, INACTIVATE } + + //modelmapper 매핑 규칙 정의를 위한 setter + //일반 코드 작성 시에는 사용 지양 + public void setNotifyType(Enum notifyType) { + this.notifyType = notifyType; + } } diff --git a/src/main/java/org/dallili/secretfriends/notify/repository/NotifyRepository.java b/src/main/java/org/dallili/secretfriends/notify/repository/NotifyRepository.java index 0a4c87f..07ecf5b 100644 --- a/src/main/java/org/dallili/secretfriends/notify/repository/NotifyRepository.java +++ b/src/main/java/org/dallili/secretfriends/notify/repository/NotifyRepository.java @@ -1,8 +1,16 @@ package org.dallili.secretfriends.notify.repository; +import org.dallili.secretfriends.domain.Diary; +import org.dallili.secretfriends.domain.Member; import org.dallili.secretfriends.notify.domain.Notify; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + public interface NotifyRepository extends JpaRepository { + List findAllByReceiver_MemberID(Long receiverID); + } \ No newline at end of file diff --git a/src/main/java/org/dallili/secretfriends/notify/service/NotifyService.java b/src/main/java/org/dallili/secretfriends/notify/service/NotifyService.java index 61394f9..ae1c783 100644 --- a/src/main/java/org/dallili/secretfriends/notify/service/NotifyService.java +++ b/src/main/java/org/dallili/secretfriends/notify/service/NotifyService.java @@ -2,11 +2,13 @@ import org.dallili.secretfriends.notify.dto.NotifyDTO; +import java.util.List; + public interface NotifyService { - // "2. notify 테이블에 알림 데이터 저장" 담당하는 메소드 + // notify 테이블에 알림 데이터 저장" 담당하는 메소드 void saveNotifyTable(Long receiverID, Long senderID, NotifyDTO.NotifyType type); - void removeNotify(Long notifyID); + List findAllNotify(Long receiverID); } diff --git a/src/main/java/org/dallili/secretfriends/notify/service/NotifyServiceImpl.java b/src/main/java/org/dallili/secretfriends/notify/service/NotifyServiceImpl.java index 7a2b5bf..0e5dcbf 100644 --- a/src/main/java/org/dallili/secretfriends/notify/service/NotifyServiceImpl.java +++ b/src/main/java/org/dallili/secretfriends/notify/service/NotifyServiceImpl.java @@ -9,6 +9,8 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; @Service @Log4j2 @@ -26,8 +28,9 @@ public void saveNotifyTable(Long receiverID, Long senderID, NotifyDTO.NotifyType .receiverID(receiverID) .senderID(senderID) .build(); - //log.info(receiverNotifyDTO); + log.info(receiverNotifyDTO); Notify receiverNotify = modelMapper.map(receiverNotifyDTO, Notify.class); + log.info(receiverNotify); notifyRepository.save(receiverNotify); if(type == NotifyDTO.NotifyType.NEWDIARY || type == NotifyDTO.NotifyType.INACTIVATE){ @@ -45,4 +48,19 @@ public void saveNotifyTable(Long receiverID, Long senderID, NotifyDTO.NotifyType public void removeNotify(Long notifyID){ notifyRepository.deleteById(notifyID); } + + public List findAllNotify(Long receiverID){ + List notifyList = notifyRepository.findAllByReceiver_MemberID(receiverID); + + List notifyDTOList = notifyList.stream() + .map(notify -> { + NotifyDTO notifyDTO = modelMapper.map(notify, NotifyDTO.class); + // notificationType 가공하여 NotifyDTO에 추가 + notifyDTO.setNotifyType(NotifyDTO.NotifyType.valueOf(notify.getNotifyType())); + return notifyDTO; + }) + .collect(Collectors.toList()); + + return notifyDTOList; + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 4f962d9..01d324c 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -12,7 +12,7 @@ spring: show-sql: true profiles: - active: prod + active: local logging: level: diff --git a/src/test/java/org/dallili/secretfriends/repository/NotifyRepositoryTests.java b/src/test/java/org/dallili/secretfriends/repository/NotifyRepositoryTests.java index 9da66cc..c3355f6 100644 --- a/src/test/java/org/dallili/secretfriends/repository/NotifyRepositoryTests.java +++ b/src/test/java/org/dallili/secretfriends/repository/NotifyRepositoryTests.java @@ -18,7 +18,7 @@ public class NotifyRepositoryTests { @Autowired private MemberRepository memberRepository; - +/* @Test public void testInsert() { @@ -32,5 +32,5 @@ public void testInsert() { .build(); notifyRepository.save(notify); - } + }*/ } diff --git a/src/test/java/org/dallili/secretfriends/service/NotifyServiceTests.java b/src/test/java/org/dallili/secretfriends/service/NotifyServiceTests.java index 0db14d1..525db82 100644 --- a/src/test/java/org/dallili/secretfriends/service/NotifyServiceTests.java +++ b/src/test/java/org/dallili/secretfriends/service/NotifyServiceTests.java @@ -18,12 +18,17 @@ public class NotifyServiceTests { @Test public void testSaveNotify() { - notifyService.saveNotifyTable(1L, 2L, NotifyDTO.NotifyType.NEWDIARY); + notifyService.saveNotifyTable(1L, 2L, NotifyDTO.NotifyType.INACTIVATE); } @Test public void testRemoveNotify(){ - notifyService.removeNotify(1L); + notifyService.removeNotify(3L); } + + @Test + public void testFindAllNotify() { + log.info(notifyService.findAllNotify(2L)); + } } From bede3cb4585de0db6f9074d798f29df93c225427 Mon Sep 17 00:00:00 2001 From: idon1nab <99960721+idon1nab@users.noreply.github.com> Date: Wed, 8 May 2024 12:11:46 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat:=20NotifyController=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=20=EB=B0=8F=20=EC=95=8C=EB=A6=BC=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notify/controller/NotifyController.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java diff --git a/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java b/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java new file mode 100644 index 0000000..49aeeec --- /dev/null +++ b/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java @@ -0,0 +1,29 @@ +package org.dallili.secretfriends.notify.controller; + +import io.swagger.v3.oas.annotations.Operation; +import lombok.RequiredArgsConstructor; +import lombok.extern.log4j.Log4j2; +import org.dallili.secretfriends.notify.dto.NotifyDTO; +import org.dallili.secretfriends.notify.service.NotifyService; +import org.springframework.security.core.Authentication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@Log4j2 +@RequiredArgsConstructor +@RequestMapping("/notify2") +public class NotifyController { + + private final NotifyService notifyService; + @Operation(summary = "Notify List GET", description = "알림 목록 조회") + @GetMapping(value = "/") + public List notifyDTOList (Authentication authentication){ + return notifyService.findAllNotify(Long.parseLong(authentication.getName())); + } + + +} From 2e2dcab22809ab277260d62587e61fc1e32707d6 Mon Sep 17 00:00:00 2001 From: idon1nab <99960721+idon1nab@users.noreply.github.com> Date: Wed, 8 May 2024 17:16:17 +0900 Subject: [PATCH 3/3] =?UTF-8?q?style:=20EmitterController/NotifyController?= =?UTF-8?q?=20=EB=A7=A4=ED=95=91=20=EC=A3=BC=EC=86=8C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../secretfriends/notify/controller/EmitterController.java | 2 +- .../secretfriends/notify/controller/NotifyController.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/dallili/secretfriends/notify/controller/EmitterController.java b/src/main/java/org/dallili/secretfriends/notify/controller/EmitterController.java index 7cc3453..717957f 100644 --- a/src/main/java/org/dallili/secretfriends/notify/controller/EmitterController.java +++ b/src/main/java/org/dallili/secretfriends/notify/controller/EmitterController.java @@ -13,7 +13,7 @@ @RestController @Log4j2 @RequiredArgsConstructor -@RequestMapping("/notify") +@RequestMapping("/emitter") public class EmitterController { private final EmitterService emitterService; diff --git a/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java b/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java index 49aeeec..e854529 100644 --- a/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java +++ b/src/main/java/org/dallili/secretfriends/notify/controller/NotifyController.java @@ -15,7 +15,7 @@ @RestController @Log4j2 @RequiredArgsConstructor -@RequestMapping("/notify2") +@RequestMapping("/notify") public class NotifyController { private final NotifyService notifyService;