From 803753ac9f44c043ef02bff47d3c4ebb6985a25f Mon Sep 17 00:00:00 2001 From: KimMinHwan <2021111977@dgu.ac.kr> Date: Sat, 21 Dec 2024 10:21:48 +0900 Subject: [PATCH] =?UTF-8?q?"FEAT":=20=EC=9D=B4=EB=A9=94=EC=9D=BC=20?= =?UTF-8?q?=EC=95=8C=EB=A6=BC=20=EA=B5=AC=ED=98=84=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server_9dokme/build.gradle | 1 + .../Admin/controller/AdminController.java | 17 ++++++ .../SSE/EmitterRepositoryImpl.java | 60 ------------------- .../Notification/SSE/SseEmitters.java | 4 -- .../repository/NotificationRepository.java | 11 ++++ .../service/NotificationService.java | 32 ++++++++++ .../book/service/BookService.java | 4 ++ .../server_9dokme/member/entity/Device.java | 27 +++++++++ .../server_9dokme/member/entity/Member.java | 3 + .../member/repository/DeviceRepository.java | 18 ++++++ .../member/repository/KeywordRepository.java | 3 + 11 files changed, 116 insertions(+), 64 deletions(-) delete mode 100644 server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/EmitterRepositoryImpl.java delete mode 100644 server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/SseEmitters.java create mode 100644 server_9dokme/src/main/java/com/example/server_9dokme/Notification/repository/NotificationRepository.java create mode 100644 server_9dokme/src/main/java/com/example/server_9dokme/Notification/service/NotificationService.java create mode 100644 server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Device.java create mode 100644 server_9dokme/src/main/java/com/example/server_9dokme/member/repository/DeviceRepository.java diff --git a/server_9dokme/build.gradle b/server_9dokme/build.gradle index fe1f31a3..072a73ea 100644 --- a/server_9dokme/build.gradle +++ b/server_9dokme/build.gradle @@ -60,6 +60,7 @@ dependencies { //jwt implementation 'io.jsonwebtoken:jjwt:0.9.1' + } tasks.named('test') { diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/Admin/controller/AdminController.java b/server_9dokme/src/main/java/com/example/server_9dokme/Admin/controller/AdminController.java index 31037609..b3a373be 100644 --- a/server_9dokme/src/main/java/com/example/server_9dokme/Admin/controller/AdminController.java +++ b/server_9dokme/src/main/java/com/example/server_9dokme/Admin/controller/AdminController.java @@ -4,11 +4,17 @@ import com.example.server_9dokme.book.dto.request.BookUpdateRequest; import com.example.server_9dokme.book.dto.response.BookInfoResponse; import com.example.server_9dokme.book.service.BookService; +import com.example.server_9dokme.member.entity.Keyword; +import com.example.server_9dokme.member.repository.KeywordRepository; import org.springframework.web.bind.annotation.RequestBody; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + @RestController @RequestMapping("/admin") @RequiredArgsConstructor @@ -16,10 +22,21 @@ public class AdminController { private final BookService bookService; + + // 책 정보(pdf) 등록 @PostMapping("/books") public ResponseEntity createBook(@RequestBody BookCreateRequest request) { BookInfoResponse response = bookService.createBook(request); + + String bookTitle = response.title(); + + + + + //푸시알림 로직 처리 + //send Notification(String[] sendMessageUserList, String bookTitle, String message) + return ResponseEntity.ok(response); } diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/EmitterRepositoryImpl.java b/server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/EmitterRepositoryImpl.java deleted file mode 100644 index da1d22b8..00000000 --- a/server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/EmitterRepositoryImpl.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.example.server_9dokme.Notification.SSE; - -import org.springframework.stereotype.Repository; -import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; - -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; - -@Repository -public class EmitterRepositoryImpl { - - private final Map emitters = new ConcurrentHashMap<>(); - private final Map eventCache = new ConcurrentHashMap<>(); - - public SseEmitter save(String emitteId, SseEmitter sseEmitter) { - emitters.put(emitteId, sseEmitter); - return sseEmitter; - } - - public void saveEventCache(String emitteId, Object event) { - eventCache.put(emitteId, event); - } - - public Map findAllEmitterStartWithByMemberId(String memberId) { - return emitters.entrySet().stream() - .filter(entry->entry.getKey().startsWith(memberId)) - .collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue)); - } - - public Map findAllEventCacheStartWithByMemberId(String memberId) { - return eventCache.entrySet().stream() - .filter(entry -> entry.getKey().startsWith(memberId)) - .collect(Collectors.toMap(Map.Entry::getKey,Map.Entry::getValue)); - } - - public void delete(String emitteId) { - emitters.remove(emitteId); - } - - public void deleteAllEmitterStartWithId(String memberId) { - emitters.forEach( - (key,emitter)->{ - if(key.startsWith(memberId)){ - emitters.remove(key); - } - } - ); - } - - public void deleteAllEventCacheStartWithId(String memberId) { - eventCache.forEach( - (key,value)->{ - if(key.startsWith(memberId)){ - eventCache.remove(key); - } - } - ); - } -} diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/SseEmitters.java b/server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/SseEmitters.java deleted file mode 100644 index 05296535..00000000 --- a/server_9dokme/src/main/java/com/example/server_9dokme/Notification/SSE/SseEmitters.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.example.server_9dokme.Notification.SSE; - -public class SseEmitters { -} diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/Notification/repository/NotificationRepository.java b/server_9dokme/src/main/java/com/example/server_9dokme/Notification/repository/NotificationRepository.java new file mode 100644 index 00000000..bca793c3 --- /dev/null +++ b/server_9dokme/src/main/java/com/example/server_9dokme/Notification/repository/NotificationRepository.java @@ -0,0 +1,11 @@ +package com.example.server_9dokme.Notification.repository; + +import com.example.server_9dokme.Notification.entity.Notification; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface NotificationRepository extends JpaRepository { + + Page findAllByMember_MemberId(Long memberId, Pageable pageable); +} diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/Notification/service/NotificationService.java b/server_9dokme/src/main/java/com/example/server_9dokme/Notification/service/NotificationService.java new file mode 100644 index 00000000..35fc5993 --- /dev/null +++ b/server_9dokme/src/main/java/com/example/server_9dokme/Notification/service/NotificationService.java @@ -0,0 +1,32 @@ +package com.example.server_9dokme.Notification.service; + + +import com.example.server_9dokme.Notification.entity.Notification; +import com.example.server_9dokme.Notification.repository.NotificationRepository; +import lombok.Data; +import lombok.NoArgsConstructor; +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.stereotype.Service; + +@Service +@Data +@NoArgsConstructor +public class NotificationService { + + @Autowired + private NotificationRepository notificationRepository; + + public Page findAllNotification(Long memberId, int pageNo){ + + Pageable pageable = PageRequest.of(pageNo,8); + + Page notifications = notificationRepository.findAllByMember_MemberId(memberId,pageable); + + return notifications; + } + + +} diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/book/service/BookService.java b/server_9dokme/src/main/java/com/example/server_9dokme/book/service/BookService.java index 7756cced..66f83452 100644 --- a/server_9dokme/src/main/java/com/example/server_9dokme/book/service/BookService.java +++ b/server_9dokme/src/main/java/com/example/server_9dokme/book/service/BookService.java @@ -178,6 +178,10 @@ public BookInfoResponse createBook(BookCreateRequest request) { request.rent() ); bookRepository.save(book); + + + + return toResponse(book); } diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Device.java b/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Device.java new file mode 100644 index 00000000..ca04783e --- /dev/null +++ b/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Device.java @@ -0,0 +1,27 @@ +package com.example.server_9dokme.member.entity; + + +import com.example.server_9dokme.common.entity.BaseEntity; +import jakarta.persistence.*; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.GenericGenerator; + +@Entity +@Data +@NoArgsConstructor +public class Device extends BaseEntity { + + @Id + @GeneratedValue(generator = "uuid") + @GenericGenerator(name = "uuid", strategy = "uuid2") + private String deviceId; + + private Boolean notificationStatement; + + private String userFirebaseToken; + + @ManyToOne + @JoinColumn(name ="member_id") + private Member member; +} diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Member.java b/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Member.java index 1f32443d..adda7e3b 100644 --- a/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Member.java +++ b/server_9dokme/src/main/java/com/example/server_9dokme/member/entity/Member.java @@ -3,6 +3,7 @@ import com.example.server_9dokme.subscribe.entity.Subscribe; import jakarta.persistence.*; import lombok.*; +import org.hibernate.annotations.GenericGenerator; @Entity @Data @@ -43,6 +44,8 @@ public enum SocialType { private String billingKey; + + @Builder public Member(Long subscribeId, String userRole, String password, String nickName, String socialId, SocialType socialType, String customerKey, String authKey, String billingKey) { this.subscribeId = subscribeId; diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/DeviceRepository.java b/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/DeviceRepository.java new file mode 100644 index 00000000..d09ff0f4 --- /dev/null +++ b/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/DeviceRepository.java @@ -0,0 +1,18 @@ +package com.example.server_9dokme.member.repository; + +import com.example.server_9dokme.member.entity.Device; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; + +import java.util.List; + +public interface DeviceRepository extends JpaRepository { + + @Query("SELECT d.deviceId " + + "FROM Device d " + + "JOIN d.member m " + + "JOIN Keyword k ON k.member.memberId = m.memberId " + + "WHERE k.keyword LIKE %:title%") + List findDeviceIdsByTitle(@Param("title") String title); +} diff --git a/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/KeywordRepository.java b/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/KeywordRepository.java index 184b8f9e..70ab4241 100644 --- a/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/KeywordRepository.java +++ b/server_9dokme/src/main/java/com/example/server_9dokme/member/repository/KeywordRepository.java @@ -3,6 +3,9 @@ import com.example.server_9dokme.member.entity.Keyword; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + public interface KeywordRepository extends JpaRepository { + List findAllByKeywordContaining(String keyword); }