From 0e711346d26cc8d96b6fd1178a7ec8615fc0ec2e Mon Sep 17 00:00:00 2001 From: fing9 Date: Fri, 31 May 2024 16:03:10 +0900 Subject: [PATCH 01/14] =?UTF-8?q?[Refator]=20Spring=20event=EB=A5=BC=20?= =?UTF-8?q?=EC=9D=B4=EC=9A=A9=ED=95=9C=20=EC=95=8C=EB=A6=BC=20=EB=B0=9C?= =?UTF-8?q?=ED=96=89=EC=9C=BC=EB=A1=9C=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../board/controller/BoardController.java | 21 ++++++--- .../domain/board/dto/BoardDetail.java | 4 +- .../domain/board/service/BoardService.java | 15 ++++--- .../controller/BoolshitController.java | 5 +-- .../boolshit/dto/BoolshitLastResponse.java | 3 +- .../comment/controller/CommentController.java | 11 +++-- .../domain/comment/dto/CommentDto.java | 4 +- .../comment/service/CommentService.java | 23 +++++----- .../service/ComplaintProcessorService.java | 19 ++++---- .../service/ComplaintRequesterService.java | 20 +++++---- .../EventPointSearchController.java | 3 +- .../domain/event/dto/EventPointDto.java | 3 +- .../event/dto/EventPointPublishRequest.java | 3 +- .../event/dto/EventPointUpdateRequest.java | 3 +- .../image/controller/ImageController.java | 4 +- .../image/controller/ImageS3Controller.java | 14 +++--- .../item/controller/ItemController.java | 20 ++++++--- .../log/controller/PointLogController.java | 11 ++--- .../log/controller/WarningLogController.java | 10 +++-- .../domain/problem/dto/ProblemDto.java | 6 +-- .../controller/RecommendationController.java | 5 +-- .../dto/RecommendationResponse.java | 3 +- .../domain/scraping/domain/Scraping.java | 7 ++- .../controller/GraphStatisticsController.java | 2 - .../GraphStatisticsControllerV2.java | 9 ++-- .../controller/UserStatisticsController.java | 14 +++--- .../domain/statistics/dto/PointBarDto.java | 1 - .../dto/PointBarGraphStatisticsResponse.java | 3 +- .../domain/statistics/dto/SolvedBarDto.java | 2 - .../dto/SolvedBarGraphStatisticsResponse.java | 5 +-- .../statistics/dto/TeamStatisticsDto.java | 4 +- .../dto/TeamStatisticsResponse.java | 3 +- .../team/controller/TeamController.java | 3 +- .../domain/team/dto/TeamInfoResponse.java | 3 +- .../domain/team/service/TeamService.java | 16 ++++--- .../domain/user/dto/SolvedProblemDto.java | 4 +- .../user/dto/UserSolvedProblemPairDto.java | 3 +- .../user/dto/authDto/LogoutResponse.java | 1 - .../domain/user/service/UserInfoService.java | 22 ++++++---- .../user/service/UserRandomStreakService.java | 35 ++++++++------- .../global/auditing/BaseTimeEntity.java | 9 ++-- .../global/aws/s3/config/S3Config.java | 1 - .../global/component/crawler/WebCrawler.java | 11 +---- .../component/imageParser/ImageParser.java | 1 - .../imageParser/ImageParserImpl.java | 13 +++--- .../global/config/LogConfig.java | 9 ++-- .../notify/entity/NotifyToAdminEvent.java | 25 +++++++++++ .../event/notify/entity/NotifyToAllEvent.java | 24 +++++++++++ .../entity/NotifyToUserBySenderEvent.java | 22 ++++++++++ .../entity/NotifyToUserBySystemEvent.java | 29 +++++++++++++ .../notify/handler/NotifyEventHandler.java | 43 +++++++++++++++++++ .../global/scheduler/Scheduler.java | 1 + 52 files changed, 343 insertions(+), 192 deletions(-) create mode 100644 src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAdminEvent.java create mode 100644 src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAllEvent.java create mode 100644 src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySenderEvent.java create mode 100644 src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySystemEvent.java create mode 100644 src/main/java/com/randps/randomdefence/global/event/notify/handler/NotifyEventHandler.java diff --git a/src/main/java/com/randps/randomdefence/domain/board/controller/BoardController.java b/src/main/java/com/randps/randomdefence/domain/board/controller/BoardController.java index 81b47d4..57a0368 100644 --- a/src/main/java/com/randps/randomdefence/domain/board/controller/BoardController.java +++ b/src/main/java/com/randps/randomdefence/domain/board/controller/BoardController.java @@ -1,8 +1,15 @@ package com.randps.randomdefence.domain.board.controller; import com.randps.randomdefence.domain.board.domain.Board; -import com.randps.randomdefence.domain.board.dto.*; +import com.randps.randomdefence.domain.board.dto.BoardDetail; +import com.randps.randomdefence.domain.board.dto.BoardPublishRequest; +import com.randps.randomdefence.domain.board.dto.BoardSimple; +import com.randps.randomdefence.domain.board.dto.BoardUpdateRequest; +import com.randps.randomdefence.domain.board.dto.SearchCondition; import com.randps.randomdefence.domain.board.service.BoardService; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -10,11 +17,13 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/randps/randomdefence/domain/board/dto/BoardDetail.java b/src/main/java/com/randps/randomdefence/domain/board/dto/BoardDetail.java index 7058869..5de2b3a 100644 --- a/src/main/java/com/randps/randomdefence/domain/board/dto/BoardDetail.java +++ b/src/main/java/com/randps/randomdefence/domain/board/dto/BoardDetail.java @@ -1,13 +1,11 @@ package com.randps.randomdefence.domain.board.dto; +import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; -import java.util.List; - @Data @Builder @AllArgsConstructor diff --git a/src/main/java/com/randps/randomdefence/domain/board/service/BoardService.java b/src/main/java/com/randps/randomdefence/domain/board/service/BoardService.java index b519dba..fb73c02 100644 --- a/src/main/java/com/randps/randomdefence/domain/board/service/BoardService.java +++ b/src/main/java/com/randps/randomdefence/domain/board/service/BoardService.java @@ -13,13 +13,14 @@ import com.randps.randomdefence.domain.image.service.port.BoardImageRepository; import com.randps.randomdefence.domain.image.service.port.ImageRepository; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.global.aws.s3.service.S3Service; +import com.randps.randomdefence.global.event.notify.entity.NotifyToAllEvent; import java.util.ArrayList; import java.util.List; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -41,7 +42,7 @@ public class BoardService { private final BoardImageRepository boardImageRepository; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; /* * 게시글 저장 @@ -60,8 +61,9 @@ public Board save(String type, String bojHandle, String title, String content, I // 만약 공지라면 전체 유저에게 알림을 발행한다. if (type.equals("notice")) { - notifyService.systemPublishToAll("📣 새로운 공지가 등록되었습니다. 확인해보세요! [" + board.getTitle() + "]", - NotifyType.NOTICE, board.getId()); + applicationContext.publishEvent( + new NotifyToAllEvent(this, "📣 새로운 공지가 등록되었습니다. 확인해보세요! [" + board.getTitle() + "]", + NotifyType.NOTICE, board.getId())); } if (images.isBlank() || images.isEmpty()) { @@ -105,8 +107,9 @@ public Board update(Long boardId, String type, String bojHandle, String title, S // 만약 공지라면 전체 유저에게 알림을 발행한다. if (type.equals("notice")) { - notifyService.systemPublishToAll("📣 공지에 변화가 있습니다. 확인해보세요! [" + board.getTitle() + "]", - NotifyType.NOTICE, board.getId()); + applicationContext.publishEvent( + new NotifyToAllEvent(this, "📣 공지에 변화가 있습니다. 확인해보세요! [" + board.getTitle() + "]", + NotifyType.NOTICE, board.getId())); } if (images.isBlank() || images.isEmpty()) { diff --git a/src/main/java/com/randps/randomdefence/domain/boolshit/controller/BoolshitController.java b/src/main/java/com/randps/randomdefence/domain/boolshit/controller/BoolshitController.java index be592d0..9874e1d 100644 --- a/src/main/java/com/randps/randomdefence/domain/boolshit/controller/BoolshitController.java +++ b/src/main/java/com/randps/randomdefence/domain/boolshit/controller/BoolshitController.java @@ -1,16 +1,13 @@ package com.randps.randomdefence.domain.boolshit.controller; -import com.randps.randomdefence.domain.boolshit.domain.Boolshit; -import com.randps.randomdefence.domain.boolshit.dto.BoolshitLastResponse; import com.randps.randomdefence.domain.boolshit.dto.BoolshitResponse; import com.randps.randomdefence.domain.boolshit.service.BoolshitService; +import java.util.List; import lombok.RequiredArgsConstructor; 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; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/boolshit") diff --git a/src/main/java/com/randps/randomdefence/domain/boolshit/dto/BoolshitLastResponse.java b/src/main/java/com/randps/randomdefence/domain/boolshit/dto/BoolshitLastResponse.java index 0688a11..feefdc2 100644 --- a/src/main/java/com/randps/randomdefence/domain/boolshit/dto/BoolshitLastResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/boolshit/dto/BoolshitLastResponse.java @@ -1,10 +1,9 @@ package com.randps.randomdefence.domain.boolshit.dto; +import java.time.LocalDateTime; import lombok.Builder; import lombok.Data; -import java.time.LocalDateTime; - @Data public class BoolshitLastResponse { private Long id; diff --git a/src/main/java/com/randps/randomdefence/domain/comment/controller/CommentController.java b/src/main/java/com/randps/randomdefence/domain/comment/controller/CommentController.java index dacd016..c8a592a 100644 --- a/src/main/java/com/randps/randomdefence/domain/comment/controller/CommentController.java +++ b/src/main/java/com/randps/randomdefence/domain/comment/controller/CommentController.java @@ -5,11 +5,16 @@ import com.randps.randomdefence.domain.comment.dto.CommentPublishRequest; import com.randps.randomdefence.domain.comment.dto.CommentUpdateRequest; import com.randps.randomdefence.domain.comment.service.CommentService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.repository.query.Param; -import org.springframework.web.bind.annotation.*; - -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/randps/randomdefence/domain/comment/dto/CommentDto.java b/src/main/java/com/randps/randomdefence/domain/comment/dto/CommentDto.java index 308495d..b539663 100644 --- a/src/main/java/com/randps/randomdefence/domain/comment/dto/CommentDto.java +++ b/src/main/java/com/randps/randomdefence/domain/comment/dto/CommentDto.java @@ -1,13 +1,11 @@ package com.randps.randomdefence.domain.comment.dto; +import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; -import java.util.List; - @Data @Builder @AllArgsConstructor diff --git a/src/main/java/com/randps/randomdefence/domain/comment/service/CommentService.java b/src/main/java/com/randps/randomdefence/domain/comment/service/CommentService.java index d046b15..37e5af4 100644 --- a/src/main/java/com/randps/randomdefence/domain/comment/service/CommentService.java +++ b/src/main/java/com/randps/randomdefence/domain/comment/service/CommentService.java @@ -9,13 +9,14 @@ import com.randps.randomdefence.domain.comment.dto.CommentUpdateRequest; import com.randps.randomdefence.domain.comment.service.port.CommentRepository; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; import java.util.List; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -29,7 +30,7 @@ public class CommentService { private final CommentRepository commentRepository; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; /** * 코멘트 저장 @@ -59,18 +60,20 @@ public Comment save(CommentPublishRequest commentPublishRequest) { () -> new NotFoundException("존재하지 않는 유저입니다.")); if (!parentCommenter.getBojHandle().equals(commenter.getBojHandle()) && !parentComment.getBojHandle().equals(board.getBojHandle())) { - notifyService.systemPublish(parentCommenter.getBojHandle(), - "[" + board.getTitle() + "] 에 작성한 댓글에 [" + commenter.getNotionId() - + "] 님이 댓글을 작성했습니다." + " - \"" + commentPublishRequest.getContent() + "\"", - NotifyType.SYSTEM, commentPublishRequest.getBoardId()); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, parentCommenter.getBojHandle(), + "[" + board.getTitle() + "] 에 작성한 댓글에 [" + commenter.getNotionId() + + "] 님이 댓글을 작성했습니다." + " - \"" + commentPublishRequest.getContent() + "\"", + NotifyType.SYSTEM, commentPublishRequest.getBoardId())); } } if (!commenter.getBojHandle().equals(board.getBojHandle())) { // 글쓴이에게 보내는 알림을 발행한다. - notifyService.systemPublish(board.getBojHandle(), - "작성한 글 [" + board.getTitle() + "] 에 [" + commenter.getNotionId() - + "] 님이 댓글을 작성했습니다." + " - \"" + commentPublishRequest.getContent() + "\"", - NotifyType.SYSTEM, commentPublishRequest.getBoardId()); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, board.getBojHandle(), + "작성한 글 [" + board.getTitle() + "] 에 [" + commenter.getNotionId() + + "] 님이 댓글을 작성했습니다." + " - \"" + commentPublishRequest.getContent() + "\"", + NotifyType.SYSTEM, commentPublishRequest.getBoardId())); } return comment; diff --git a/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintProcessorService.java b/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintProcessorService.java index b1cf9e0..95316b3 100644 --- a/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintProcessorService.java +++ b/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintProcessorService.java @@ -5,12 +5,13 @@ import com.randps.randomdefence.domain.complaint.enums.ProcessType; import com.randps.randomdefence.domain.complaint.service.port.ComplaintRepository; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; @Service @@ -22,7 +23,7 @@ public class ComplaintProcessorService { private final UserRepository userRepository; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; /* * 민원의 상태를 바꾼다. @@ -43,18 +44,20 @@ public void changeProcessType(ComplaintProcessorUpdateRequest request, String bo } if (request.getProcessType().equals(ProcessType.WAITING)) { complaint.setProcessWAITING(); - notifyService.systemPublish(complaint.getRequester(), "😴 내 민원이 [대기] 상태로 변경되었습니다.", - NotifyType.ADMIN, null); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, complaint.getRequester(), "😴 내 민원이 [대기] 상태로 변경되었습니다.", + NotifyType.ADMIN, null)); } if (request.getProcessType().equals(ProcessType.PROCESSING)) { complaint.setProcessPROCESSING(); - notifyService.systemPublish(complaint.getRequester(), "😎 내 민원이 [처리 중] 상태로 변경되었습니다.", - NotifyType.ADMIN, null); + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, complaint.getRequester(), + "😎 내 민원이 [처리 중] 상태로 변경되었습니다.", NotifyType.ADMIN, null)); } if (request.getProcessType().equals(ProcessType.DONE)) { complaint.setProcessDONE(); - notifyService.systemPublish(complaint.getRequester(), "🥳 내 민원이 [처리 완료] 상태로 변경되었습니다.", - NotifyType.ADMIN, null); + + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, complaint.getRequester(), + "🥳 내 민원이 [처리 완료] 상태로 변경되었습니다.", NotifyType.ADMIN, null)); } if (request.getReply() != null) { complaint.updateProcessorAndReply(request.getProcessor(), request.getReply()); diff --git a/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintRequesterService.java b/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintRequesterService.java index 05af062..3147945 100644 --- a/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintRequesterService.java +++ b/src/main/java/com/randps/randomdefence/domain/complaint/service/ComplaintRequesterService.java @@ -6,12 +6,14 @@ import com.randps.randomdefence.domain.complaint.dto.ComplaintUpdateRequest; import com.randps.randomdefence.domain.complaint.service.port.ComplaintRepository; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.global.event.notify.entity.NotifyToAdminEvent; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.security.access.AccessDeniedException; import org.springframework.stereotype.Service; @@ -24,7 +26,7 @@ public class ComplaintRequesterService { private final UserRepository userRepository; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; /* * 민원인의 민원을 생성한다. @@ -39,8 +41,9 @@ public Complaint makeNewComplaint(ComplaintSaveRequest request, String bojHandle if (!request.getRequester().equals(bojHandle) && !user.getManager()) { throw new AccessDeniedException("이 민원을 생성할 권한이 없습니다."); } - notifyService.systemPublishToAdmins("[" + user.getNotionId() + "]님이 작성한 새로운 민원이 등록되었습니다.", - NotifyType.ADMIN, null); + applicationContext.publishEvent( + new NotifyToAdminEvent(this, "[" + user.getNotionId() + "]님이 작성한 새로운 민원이 등록되었습니다.", + NotifyType.ADMIN, null)); return complaintRepository.save(ComplaintSaveRequest.to(request)); } @@ -81,11 +84,12 @@ public void delete(ComplaintDeleteRequest request, String bojHandle) throw new AccessDeniedException("삭제 권한이 없습니다."); } - notifyService.systemPublish(complaint.getRequester(), "😈 내 민원이 삭제되었습니다.", - NotifyType.ADMIN, null); - notifyService.systemPublishToAdmins( + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, + complaint.getRequester(), "😈 내 민원이 삭제되었습니다.", + NotifyType.ADMIN, null)); + applicationContext.publishEvent(new NotifyToAdminEvent(this, "[" + requester.getNotionId() + "]님이 작성한 기존의 민원을 " + user.getNotionId() + "님이 삭제했습니다.", - NotifyType.ADMIN, null); + NotifyType.ADMIN, null)); complaintRepository.delete(complaint); } diff --git a/src/main/java/com/randps/randomdefence/domain/event/controller/EventPointSearchController.java b/src/main/java/com/randps/randomdefence/domain/event/controller/EventPointSearchController.java index 6cf9b3a..71c436c 100644 --- a/src/main/java/com/randps/randomdefence/domain/event/controller/EventPointSearchController.java +++ b/src/main/java/com/randps/randomdefence/domain/event/controller/EventPointSearchController.java @@ -2,13 +2,12 @@ import com.randps.randomdefence.domain.event.dto.EventPointDto; import com.randps.randomdefence.domain.event.service.EventPointSearchService; +import java.util.List; import lombok.RequiredArgsConstructor; 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; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/event/point") diff --git a/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointDto.java b/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointDto.java index 539f331..5c79bb2 100644 --- a/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointDto.java +++ b/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointDto.java @@ -1,12 +1,11 @@ package com.randps.randomdefence.domain.event.dto; +import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @AllArgsConstructor diff --git a/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointPublishRequest.java b/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointPublishRequest.java index 273f3bc..26282c1 100644 --- a/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointPublishRequest.java +++ b/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointPublishRequest.java @@ -1,12 +1,11 @@ package com.randps.randomdefence.domain.event.dto; +import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @AllArgsConstructor diff --git a/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointUpdateRequest.java b/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointUpdateRequest.java index c0bd677..8879031 100644 --- a/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointUpdateRequest.java +++ b/src/main/java/com/randps/randomdefence/domain/event/dto/EventPointUpdateRequest.java @@ -1,12 +1,11 @@ package com.randps.randomdefence.domain.event.dto; +import java.time.LocalDateTime; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import java.time.LocalDateTime; - @Data @Builder @AllArgsConstructor diff --git a/src/main/java/com/randps/randomdefence/domain/image/controller/ImageController.java b/src/main/java/com/randps/randomdefence/domain/image/controller/ImageController.java index e8e7141..daae9b7 100644 --- a/src/main/java/com/randps/randomdefence/domain/image/controller/ImageController.java +++ b/src/main/java/com/randps/randomdefence/domain/image/controller/ImageController.java @@ -2,14 +2,12 @@ import com.randps.randomdefence.domain.image.domain.Image; import com.randps.randomdefence.domain.image.service.ImageService; -import com.randps.randomdefence.global.aws.s3.service.S3Service; +import java.util.List; import lombok.RequiredArgsConstructor; 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; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/image") diff --git a/src/main/java/com/randps/randomdefence/domain/image/controller/ImageS3Controller.java b/src/main/java/com/randps/randomdefence/domain/image/controller/ImageS3Controller.java index 2a322af..96dff70 100644 --- a/src/main/java/com/randps/randomdefence/domain/image/controller/ImageS3Controller.java +++ b/src/main/java/com/randps/randomdefence/domain/image/controller/ImageS3Controller.java @@ -4,18 +4,22 @@ import com.randps.randomdefence.domain.image.dto.ImageUploadResponse; import com.randps.randomdefence.domain.image.service.ImageService; import com.randps.randomdefence.global.aws.s3.service.S3Service; +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.core.io.UrlResource; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import org.springframework.web.multipart.MultipartFile; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/image/s3") diff --git a/src/main/java/com/randps/randomdefence/domain/item/controller/ItemController.java b/src/main/java/com/randps/randomdefence/domain/item/controller/ItemController.java index 0654e44..114804f 100644 --- a/src/main/java/com/randps/randomdefence/domain/item/controller/ItemController.java +++ b/src/main/java/com/randps/randomdefence/domain/item/controller/ItemController.java @@ -1,19 +1,25 @@ package com.randps.randomdefence.domain.item.controller; -import com.randps.randomdefence.domain.item.domain.Item; import com.randps.randomdefence.domain.item.dto.ItemDto; import com.randps.randomdefence.domain.item.dto.UserItemResponse; -import com.randps.randomdefence.domain.item.service.*; +import com.randps.randomdefence.domain.item.service.BoolshitItemUseServiceImpl; +import com.randps.randomdefence.domain.item.service.DeleteWarningItemUseServiceImpl; +import com.randps.randomdefence.domain.item.service.ItemSaveService; +import com.randps.randomdefence.domain.item.service.ItemSearchService; +import com.randps.randomdefence.domain.item.service.TestItemUseServiceImpl; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.data.repository.query.Param; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/randps/randomdefence/domain/log/controller/PointLogController.java b/src/main/java/com/randps/randomdefence/domain/log/controller/PointLogController.java index 05a6dd6..f8f6220 100644 --- a/src/main/java/com/randps/randomdefence/domain/log/controller/PointLogController.java +++ b/src/main/java/com/randps/randomdefence/domain/log/controller/PointLogController.java @@ -1,17 +1,18 @@ package com.randps.randomdefence.domain.log.controller; import com.randps.randomdefence.domain.log.domain.PointLog; -import com.randps.randomdefence.domain.log.domain.WarningLog; import com.randps.randomdefence.domain.log.service.PointLogSaveService; import com.randps.randomdefence.domain.log.service.PointLogSearchService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.query.Param; -import org.springframework.web.bind.annotation.*; - -import java.awt.*; -import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/randps/randomdefence/domain/log/controller/WarningLogController.java b/src/main/java/com/randps/randomdefence/domain/log/controller/WarningLogController.java index 691539e..d668a6b 100644 --- a/src/main/java/com/randps/randomdefence/domain/log/controller/WarningLogController.java +++ b/src/main/java/com/randps/randomdefence/domain/log/controller/WarningLogController.java @@ -1,16 +1,18 @@ package com.randps.randomdefence.domain.log.controller; -import com.randps.randomdefence.domain.log.domain.PointLog; import com.randps.randomdefence.domain.log.domain.WarningLog; import com.randps.randomdefence.domain.log.service.WarningLogSaveService; import com.randps.randomdefence.domain.log.service.WarningLogSearchService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.repository.query.Param; -import org.springframework.web.bind.annotation.*; - -import java.util.List; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/randps/randomdefence/domain/problem/dto/ProblemDto.java b/src/main/java/com/randps/randomdefence/domain/problem/dto/ProblemDto.java index b389636..9961d05 100644 --- a/src/main/java/com/randps/randomdefence/domain/problem/dto/ProblemDto.java +++ b/src/main/java/com/randps/randomdefence/domain/problem/dto/ProblemDto.java @@ -1,11 +1,9 @@ package com.randps.randomdefence.domain.problem.dto; -import lombok.Builder; -import lombok.Data; - -import javax.persistence.ElementCollection; import java.util.ArrayList; import java.util.List; +import lombok.Builder; +import lombok.Data; @Data public class ProblemDto { diff --git a/src/main/java/com/randps/randomdefence/domain/recommendation/controller/RecommendationController.java b/src/main/java/com/randps/randomdefence/domain/recommendation/controller/RecommendationController.java index 1f5a29b..3035b5c 100644 --- a/src/main/java/com/randps/randomdefence/domain/recommendation/controller/RecommendationController.java +++ b/src/main/java/com/randps/randomdefence/domain/recommendation/controller/RecommendationController.java @@ -1,15 +1,14 @@ package com.randps.randomdefence.domain.recommendation.controller; -import com.randps.randomdefence.domain.recommendation.service.RecommendationService; import com.randps.randomdefence.domain.recommendation.dto.RecommendationResponse; +import com.randps.randomdefence.domain.recommendation.service.RecommendationService; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.repository.query.Param; 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; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/recommend") diff --git a/src/main/java/com/randps/randomdefence/domain/recommendation/dto/RecommendationResponse.java b/src/main/java/com/randps/randomdefence/domain/recommendation/dto/RecommendationResponse.java index 4b47458..413748d 100644 --- a/src/main/java/com/randps/randomdefence/domain/recommendation/dto/RecommendationResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/recommendation/dto/RecommendationResponse.java @@ -1,10 +1,9 @@ package com.randps.randomdefence.domain.recommendation.dto; +import java.util.ArrayList; import lombok.Builder; import lombok.Data; -import java.util.ArrayList; - @Data public class RecommendationResponse { public Integer problemId; diff --git a/src/main/java/com/randps/randomdefence/domain/scraping/domain/Scraping.java b/src/main/java/com/randps/randomdefence/domain/scraping/domain/Scraping.java index 133b2f3..31077c4 100644 --- a/src/main/java/com/randps/randomdefence/domain/scraping/domain/Scraping.java +++ b/src/main/java/com/randps/randomdefence/domain/scraping/domain/Scraping.java @@ -1,12 +1,15 @@ package com.randps.randomdefence.domain.scraping.domain; import com.randps.randomdefence.global.auditing.BaseTimeEntity; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; -import javax.persistence.*; - @NoArgsConstructor @Getter @Table(name = "RD_SCRAPING") diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsController.java b/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsController.java index 5347b0c..bdc23bd 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsController.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsController.java @@ -1,12 +1,10 @@ package com.randps.randomdefence.domain.statistics.controller; -import com.randps.randomdefence.domain.statistics.domain.UserStatistics; import com.randps.randomdefence.domain.statistics.dto.PointBarGraphStatisticsResponse; import com.randps.randomdefence.domain.statistics.dto.SolvedBarGraphStatisticsResponse; import com.randps.randomdefence.domain.statistics.service.PointBarGraphStatisticsService; import com.randps.randomdefence.domain.statistics.service.SolvedBarGraphStatisticsService; import lombok.RequiredArgsConstructor; -import org.springframework.data.repository.query.Param; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsControllerV2.java b/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsControllerV2.java index 0d793b3..dc61637 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsControllerV2.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/controller/GraphStatisticsControllerV2.java @@ -1,18 +1,19 @@ package com.randps.randomdefence.domain.statistics.controller; -import com.randps.randomdefence.domain.statistics.dto.*; +import com.randps.randomdefence.domain.statistics.dto.PointBarPair; +import com.randps.randomdefence.domain.statistics.dto.SolvedBarPair; +import com.randps.randomdefence.domain.statistics.dto.UserIsTodaySolvedDto; +import com.randps.randomdefence.domain.statistics.dto.UserWarningBarDto; import com.randps.randomdefence.domain.statistics.service.PointBarGraphStatisticsServiceV2; import com.randps.randomdefence.domain.statistics.service.SolvedBarGraphStatisticsServiceV2; import com.randps.randomdefence.domain.statistics.service.UserStatisticsServiceV2; import com.randps.randomdefence.domain.statistics.service.WarningBarGraphStatisticsServiceV2; -import com.randps.randomdefence.domain.user.service.UserInfoService; +import java.util.List; import lombok.RequiredArgsConstructor; 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; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v2/stat/graph") diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/controller/UserStatisticsController.java b/src/main/java/com/randps/randomdefence/domain/statistics/controller/UserStatisticsController.java index 2d30a17..75655c6 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/controller/UserStatisticsController.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/controller/UserStatisticsController.java @@ -4,17 +4,19 @@ import com.randps.randomdefence.domain.statistics.dto.YesterdayUnsolvedUserDto; import com.randps.randomdefence.domain.statistics.service.UserStatisticsService; import com.randps.randomdefence.domain.statistics.service.UserStatisticsServiceV2; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import org.springframework.data.repository.query.Param; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.*; - -import java.net.http.HttpResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @RestController diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarDto.java b/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarDto.java index 96c079d..8cf9b99 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarDto.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarDto.java @@ -1,6 +1,5 @@ package com.randps.randomdefence.domain.statistics.dto; -import com.randps.randomdefence.domain.statistics.domain.UserProblemStatistics; import com.randps.randomdefence.domain.user.domain.User; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarGraphStatisticsResponse.java b/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarGraphStatisticsResponse.java index 52bd2af..5de3373 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarGraphStatisticsResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/dto/PointBarGraphStatisticsResponse.java @@ -1,10 +1,9 @@ package com.randps.randomdefence.domain.statistics.dto; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.List; - @Data public class PointBarGraphStatisticsResponse { diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarDto.java b/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarDto.java index fb64442..901e380 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarDto.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarDto.java @@ -5,8 +5,6 @@ import lombok.Builder; import lombok.Data; -import java.util.List; - @Data public class SolvedBarDto { private User user; diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarGraphStatisticsResponse.java b/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarGraphStatisticsResponse.java index be154dd..cf39d55 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarGraphStatisticsResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/dto/SolvedBarGraphStatisticsResponse.java @@ -1,12 +1,9 @@ package com.randps.randomdefence.domain.statistics.dto; -import com.randps.randomdefence.domain.user.domain.User; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.ArrayList; -import java.util.List; - @Data public class SolvedBarGraphStatisticsResponse { private List userBars; diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsDto.java b/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsDto.java index 7013363..5b76963 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsDto.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsDto.java @@ -1,12 +1,10 @@ package com.randps.randomdefence.domain.statistics.dto; import com.randps.randomdefence.domain.team.domain.Team; -import com.randps.randomdefence.domain.user.domain.User; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.List; - @Data public class TeamStatisticsDto { diff --git a/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsResponse.java b/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsResponse.java index 9ca8526..e189427 100644 --- a/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/statistics/dto/TeamStatisticsResponse.java @@ -1,10 +1,9 @@ package com.randps.randomdefence.domain.statistics.dto; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.List; - @Data public class TeamStatisticsResponse { diff --git a/src/main/java/com/randps/randomdefence/domain/team/controller/TeamController.java b/src/main/java/com/randps/randomdefence/domain/team/controller/TeamController.java index 9dc69e6..56e346f 100644 --- a/src/main/java/com/randps/randomdefence/domain/team/controller/TeamController.java +++ b/src/main/java/com/randps/randomdefence/domain/team/controller/TeamController.java @@ -4,6 +4,7 @@ import com.randps.randomdefence.domain.team.service.TeamSearchService; import com.randps.randomdefence.domain.team.service.TeamSettingService; import com.randps.randomdefence.domain.user.domain.User; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.repository.query.Param; import org.springframework.web.bind.annotation.GetMapping; @@ -11,8 +12,6 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.List; - @RequiredArgsConstructor @RestController @RequestMapping("/api/v1/team") diff --git a/src/main/java/com/randps/randomdefence/domain/team/dto/TeamInfoResponse.java b/src/main/java/com/randps/randomdefence/domain/team/dto/TeamInfoResponse.java index 972f5ad..33276fa 100644 --- a/src/main/java/com/randps/randomdefence/domain/team/dto/TeamInfoResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/team/dto/TeamInfoResponse.java @@ -1,11 +1,10 @@ package com.randps.randomdefence.domain.team.dto; import com.randps.randomdefence.domain.user.domain.User; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.List; - @Data public class TeamInfoResponse { diff --git a/src/main/java/com/randps/randomdefence/domain/team/service/TeamService.java b/src/main/java/com/randps/randomdefence/domain/team/service/TeamService.java index 0dee05f..267ea01 100644 --- a/src/main/java/com/randps/randomdefence/domain/team/service/TeamService.java +++ b/src/main/java/com/randps/randomdefence/domain/team/service/TeamService.java @@ -2,16 +2,17 @@ import com.randps.randomdefence.domain.log.service.PointLogSaveService; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.domain.team.domain.Team; import com.randps.randomdefence.domain.team.service.port.TeamRepository; import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; import java.util.List; import java.util.Optional; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -25,7 +26,7 @@ public class TeamService { private final PointLogSaveService pointLogSaveService; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; /* * 팀의 점수를 올린다. @@ -92,17 +93,18 @@ public void weeklyTeamPointDistribution() { true); // 승리 축하 알림을 발행한다. - notifyService.systemPublish(user.getBojHandle(), + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), "🎉 이번 주 팀 경쟁에서 [" + teamName + "] 팀으로 승리했습니다! 🎉", - NotifyType.SYSTEM, null); + NotifyType.SYSTEM, null)); } // 패배 알림을 발행한다. for (User loosingUser : loosingTeamUsers) { - notifyService.systemPublish(loosingUser.getBojHandle(), - "😢 이번 주 팀 경쟁에서 [" + lossingTeamName + "] 팀으로 패배했습니다. 😢", - NotifyType.SYSTEM, null); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, loosingUser.getBojHandle(), + "😢 이번 주 팀 경쟁에서 [" + lossingTeamName + "] 팀으로 패배했습니다. 😢", + NotifyType.SYSTEM, null)); } } } diff --git a/src/main/java/com/randps/randomdefence/domain/user/dto/SolvedProblemDto.java b/src/main/java/com/randps/randomdefence/domain/user/dto/SolvedProblemDto.java index 0aec9ca..a636f3b 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/dto/SolvedProblemDto.java +++ b/src/main/java/com/randps/randomdefence/domain/user/dto/SolvedProblemDto.java @@ -1,11 +1,9 @@ package com.randps.randomdefence.domain.user.dto; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.ArrayList; -import java.util.List; - @Data public class SolvedProblemDto { diff --git a/src/main/java/com/randps/randomdefence/domain/user/dto/UserSolvedProblemPairDto.java b/src/main/java/com/randps/randomdefence/domain/user/dto/UserSolvedProblemPairDto.java index fa53d20..2bdb079 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/dto/UserSolvedProblemPairDto.java +++ b/src/main/java/com/randps/randomdefence/domain/user/dto/UserSolvedProblemPairDto.java @@ -1,10 +1,9 @@ package com.randps.randomdefence.domain.user.dto; +import java.util.List; import lombok.Builder; import lombok.Data; -import java.util.List; - @Data public class UserSolvedProblemPairDto { private String bojHandle; diff --git a/src/main/java/com/randps/randomdefence/domain/user/dto/authDto/LogoutResponse.java b/src/main/java/com/randps/randomdefence/domain/user/dto/authDto/LogoutResponse.java index 3bb666b..0a9cabd 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/dto/authDto/LogoutResponse.java +++ b/src/main/java/com/randps/randomdefence/domain/user/dto/authDto/LogoutResponse.java @@ -1,6 +1,5 @@ package com.randps.randomdefence.domain.user.dto.authDto; -import com.randps.randomdefence.global.jwt.dto.TokenDto; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java index ae410e8..34dd8e6 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java @@ -4,18 +4,19 @@ import com.fasterxml.jackson.databind.JsonNode; import com.randps.randomdefence.domain.log.service.WarningLogSaveService; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.domain.UserRandomStreak; import com.randps.randomdefence.domain.user.dto.UserInfoResponse; import com.randps.randomdefence.domain.user.service.port.UserRepository; import com.randps.randomdefence.global.component.parser.Parser; import com.randps.randomdefence.global.component.parser.SolvedacParser; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; import java.util.List; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -33,7 +34,7 @@ public class UserInfoService { private final SolvedacParser solvedacParser; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; @Qualifier("bojParserToUse") private final Parser bojParser; @@ -64,12 +65,13 @@ public List getAllInfo() { public void updateUserInfo(String bojHandle) { User user = userRepository.findByBojHandle(bojHandle) .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 유저입니다.")); - + // 오늘 문제 푼 것을 축하하는 알림을 발행한다. Boolean isTodaySolved = userSolvedProblemService.isTodaySolved(user.getBojHandle()); if (!user.getIsTodaySolved() && isTodaySolved) { - notifyService.systemPublish(user.getBojHandle(), "😊🥳 오늘도 문제를 해결하셨네요! 정말 정말 잘 했어요!", - NotifyType.SYSTEM, null); + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), + "😊🥳 오늘도 문제를 해결하셨네요! 정말 정말 잘 했어요!", + NotifyType.SYSTEM, null)); } user.setIsTodaySolved(isTodaySolved); @@ -91,8 +93,9 @@ public void updateAllUserInfo() { // 오늘 문제 푼 것을 축하하는 알림을 발행한다. Boolean isTodaySolved = userSolvedProblemService.isTodaySolved(user.getBojHandle()); if (!user.getIsTodaySolved() && isTodaySolved) { - notifyService.systemPublish(user.getBojHandle(), "😊🥳 오늘도 문제를 해결하셨네요! 정말 정말 잘 했어요!", - NotifyType.SYSTEM, null); + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), + "😊🥳 오늘도 문제를 해결하셨네요! 정말 정말 잘 했어요!", + NotifyType.SYSTEM, null)); } user.setIsTodaySolved(isTodaySolved); @@ -160,8 +163,9 @@ public void checkAllUserSolvedStreak() throws JsonProcessingException { } // 스트릭 끊김을 알리는 알림을 발행한다. if (user.getWarning() < 4) { - notifyService.systemPublish(user.getBojHandle(), "문제를 풀지 않아, 경고가 부여됐습니다.", - NotifyType.SYSTEM, null); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, user.getBojHandle(), "문제를 풀지 않아, 경고가 부여됐습니다.", + NotifyType.SYSTEM, null)); } userRepository.save(user); diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserRandomStreakService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserRandomStreakService.java index 4850d5f..80cfbae 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserRandomStreakService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserRandomStreakService.java @@ -6,7 +6,6 @@ import com.randps.randomdefence.domain.item.service.RandomStreakFreezeItemUseServiceImpl; import com.randps.randomdefence.domain.log.service.PointLogSaveService; import com.randps.randomdefence.domain.notify.enums.NotifyType; -import com.randps.randomdefence.domain.notify.service.NotifyService; import com.randps.randomdefence.domain.problem.dto.ProblemDto; import com.randps.randomdefence.domain.problem.service.ProblemService; import com.randps.randomdefence.domain.recommendation.dto.RecommendationResponse; @@ -21,11 +20,13 @@ import com.randps.randomdefence.domain.user.service.port.UserGrassRepository; import com.randps.randomdefence.domain.user.service.port.UserRandomStreakRepository; import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; import java.util.ArrayList; import java.util.List; import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; @RequiredArgsConstructor @@ -57,7 +58,7 @@ public class UserRandomStreakService { private final EventPointService eventPointService; - private final NotifyService notifyService; + private final ApplicationContext applicationContext; /* * 유저 랜덤 스트릭 생성하기 (유저 생성 시 사용) @@ -297,9 +298,9 @@ public Boolean solvedCheck(String bojHandle) { if (solvedProblemDto.getProblemId().equals(randomProblem.getProblemId())) { // 오늘의 랜덤 문제 해결 알림을 발행한다. - notifyService.systemPublish(bojHandle, + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, bojHandle, "🎉 오늘의 랜덤 문제를 해결했습니다. (문제 : " + randomProblem.getProblemId() + ")", NotifyType.SYSTEM, - null); + null)); // 유저의 정보 갱신 user.increasePoint(randomProblem.getLevel() * 2); // 문제의 레벨 * 2만큼의 포인트를 지급한다. @@ -362,9 +363,11 @@ public void solvedCheckAll() { UserGrass todayUserGrass = userGrassService.findTodayUserGrass(userRandomStreak); // 오늘의 랜덤 문제 해결 알림을 발행한다. - notifyService.systemPublish(userCur.getBojHandle(), - "🎉 오늘의 랜덤 문제를 해결했습니다. (문제 : " + randomProblem.getProblemId() + ")", NotifyType.SYSTEM, - null); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, userCur.getBojHandle(), + "🎉 오늘의 랜덤 문제를 해결했습니다. (문제 : " + randomProblem.getProblemId() + ")", + NotifyType.SYSTEM, + null)); // 유저의 정보 갱신 userCur.increasePoint(randomProblem.getLevel() * 2); // 문제의 레벨 * 2만큼의 포인트를 지급한다. @@ -433,8 +436,9 @@ public Boolean streakCheck(String bojHandle) { if (randomStreakFreezeItemUseService.isExist(user)) { randomStreakFreezeItemUseService.useItem(user, 3L); // 아이템 사용 알림을 생성한다. - notifyService.systemPublish(user.getBojHandle(), "자동으로 랜덤 스트릭 프리즈 아이템을 사용했습니다.", - NotifyType.SYSTEM, null); + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, user.getBojHandle(), "자동으로 랜덤 스트릭 프리즈 아이템을 사용했습니다.", + NotifyType.SYSTEM, null)); // 스트릭 프리즈를 사용했으므로 넘어간다. return true; @@ -442,9 +446,9 @@ public Boolean streakCheck(String bojHandle) { // 랜덤 스트릭이 끊어진 경우, 알림을 발행한다. if (user.getCurrentRandomStreak() > 1) { - notifyService.systemPublish(user.getBojHandle(), + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), "🥲 랜덤 스트릭이 끊어졌습니다. (스트릭 : " + user.getCurrentRandomStreak() + ")", NotifyType.SYSTEM, - null); + null)); } // 유저 정보 갱신 @@ -500,8 +504,9 @@ public void streakCheckAll() { randomStreakFreezeItemUseService.useItem(user, 3L); // 아이템 사용 알림을 생성한다. - notifyService.systemPublish(user.getBojHandle(), "자동으로 랜덤 스트릭 프리즈 아이템을 사용했습니다.", - NotifyType.SYSTEM, null); + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), + "자동으로 랜덤 스트릭 프리즈 아이템을 사용했습니다.", + NotifyType.SYSTEM, null)); // 스트릭 프리즈를 사용했으므로 넘어간다. continue; @@ -509,9 +514,9 @@ public void streakCheckAll() { // 랜덤 스트릭이 끊어진 경우, 알림을 발행한다. if (user.getCurrentRandomStreak() > 1) { - notifyService.systemPublish(user.getBojHandle(), + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), "🥲 랜덤 스트릭이 끊어졌습니다. (스트릭 : " + user.getCurrentRandomStreak() + ")", NotifyType.SYSTEM, - null); + null)); } // 유저 정보 갱신 diff --git a/src/main/java/com/randps/randomdefence/global/auditing/BaseTimeEntity.java b/src/main/java/com/randps/randomdefence/global/auditing/BaseTimeEntity.java index f9d778a..45fe09f 100644 --- a/src/main/java/com/randps/randomdefence/global/auditing/BaseTimeEntity.java +++ b/src/main/java/com/randps/randomdefence/global/auditing/BaseTimeEntity.java @@ -1,16 +1,15 @@ package com.randps.randomdefence.global.auditing; import com.fasterxml.jackson.annotation.JsonFormat; +import java.time.LocalDateTime; +import javax.persistence.Column; +import javax.persistence.EntityListeners; +import javax.persistence.MappedSuperclass; import lombok.Getter; import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.Column; -import javax.persistence.EntityListeners; -import javax.persistence.MappedSuperclass; -import java.time.LocalDateTime; - @Getter @MappedSuperclass @EntityListeners(AuditingEntityListener.class) // Auditing 기능 포함 diff --git a/src/main/java/com/randps/randomdefence/global/aws/s3/config/S3Config.java b/src/main/java/com/randps/randomdefence/global/aws/s3/config/S3Config.java index e1aaf59..fde2a40 100644 --- a/src/main/java/com/randps/randomdefence/global/aws/s3/config/S3Config.java +++ b/src/main/java/com/randps/randomdefence/global/aws/s3/config/S3Config.java @@ -3,7 +3,6 @@ import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.AWSStaticCredentialsProvider; import com.amazonaws.auth.BasicAWSCredentials; -import com.amazonaws.services.s3.AmazonS3; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.AmazonS3ClientBuilder; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/randps/randomdefence/global/component/crawler/WebCrawler.java b/src/main/java/com/randps/randomdefence/global/component/crawler/WebCrawler.java index cb00a33..496c0bf 100644 --- a/src/main/java/com/randps/randomdefence/global/component/crawler/WebCrawler.java +++ b/src/main/java/com/randps/randomdefence/global/component/crawler/WebCrawler.java @@ -1,19 +1,12 @@ package com.randps.randomdefence.global.component.crawler; +import java.io.IOException; +import java.util.List; import org.jsoup.Connection; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; -import org.jsoup.nodes.Element; -import org.jsoup.select.Elements; import org.springframework.stereotype.Component; -import java.io.IOException; -import java.time.LocalDate; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - @Component public abstract class WebCrawler { private String url; diff --git a/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParser.java b/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParser.java index caea940..964726c 100644 --- a/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParser.java +++ b/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParser.java @@ -2,7 +2,6 @@ import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; import java.net.URL; public interface ImageParser { diff --git a/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParserImpl.java index 1dedbe3..c7a4270 100644 --- a/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/imageParser/ImageParserImpl.java @@ -1,18 +1,17 @@ package com.randps.randomdefence.global.component.imageParser; -import org.springframework.stereotype.Component; - -import javax.imageio.IIOImage; -import javax.imageio.ImageIO; -import javax.imageio.ImageWriter; -import javax.imageio.plugins.jpeg.JPEGImageWriteParam; -import javax.imageio.stream.ImageOutputStream; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.util.Iterator; +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageWriter; +import javax.imageio.plugins.jpeg.JPEGImageWriteParam; +import javax.imageio.stream.ImageOutputStream; +import org.springframework.stereotype.Component; @Component public class ImageParserImpl implements ImageParser { diff --git a/src/main/java/com/randps/randomdefence/global/config/LogConfig.java b/src/main/java/com/randps/randomdefence/global/config/LogConfig.java index 92a2a61..d7c2b76 100644 --- a/src/main/java/com/randps/randomdefence/global/config/LogConfig.java +++ b/src/main/java/com/randps/randomdefence/global/config/LogConfig.java @@ -1,21 +1,18 @@ package com.randps.randomdefence.global.config; import com.google.common.base.Joiner; +import java.util.Map; +import java.util.stream.Collectors; +import javax.servlet.http.HttpServletRequest; import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.springframework.stereotype.Component; import org.springframework.web.context.request.RequestAttributes; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; -import javax.servlet.http.HttpServletRequest; -import java.util.Map; -import java.util.stream.Collectors; - @Slf4j -@Component @Aspect public class LogConfig { diff --git a/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAdminEvent.java b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAdminEvent.java new file mode 100644 index 0000000..b65da78 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAdminEvent.java @@ -0,0 +1,25 @@ +package com.randps.randomdefence.global.event.notify.entity; + +import com.randps.randomdefence.domain.notify.enums.NotifyType; +import lombok.Getter; +import lombok.Setter; +import org.springframework.context.ApplicationEvent; + +@Setter +@Getter +public class NotifyToAdminEvent extends ApplicationEvent { + + private String message; + + private NotifyType type; + + private Long relatedBoardId; + + public NotifyToAdminEvent(Object source, String message, NotifyType type, Long relatedBoardId) { + super(source); + this.message = message; + this.type = type; + this.relatedBoardId = relatedBoardId; + } + +} diff --git a/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAllEvent.java b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAllEvent.java new file mode 100644 index 0000000..6ec912f --- /dev/null +++ b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToAllEvent.java @@ -0,0 +1,24 @@ +package com.randps.randomdefence.global.event.notify.entity; + +import com.randps.randomdefence.domain.notify.enums.NotifyType; +import lombok.Getter; +import lombok.Setter; +import org.springframework.context.ApplicationEvent; + +@Setter +@Getter +public class NotifyToAllEvent extends ApplicationEvent { + + private String message; + + private NotifyType type; + + private Long relatedBoardId; + + public NotifyToAllEvent(Object source, String message, NotifyType type, Long relatedBoardId) { + super(source); + this.message = message; + this.type = type; + this.relatedBoardId = relatedBoardId; + } +} diff --git a/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySenderEvent.java b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySenderEvent.java new file mode 100644 index 0000000..1127685 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySenderEvent.java @@ -0,0 +1,22 @@ +package com.randps.randomdefence.global.event.notify.entity; + +import com.randps.randomdefence.domain.notify.dto.NotifyPublishRequest; +import lombok.Getter; +import lombok.Setter; +import org.springframework.context.ApplicationEvent; + +@Setter +@Getter +public class NotifyToUserBySenderEvent extends ApplicationEvent { + + private NotifyPublishRequest request; + + private String sender; + + public NotifyToUserBySenderEvent(Object source, NotifyPublishRequest request, String sender) { + super(source); + this.request = request; + this.sender = sender; + } + +} diff --git a/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySystemEvent.java b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySystemEvent.java new file mode 100644 index 0000000..c710195 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/global/event/notify/entity/NotifyToUserBySystemEvent.java @@ -0,0 +1,29 @@ +package com.randps.randomdefence.global.event.notify.entity; + +import com.randps.randomdefence.domain.notify.enums.NotifyType; +import lombok.Getter; +import lombok.Setter; +import org.springframework.context.ApplicationEvent; + +@Setter +@Getter +public class NotifyToUserBySystemEvent extends ApplicationEvent { + + private String receiver; + + private String message; + + private NotifyType type; + + private Long relatedBoardId; + + public NotifyToUserBySystemEvent(Object source, String receiver, String message, NotifyType type, + Long relatedBoardId) { + super(source); + this.receiver = receiver; + this.message = message; + this.type = type; + this.relatedBoardId = relatedBoardId; + } + +} diff --git a/src/main/java/com/randps/randomdefence/global/event/notify/handler/NotifyEventHandler.java b/src/main/java/com/randps/randomdefence/global/event/notify/handler/NotifyEventHandler.java new file mode 100644 index 0000000..c623cca --- /dev/null +++ b/src/main/java/com/randps/randomdefence/global/event/notify/handler/NotifyEventHandler.java @@ -0,0 +1,43 @@ +package com.randps.randomdefence.global.event.notify.handler; + +import com.randps.randomdefence.domain.notify.service.NotifyService; +import com.randps.randomdefence.global.event.notify.entity.NotifyToAdminEvent; +import com.randps.randomdefence.global.event.notify.entity.NotifyToAllEvent; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySenderEvent; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; +import java.nio.file.AccessDeniedException; +import lombok.RequiredArgsConstructor; +import org.springframework.context.event.EventListener; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class NotifyEventHandler { + + private final NotifyService notifyService; + + @EventListener + public void handlePublishToAllEvent(NotifyToAllEvent event) { + notifyService.systemPublishToAll(event.getMessage(), event.getType(), + event.getRelatedBoardId()); + } + + @EventListener + public void handlePublishToAdminEvent(NotifyToAdminEvent event) { + notifyService.systemPublishToAdmins(event.getMessage(), event.getType(), + event.getRelatedBoardId()); + } + + @EventListener + public void handlePublishToUserBySenderEvent(NotifyToUserBySenderEvent event) + throws AccessDeniedException { + notifyService.publish(event.getRequest(), event.getSender()); + } + + @EventListener + public void handlePublishToUserBySystemEvent(NotifyToUserBySystemEvent event) { + notifyService.systemPublish(event.getReceiver(), event.getMessage(), event.getType(), + event.getRelatedBoardId()); + } + +} diff --git a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java index 0d82a31..38fe049 100644 --- a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java +++ b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java @@ -83,4 +83,5 @@ public void weekInitJob() { teamSettingService.initWeekly(); // 팀 포인트 주간 초기화 teamSettingService.setUsers(); // 모든 유저 팀 할당 } + } From 020d05615cd850b9753d05adddf409c3b9091962 Mon Sep 17 00:00:00 2001 From: fing9 Date: Fri, 31 May 2024 16:15:14 +0900 Subject: [PATCH 02/14] =?UTF-8?q?[Feat]=20=EC=A3=BC=EB=A7=90=EC=97=90=20?= =?UTF-8?q?=EA=B2=BD=EA=B3=A0=EA=B0=80=203=ED=9A=8C=EC=9D=B8=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=EC=97=90=EA=B2=8C=20=EA=B2=BD=EA=B3=A0=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=B0=9C=ED=96=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notify/service/AutoNotifyService.java | 34 +++++++++++++++++++ .../global/scheduler/Scheduler.java | 14 +++++++- 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/randps/randomdefence/domain/notify/service/AutoNotifyService.java diff --git a/src/main/java/com/randps/randomdefence/domain/notify/service/AutoNotifyService.java b/src/main/java/com/randps/randomdefence/domain/notify/service/AutoNotifyService.java new file mode 100644 index 0000000..03b45e0 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/notify/service/AutoNotifyService.java @@ -0,0 +1,34 @@ +package com.randps.randomdefence.domain.notify.service; + +import com.randps.randomdefence.domain.notify.enums.NotifyType; +import com.randps.randomdefence.domain.user.domain.User; +import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.global.event.notify.entity.NotifyToUserBySystemEvent; +import java.util.List; +import javax.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationContext; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class AutoNotifyService { + + private final UserRepository userRepository; + + private final ApplicationContext applicationContext; + + @Transactional + public void weekendWarningNotify() { + List users = userRepository.findAll(); + + for (User user : users) { + if (user.getWarning() == 3) { + applicationContext.publishEvent( + new NotifyToUserBySystemEvent(this, user.getBojHandle(), + "🚨 현재 경고 3회 입니다. 경고를 차감해주세요", NotifyType.SYSTEM, null)); + } + } + } + +} diff --git a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java index 38fe049..c48bdd4 100644 --- a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java +++ b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java @@ -1,6 +1,7 @@ package com.randps.randomdefence.global.scheduler; import com.fasterxml.jackson.core.JsonProcessingException; +import com.randps.randomdefence.domain.notify.service.AutoNotifyService; import com.randps.randomdefence.domain.statistics.service.UserStatisticsService; import com.randps.randomdefence.domain.team.service.TeamService; import com.randps.randomdefence.domain.team.service.TeamSettingService; @@ -23,6 +24,8 @@ @EnableScheduling public class Scheduler { + private final AutoNotifyService autoNotifyService; + private final UserInfoService userInfoService; private final UserSolvedProblemService userSolvedProblemService; @@ -83,5 +86,14 @@ public void weekInitJob() { teamSettingService.initWeekly(); // 팀 포인트 주간 초기화 teamSettingService.setUsers(); // 모든 유저 팀 할당 } - + + /* + * 매 주, 주말에 경고 알림 발행 메서드 (매 주 토, 일요일 새벽 6시 30분) + */ + @Transactional + @Scheduled(cron = "0 30 6 ? * SAT,SUN *") + public void weekendWarningJob() { + autoNotifyService.weekendWarningNotify(); // 경고가 3회인 유저에게 경고 알림을 발행한다. + } + } From 24e321a3083896f7e2a6e594f0636c1c5c6b01c9 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 16:35:49 +0900 Subject: [PATCH 03/14] =?UTF-8?q?[Feat]=20=ED=81=AC=EB=A1=A4=EB=A7=81=20On?= =?UTF-8?q?/Off=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/domain/User.java | 93 +++++++++-------- .../domain/user/domain/UserSetting.java | 59 +++++++++++ .../UserSettingJpaRepository.java | 11 +++ .../UserSettingRepositoryAdapter.java | 30 ++++++ .../service/UserSettingSearchService.java | 32 ++++++ .../service/UserSettingToggleService.java | 31 ++++++ .../service/port/UserSettingRepository.java | 14 +++ .../component/parser/BojParserImpl.java | 10 ++ .../parser/BojProfileParserImpl.java | 9 ++ .../component/parser/SolvedacParserImpl.java | 9 ++ .../service/PrincipalDetailServiceTest.java | 99 ++++++++++--------- 11 files changed, 306 insertions(+), 91 deletions(-) create mode 100644 src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingJpaRepository.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingRepositoryAdapter.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/service/UserSettingToggleService.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/service/port/UserSettingRepository.java diff --git a/src/main/java/com/randps/randomdefence/domain/user/domain/User.java b/src/main/java/com/randps/randomdefence/domain/user/domain/User.java index 8607176..27e54ef 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/domain/User.java +++ b/src/main/java/com/randps/randomdefence/domain/user/domain/User.java @@ -20,6 +20,7 @@ @Table(name = "RD_USER") @Entity public class User extends BaseTimeEntity { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @@ -60,19 +61,23 @@ public class User extends BaseTimeEntity { private Integer todaySolvedProblemCount; // by Solved - /* * 유저 Role Parser */ - public List getRolesList(){ - if(this.roles.length() > 0){ + public List getRolesList() { + if (this.roles.length() > 0) { return Arrays.asList(this.roles.split(",")); } return new ArrayList<>(); } @Builder - public User(Long id, String bojHandle, String password, String roles, String notionId, Boolean manager, Integer warning, String profileImg, String emoji, Integer tier, Integer totalSolved, Integer currentStreak, Integer currentRandomStreak, Integer team, Integer point, Boolean isTodaySolved, Boolean isTodayRandomSolved, Boolean isYesterdaySolved, Integer todaySolvedProblemCount) { + public User(Long id, String bojHandle, String password, String roles, String notionId, + Boolean manager, Integer warning, String profileImg, String emoji, Integer tier, + Integer totalSolved, Integer currentStreak, Integer currentRandomStreak, Integer team, + Integer point, Boolean isTodaySolved, Boolean isTodayRandomSolved, + Boolean isYesterdaySolved, + Integer todaySolvedProblemCount) { this.id = id; this.bojHandle = bojHandle; this.password = password; @@ -132,7 +137,9 @@ public Boolean increasePoint(Integer value) { } public Boolean decreasePoint(Integer value) { - if (this.point < value) return false; + if (this.point < value) { + return false; + } this.point -= value; return true; } @@ -163,46 +170,46 @@ public void resetCurrentRandomStreak() { public UserInfoResponse toUserInfoResponse() { return UserInfoResponse.builder() - .bojHandle(this.getBojHandle()) - .notionId(this.getNotionId()) - .manager(this.getManager()) - .warning(this.getWarning()) - .profileImg(this.getProfileImg()) - .emoji(this.getEmoji()) - .tier(this.getTier()) - .totalSolved(this.getTotalSolved()) - .currentStreak(this.getCurrentStreak()) - .currentRandomStreak(this.getCurrentRandomStreak()) - .team(this.getTeam()) - .point(this.getPoint()) - .isTodaySolved(this.getIsTodaySolved()) - .isYesterdaySolved(this.getIsYesterdaySolved()) - .isTodayRandomSolved(this.getIsTodayRandomSolved()) - .todaySolvedProblemCount(this.getTodaySolvedProblemCount()) - .maxRandomStreak(0) - .build(); + .bojHandle(this.getBojHandle()) + .notionId(this.getNotionId()) + .manager(this.getManager()) + .warning(this.getWarning()) + .profileImg(this.getProfileImg()) + .emoji(this.getEmoji()) + .tier(this.getTier()) + .totalSolved(this.getTotalSolved()) + .currentStreak(this.getCurrentStreak()) + .currentRandomStreak(this.getCurrentRandomStreak()) + .team(this.getTeam()) + .point(this.getPoint()) + .isTodaySolved(this.getIsTodaySolved()) + .isYesterdaySolved(this.getIsYesterdaySolved()) + .isTodayRandomSolved(this.getIsTodayRandomSolved()) + .todaySolvedProblemCount(this.getTodaySolvedProblemCount()) + .maxRandomStreak(0) + .build(); } public UserInfoResponse toUserInfoResponse(Integer maxRandomStreak) { return UserInfoResponse.builder() - .bojHandle(this.getBojHandle()) - .notionId(this.getNotionId()) - .manager(this.getManager()) - .warning(this.getWarning()) - .profileImg(this.getProfileImg()) - .emoji(this.getEmoji()) - .tier(this.getTier()) - .totalSolved(this.getTotalSolved()) - .currentStreak(this.getCurrentStreak()) - .currentRandomStreak(this.getCurrentRandomStreak()) - .team(this.getTeam()) - .point(this.getPoint()) - .isTodaySolved(this.getIsTodaySolved()) - .isYesterdaySolved(this.getIsYesterdaySolved()) - .isTodayRandomSolved(this.getIsTodayRandomSolved()) - .todaySolvedProblemCount(this.getTodaySolvedProblemCount()) - .maxRandomStreak(maxRandomStreak) - .build(); + .bojHandle(this.getBojHandle()) + .notionId(this.getNotionId()) + .manager(this.getManager()) + .warning(this.getWarning()) + .profileImg(this.getProfileImg()) + .emoji(this.getEmoji()) + .tier(this.getTier()) + .totalSolved(this.getTotalSolved()) + .currentStreak(this.getCurrentStreak()) + .currentRandomStreak(this.getCurrentRandomStreak()) + .team(this.getTeam()) + .point(this.getPoint()) + .isTodaySolved(this.getIsTodaySolved()) + .isYesterdaySolved(this.getIsYesterdaySolved()) + .isTodayRandomSolved(this.getIsTodayRandomSolved()) + .todaySolvedProblemCount(this.getTodaySolvedProblemCount()) + .maxRandomStreak(maxRandomStreak) + .build(); } public void setScrapingUserInfo(UserScrapingInfoDto userInfo) { @@ -225,7 +232,9 @@ public void changePassword(String password) { this.password = password; } - public void setIsTodaySolved(Boolean isTodaySolved) {this.isTodaySolved = isTodaySolved;} + public void setIsTodaySolved(Boolean isTodaySolved) { + this.isTodaySolved = isTodaySolved; + } public void setTodaySolvedProblemCount(Integer todaySolvedProblemCount) { this.todaySolvedProblemCount = todaySolvedProblemCount; diff --git a/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java b/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java new file mode 100644 index 0000000..fd73575 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java @@ -0,0 +1,59 @@ +package com.randps.randomdefence.domain.user.domain; + + +import com.randps.randomdefence.global.auditing.BaseTimeEntity; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@NoArgsConstructor +@Getter +@Table(name = "RD_USER_SETTING") +@Entity +public class UserSetting extends BaseTimeEntity { + + @Id + private Long id; + + private String bojHandle; + + private Boolean scrapingOn; + + private Boolean warningOn; + + @Builder + public UserSetting(Long id, String bojHandle, Boolean scrapingOn, Boolean warningOn) { + this.id = id; + this.bojHandle = bojHandle; + this.scrapingOn = scrapingOn; + this.warningOn = warningOn; + } + + public void toggleScraping() { + this.scrapingOn = !this.scrapingOn; + } + + public void toggleWarning() { + this.warningOn = !this.warningOn; + } + + public void disableWarning() { + this.warningOn = false; + } + + public void enableWarning() { + this.warningOn = true; + } + + public void disableScraping() { + this.scrapingOn = false; + } + + public void enableScraping() { + this.scrapingOn = true; + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingJpaRepository.java b/src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingJpaRepository.java new file mode 100644 index 0000000..bc66c8d --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingJpaRepository.java @@ -0,0 +1,11 @@ +package com.randps.randomdefence.domain.user.infrastructure; + +import com.randps.randomdefence.domain.user.domain.UserSetting; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface UserSettingJpaRepository extends JpaRepository { + + Optional findByBojHandle(String bojHandle); + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingRepositoryAdapter.java b/src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingRepositoryAdapter.java new file mode 100644 index 0000000..48cc091 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/infrastructure/UserSettingRepositoryAdapter.java @@ -0,0 +1,30 @@ +package com.randps.randomdefence.domain.user.infrastructure; + +import com.randps.randomdefence.domain.user.domain.UserSetting; +import com.randps.randomdefence.domain.user.service.port.UserSettingRepository; +import java.util.Optional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Repository; + +@Repository +@RequiredArgsConstructor +public class UserSettingRepositoryAdapter implements UserSettingRepository { + + private final UserSettingJpaRepository userSettingJpaRepository; + + @Override + public Optional findByBojHandle(String bojHandle) { + return userSettingJpaRepository.findByBojHandle(bojHandle); + } + + @Override + public UserSetting save(UserSetting userSetting) { + return userSettingJpaRepository.save(userSetting); + } + + @Override + public void delete(UserSetting userSetting) { + userSettingJpaRepository.delete(userSetting); + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java new file mode 100644 index 0000000..a0e3d77 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java @@ -0,0 +1,32 @@ +package com.randps.randomdefence.domain.user.service; + +import com.randps.randomdefence.domain.user.domain.UserSetting; +import com.randps.randomdefence.domain.user.service.port.UserRepository; +import com.randps.randomdefence.domain.user.service.port.UserSettingRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserSettingSearchService { + + private final UserRepository userRepository; + + private final UserSettingRepository userSettingRepository; + + public UserSetting findByBojHandleSafe(String bojHandle) { + userRepository.findByBojHandle(bojHandle) + .orElseThrow(() -> new IllegalArgumentException("사용자가 존재하지 않습니다.")); + + return userSettingRepository.findByBojHandle(bojHandle) + .orElseGet(() -> { + UserSetting userSetting = UserSetting.builder() + .bojHandle(bojHandle) + .scrapingOn(true) + .warningOn(true) + .build(); + return userSettingRepository.save(userSetting); + }); + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingToggleService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingToggleService.java new file mode 100644 index 0000000..c426699 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingToggleService.java @@ -0,0 +1,31 @@ +package com.randps.randomdefence.domain.user.service; + +import com.randps.randomdefence.domain.user.domain.UserSetting; +import com.randps.randomdefence.domain.user.service.port.UserSettingRepository; +import javax.transaction.Transactional; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserSettingToggleService { + + private final UserSettingRepository userSettingRepository; + + private final UserSettingSearchService userSettingSearchService; + + @Transactional + public void toggleScrapingSetting(String bojHandle) { + UserSetting userSetting = userSettingSearchService.findByBojHandleSafe(bojHandle); + userSetting.toggleScraping(); + userSettingRepository.save(userSetting); + } + + @Transactional + public void toggleWarningSetting(String bojHandle) { + UserSetting userSetting = userSettingSearchService.findByBojHandleSafe(bojHandle); + userSetting.toggleWarning(); + userSettingRepository.save(userSetting); + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/port/UserSettingRepository.java b/src/main/java/com/randps/randomdefence/domain/user/service/port/UserSettingRepository.java new file mode 100644 index 0000000..789c992 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/service/port/UserSettingRepository.java @@ -0,0 +1,14 @@ +package com.randps.randomdefence.domain.user.service.port; + +import com.randps.randomdefence.domain.user.domain.UserSetting; +import java.util.Optional; + +public interface UserSettingRepository { + + Optional findByBojHandle(String bojHandle); + + UserSetting save(UserSetting userSetting); + + void delete(UserSetting userSetting); + +} diff --git a/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java index bf3f746..e61c413 100644 --- a/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java @@ -1,8 +1,11 @@ package com.randps.randomdefence.global.component.parser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.randps.randomdefence.domain.user.domain.UserSetting; +import com.randps.randomdefence.domain.user.service.UserSettingSearchService; import com.randps.randomdefence.global.component.crawler.BojWebCrawler; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Qualifier; @@ -15,6 +18,8 @@ @Qualifier("bojParserToUse") public class BojParserImpl implements Parser { + private final UserSettingSearchService userSettingSearchService; + private LocalDateTime startOfActiveDay; private final BojWebCrawler webCrawler; @@ -24,6 +29,11 @@ public class BojParserImpl implements Parser { */ @Override public List getSolvedProblemList(String bojHandle) throws JsonProcessingException { + UserSetting setting = userSettingSearchService.findByBojHandleSafe(bojHandle); + if (!setting.getScrapingOn()) { + return new ArrayList<>(); + } + List solvedProblems; UriComponents uri = UriComponentsBuilder.newInstance() .scheme("https").host("www.acmicpc.net").path("/status") diff --git a/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java index 42fa40e..e6923a8 100644 --- a/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java @@ -1,6 +1,8 @@ package com.randps.randomdefence.global.component.parser; import com.fasterxml.jackson.core.JsonProcessingException; +import com.randps.randomdefence.domain.user.domain.UserSetting; +import com.randps.randomdefence.domain.user.service.UserSettingSearchService; import com.randps.randomdefence.global.component.crawler.BojProfileWebCrawler; import java.time.LocalDateTime; import java.util.ArrayList; @@ -16,6 +18,8 @@ @Qualifier("bojProfileParserToUse") public class BojProfileParserImpl implements Parser { + private final UserSettingSearchService userSettingSearchService; + private LocalDateTime startOfActiveDay; private final BojProfileWebCrawler bojProfileWebCrawler; @@ -25,6 +29,11 @@ public class BojProfileParserImpl implements Parser { */ @Override public List getSolvedProblemList(String bojHandle) throws JsonProcessingException { + UserSetting setting = userSettingSearchService.findByBojHandleSafe(bojHandle); + if (!setting.getScrapingOn()) { + return new ArrayList<>(); + } + List solvedProblems = new ArrayList<>(); UriComponents uri = UriComponentsBuilder.newInstance() .scheme("https").host("www.acmicpc.net").path("/user").path("/" + bojHandle) diff --git a/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java index 80ab1cb..96ee482 100644 --- a/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.randps.randomdefence.domain.user.domain.UserSetting; +import com.randps.randomdefence.domain.user.service.UserSettingSearchService; import com.randps.randomdefence.global.component.crawler.SolvedacWebCrawler; import com.randps.randomdefence.global.component.parser.dto.UserScrapingInfoDto; import java.time.LocalDate; @@ -28,6 +30,8 @@ public class SolvedacParserImpl implements SolvedacParser { private final SolvedacWebCrawler webCrawler; + private final UserSettingSearchService userSettingSearchService; + @Override public List getSolvedProblemList(String userName) { return null; @@ -40,6 +44,11 @@ public void setStartOfActiveDay(LocalDateTime startOfActiveDay) { @Override public JsonNode crawlingUserInfo(String bojHandle) throws JsonProcessingException { + UserSetting setting = userSettingSearchService.findByBojHandleSafe(bojHandle); + if (!setting.getScrapingOn()) { + return null; + } + UriComponents uri = UriComponentsBuilder.newInstance() .scheme("https").host("solved.ac").path("/profile/" + bojHandle).build(); diff --git a/src/test/java/com/randps/randomdefence/domain/user/service/PrincipalDetailServiceTest.java b/src/test/java/com/randps/randomdefence/domain/user/service/PrincipalDetailServiceTest.java index 4c696eb..1d85b14 100644 --- a/src/test/java/com/randps/randomdefence/domain/user/service/PrincipalDetailServiceTest.java +++ b/src/test/java/com/randps/randomdefence/domain/user/service/PrincipalDetailServiceTest.java @@ -14,60 +14,61 @@ public class PrincipalDetailServiceTest { - private PrincipalDetailsService principalDetailsService; + private PrincipalDetailsService principalDetailsService; - @AfterEach - void tearDown() { - principalDetailsService = null; - } + @AfterEach + void tearDown() { + principalDetailsService = null; + } - @Test - @DisplayName("loadUserByUsername을 이용하여 bojHandle로 유저를 조회할 수 있다") - public void loadUserByUsernameTest() { - // given - UserRepository userRepository = new FakeUserRepository(); - this.principalDetailsService = new PrincipalDetailsService(userRepository); - User user = User.builder() - .id(1L) - .bojHandle("fin") - .password("q1w2e3r4!") - .roles("Admin") - .notionId("성민") - .manager(true) - .warning(1) - .profileImg("https://static.solved.ac/uploads/profile/64x64/fin-picture-1665752455693.png") - .emoji("🔥") - .tier(15) - .totalSolved(1067) - .currentStreak(252) - .currentRandomStreak(92) - .team(1) - .point(1234) - .isTodaySolved(true) - .isYesterdaySolved(true) - .isTodayRandomSolved(true) - .todaySolvedProblemCount(1) - .build(); - userRepository.save(user); + @Test + @DisplayName("loadUserByUsername을 이용하여 bojHandle로 유저를 조회할 수 있다") + public void loadUserByUsernameTest() { + // given + UserRepository userRepository = new FakeUserRepository(); + this.principalDetailsService = new PrincipalDetailsService(userRepository); + User user = User.builder() + .id(1L) + .bojHandle("fin") + .password("q1w2e3r4!") + .roles("Admin") + .notionId("성민") + .manager(true) + .warning(1) + .profileImg("https://static.solved.ac/uploads/profile/64x64/fin-picture-1665752455693.png") + .emoji("🔥") + .tier(15) + .totalSolved(1067) + .currentStreak(252) + .currentRandomStreak(92) + .team(1) + .point(1234) + .isTodaySolved(true) + .isYesterdaySolved(true) + .isTodayRandomSolved(true) + .todaySolvedProblemCount(1) + .build(); + userRepository.save(user); - // when - UserDetails result = principalDetailsService.loadUserByUsername("fin"); + // when + UserDetails result = principalDetailsService.loadUserByUsername("fin"); - // then - assertThat(result.getUsername()).isEqualTo("성민"); - assertThat(result.getPassword()).isEqualTo("q1w2e3r4!"); - assertThat(result.getAuthorities()).isNotNull(); - } + // then + assertThat(result.getUsername()).isEqualTo("성민"); + assertThat(result.getPassword()).isEqualTo("q1w2e3r4!"); + assertThat(result.getAuthorities()).isNotNull(); + } - @Test - @DisplayName("loadUserByUsername을 이용하여 bojHandle로 존재하지 않는 유저를 조회하면 에러를 던진다") - public void loadUserByUsernameExceptionTest() { - // given - UserRepository userRepository = new FakeUserRepository(); - this.principalDetailsService = new PrincipalDetailsService(userRepository); + @Test + @DisplayName("loadUserByUsername을 이용하여 bojHandle로 존재하지 않는 유저를 조회하면 에러를 던진다") + public void loadUserByUsernameExceptionTest() { + // given + UserRepository userRepository = new FakeUserRepository(); + this.principalDetailsService = new PrincipalDetailsService(userRepository); - // when & then - assertThatThrownBy(() -> principalDetailsService.loadUserByUsername("fin")).isInstanceOf(UsernameNotFoundException.class); - } + // when & then + assertThatThrownBy(() -> principalDetailsService.loadUserByUsername("fin")).isInstanceOf( + UsernameNotFoundException.class); + } } From f33b5b2df730b9b7568057ae1485a8547cf679da Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 17:05:15 +0900 Subject: [PATCH 04/14] =?UTF-8?q?[Feat]=20=EA=B2=BD=EA=B3=A0=20On/Off?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=A5=B8=20=EC=9D=BC=EA=B0=84=20=EA=B2=BD?= =?UTF-8?q?=EA=B3=A0=20=EB=B6=80=EC=97=AC=20=ED=8C=90=EB=B3=84=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserInfoService.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java index 34dd8e6..60ee257 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java @@ -6,6 +6,7 @@ import com.randps.randomdefence.domain.notify.enums.NotifyType; import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.domain.UserRandomStreak; +import com.randps.randomdefence.domain.user.domain.UserSetting; import com.randps.randomdefence.domain.user.dto.UserInfoResponse; import com.randps.randomdefence.domain.user.service.port.UserRepository; import com.randps.randomdefence.global.component.parser.Parser; @@ -36,6 +37,8 @@ public class UserInfoService { private final ApplicationContext applicationContext; + private final UserSettingSearchService userSettingSearchService; + @Qualifier("bojParserToUse") private final Parser bojParser; @@ -146,6 +149,11 @@ public void checkAllUserSolvedStreak() throws JsonProcessingException { List users = userRepository.findAll(); for (User user : users) { + UserSetting userSetting = userSettingSearchService.findByBojHandleSafe(user.getBojHandle()); + if (!userSetting.getWarningOn()) { + continue; + } + user.setScrapingUserInfo(solvedacParser.getSolvedUserInfo(user.getBojHandle())); user.setIsTodaySolved(userSolvedProblemService.isTodaySolved(user.getBojHandle())); user.setTodaySolvedProblemCount( From bb86440814f8c975ebcb9eb5b3a5cda3192e8128 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 17:21:59 +0900 Subject: [PATCH 05/14] =?UTF-8?q?[Chore]=20validation=20=EC=A2=85=EC=86=8D?= =?UTF-8?q?=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index c066acc..1f695be 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.boot:spring-boot-starter-aop' + implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'com.auth0:java-jwt:4.2.0' implementation 'org.jsoup:jsoup:1.15.3' implementation 'mysql:mysql-connector-java:8.0.32' From 1c6e8b18d7f52290a1da60e2c251554f533dc4b7 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 17:27:31 +0900 Subject: [PATCH 06/14] =?UTF-8?q?[Feat]=20User=20Setting=20=EA=B4=80?= =?UTF-8?q?=EB=A0=A8=20CRUD=20Api=20Endpoint=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserSettingSearchController.java | 31 +++++++++++++++++ .../UserSettingToggleController.java | 34 +++++++++++++++++++ .../domain/user/dto/UserSettingResponse.java | 25 ++++++++++++++ .../service/UserSettingSearchService.java | 21 ++++++++++++ .../global/config/SecurityConfig.java | 3 +- 5 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java create mode 100644 src/main/java/com/randps/randomdefence/domain/user/dto/UserSettingResponse.java diff --git a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java new file mode 100644 index 0000000..8d329f2 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java @@ -0,0 +1,31 @@ +package com.randps.randomdefence.domain.user.controller; + +import com.randps.randomdefence.domain.user.dto.UserSettingResponse; +import com.randps.randomdefence.domain.user.service.UserSettingSearchService; +import java.util.List; +import java.util.stream.Collectors; +import javax.validation.constraints.NotBlank; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/v1/user/setting") +public class UserSettingSearchController { + + private final UserSettingSearchService userSettingSearchService; + + @GetMapping("/all") + public List findAllSafe() { + return userSettingSearchService.findAllSafe().stream().map(UserSettingResponse::from).collect( + Collectors.toList()); + } + + @GetMapping + public UserSettingResponse findByBojHandleSafe(@NotBlank String bojHandle) { + return UserSettingResponse.from(userSettingSearchService.findByBojHandleSafe(bojHandle)); + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java new file mode 100644 index 0000000..ebea18a --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java @@ -0,0 +1,34 @@ +package com.randps.randomdefence.domain.user.controller; + +import static com.randps.randomdefence.global.component.util.ResponseUtil.toResponse; + +import com.randps.randomdefence.domain.user.service.UserSettingToggleService; +import java.util.Map; +import javax.validation.constraints.NotBlank; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RequiredArgsConstructor +@RestController +@RequestMapping("/api/v1/user/setting/toggle") +public class UserSettingToggleController { + + private final UserSettingToggleService userSettingToggleService; + + @PutMapping("/warning") + public ResponseEntity> toggleWarningSetting(@NotBlank String bojHandle) { + userSettingToggleService.toggleWarningSetting(bojHandle); + return toResponse(HttpStatus.OK, "200", "유저의 경고 설정을 성공적으로 변경했습니다."); + } + + @PutMapping("/warning") + public ResponseEntity> toggleScrapingSetting(@NotBlank String bojHandle) { + userSettingToggleService.toggleScrapingSetting(bojHandle); + return toResponse(HttpStatus.OK, "200", "유저의 크롤링 설정을 성공적으로 변경했습니다."); + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/dto/UserSettingResponse.java b/src/main/java/com/randps/randomdefence/domain/user/dto/UserSettingResponse.java new file mode 100644 index 0000000..9fffb50 --- /dev/null +++ b/src/main/java/com/randps/randomdefence/domain/user/dto/UserSettingResponse.java @@ -0,0 +1,25 @@ +package com.randps.randomdefence.domain.user.dto; + +import com.randps.randomdefence.domain.user.domain.UserSetting; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class UserSettingResponse { + + private String bojHandle; + + private boolean scrapingOn; + + private boolean warningOn; + + static public UserSettingResponse from(UserSetting userSetting) { + return UserSettingResponse.builder() + .bojHandle(userSetting.getBojHandle()) + .scrapingOn(userSetting.getScrapingOn()) + .warningOn(userSetting.getWarningOn()) + .build(); + } + +} diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java index a0e3d77..85560a9 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserSettingSearchService.java @@ -1,8 +1,11 @@ package com.randps.randomdefence.domain.user.service; +import com.randps.randomdefence.domain.user.domain.User; import com.randps.randomdefence.domain.user.domain.UserSetting; import com.randps.randomdefence.domain.user.service.port.UserRepository; import com.randps.randomdefence.domain.user.service.port.UserSettingRepository; +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -29,4 +32,22 @@ public UserSetting findByBojHandleSafe(String bojHandle) { }); } + public List findAllSafe() { + List users = userRepository.findAll(); + List userSettings = new ArrayList<>(); + + for (User user : users) { + userSettings.add(userSettingRepository.findByBojHandle(user.getBojHandle()) + .orElseGet(() -> { + UserSetting userSetting = UserSetting.builder() + .bojHandle(user.getBojHandle()) + .scrapingOn(true) + .warningOn(true) + .build(); + return userSettingRepository.save(userSetting); + })); + } + return userSettings; + } + } diff --git a/src/main/java/com/randps/randomdefence/global/config/SecurityConfig.java b/src/main/java/com/randps/randomdefence/global/config/SecurityConfig.java index c5f77c3..e3a30a3 100644 --- a/src/main/java/com/randps/randomdefence/global/config/SecurityConfig.java +++ b/src/main/java/com/randps/randomdefence/global/config/SecurityConfig.java @@ -56,7 +56,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/api/v1/user/admin/init", "/api/v1/recommend").permitAll() .antMatchers("/api/v1/user/sejong/register/**").permitAll() .antMatchers("/api/v1/user/add", "/api/v1/user/del", "/api/v1/scraping/*", - "api/v1/admin/*", "/api/v1/complaint/processor/*").hasRole("ADMIN") + "api/v1/admin/*", "/api/v1/complaint/processor/*", "/api/v1/user/setting/*") + .hasRole("ADMIN") .anyRequest().authenticated() .and() .cors().disable() From ca4e9308565ae748fa14f9aae732ab493e0b2cf6 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 18:25:56 +0900 Subject: [PATCH 07/14] =?UTF-8?q?[Feat]=20GlobalHandler=20logging=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/exception/randpsExceptionHandler.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/randps/randomdefence/global/exception/randpsExceptionHandler.java b/src/main/java/com/randps/randomdefence/global/exception/randpsExceptionHandler.java index 02e47a9..9e2c081 100644 --- a/src/main/java/com/randps/randomdefence/global/exception/randpsExceptionHandler.java +++ b/src/main/java/com/randps/randomdefence/global/exception/randpsExceptionHandler.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.Map; import javax.persistence.EntityExistsException; +import lombok.extern.slf4j.Slf4j; import org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -13,6 +14,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +@Slf4j @RestControllerAdvice public class randpsExceptionHandler { @@ -25,6 +27,7 @@ public ResponseEntity> ExceptionHandler(Exception e) { map.put("error type", httpStatus.getReasonPhrase()); map.put("code", "400"); map.put("message", e.getMessage()); + log.error("특정되지 않은 예외 발생 : " + e.getMessage()); return new ResponseEntity<>(map, responseHeaders, httpStatus); } @@ -115,6 +118,7 @@ public ResponseEntity> ExceptionHandler(JsonProcessingExcept map.put("error type", httpStatus.getReasonPhrase()); map.put("code", "500"); map.put("message", "크롤링 데이터의 HTML을 파싱하는데 실패했습니다."); + log.error("크롤링 데이터의 HTML을 파싱하는데 실패했습니다 : " + e.getMessage()); return new ResponseEntity<>(map, responseHeaders, httpStatus); } From 0cd008b0f8fbd669f0a974a0d677b9f5e00e9c20 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 18:43:27 +0900 Subject: [PATCH 08/14] =?UTF-8?q?[Fix]=20Scheduler=20cron=20=EC=8B=9D=20?= =?UTF-8?q?=EC=97=90=EB=9F=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/randps/randomdefence/global/scheduler/Scheduler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java index c48bdd4..7c8a9be 100644 --- a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java +++ b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java @@ -91,7 +91,7 @@ public void weekInitJob() { * 매 주, 주말에 경고 알림 발행 메서드 (매 주 토, 일요일 새벽 6시 30분) */ @Transactional - @Scheduled(cron = "0 30 6 ? * SAT,SUN *") + @Scheduled(cron = "0 30 6 * * SAT,SUN") public void weekendWarningJob() { autoNotifyService.weekendWarningNotify(); // 경고가 3회인 유저에게 경고 알림을 발행한다. } From ed7d08fbabb36b9c2a21431df84e5b067c33640e Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 18:45:44 +0900 Subject: [PATCH 09/14] =?UTF-8?q?[Fix]=20=EC=9E=98=EB=AA=BB=EB=90=9C=20API?= =?UTF-8?q?=20Endpoint=20=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/controller/UserSettingToggleController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java index ebea18a..b16727d 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java +++ b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java @@ -25,7 +25,7 @@ public ResponseEntity> toggleWarningSetting(@NotBlank String return toResponse(HttpStatus.OK, "200", "유저의 경고 설정을 성공적으로 변경했습니다."); } - @PutMapping("/warning") + @PutMapping("/scraping") public ResponseEntity> toggleScrapingSetting(@NotBlank String bojHandle) { userSettingToggleService.toggleScrapingSetting(bojHandle); return toResponse(HttpStatus.OK, "200", "유저의 크롤링 설정을 성공적으로 변경했습니다."); From 78838faad528c61f0868f971363a6377c7829824 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 18:49:28 +0900 Subject: [PATCH 10/14] [Fix] User Setting domain id bug fix --- .../randps/randomdefence/domain/user/domain/UserSetting.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java b/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java index fd73575..f4cb9ee 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java +++ b/src/main/java/com/randps/randomdefence/domain/user/domain/UserSetting.java @@ -3,6 +3,8 @@ import com.randps.randomdefence.global.auditing.BaseTimeEntity; import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import lombok.Builder; @@ -16,6 +18,7 @@ public class UserSetting extends BaseTimeEntity { @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String bojHandle; From 323962fd8c40fd41331f878dbc79bb99467eee37 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 19:01:06 +0900 Subject: [PATCH 11/14] =?UTF-8?q?[Feat]=20=EA=B2=BD=EA=B3=A0/=ED=81=AC?= =?UTF-8?q?=EB=A1=A4=EB=A7=81=20off=EA=B4=80=EB=A0=A8=20info=20logging=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../user/controller/UserSettingSearchController.java | 4 +++- .../user/controller/UserSettingToggleController.java | 7 +++++-- .../randomdefence/domain/user/service/UserInfoService.java | 3 +++ .../global/component/parser/BojParserImpl.java | 3 +++ .../global/component/parser/BojProfileParserImpl.java | 3 +++ .../global/component/parser/SolvedacParserImpl.java | 3 +++ 6 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java index 8d329f2..5b11994 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java +++ b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingSearchController.java @@ -8,6 +8,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @@ -24,7 +25,8 @@ public List findAllSafe() { } @GetMapping - public UserSettingResponse findByBojHandleSafe(@NotBlank String bojHandle) { + public UserSettingResponse findByBojHandleSafe( + @RequestParam("bojHandle") @NotBlank String bojHandle) { return UserSettingResponse.from(userSettingSearchService.findByBojHandleSafe(bojHandle)); } diff --git a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java index b16727d..5964a4e 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java +++ b/src/main/java/com/randps/randomdefence/domain/user/controller/UserSettingToggleController.java @@ -10,6 +10,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RequiredArgsConstructor @@ -20,13 +21,15 @@ public class UserSettingToggleController { private final UserSettingToggleService userSettingToggleService; @PutMapping("/warning") - public ResponseEntity> toggleWarningSetting(@NotBlank String bojHandle) { + public ResponseEntity> toggleWarningSetting( + @RequestParam("bojHandle") @NotBlank String bojHandle) { userSettingToggleService.toggleWarningSetting(bojHandle); return toResponse(HttpStatus.OK, "200", "유저의 경고 설정을 성공적으로 변경했습니다."); } @PutMapping("/scraping") - public ResponseEntity> toggleScrapingSetting(@NotBlank String bojHandle) { + public ResponseEntity> toggleScrapingSetting( + @RequestParam("bojHandle") @NotBlank String bojHandle) { userSettingToggleService.toggleScrapingSetting(bojHandle); return toResponse(HttpStatus.OK, "200", "유저의 크롤링 설정을 성공적으로 변경했습니다."); } diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java index 60ee257..3810cc4 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java @@ -16,10 +16,12 @@ import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; +@Slf4j @RequiredArgsConstructor @Builder @Service @@ -151,6 +153,7 @@ public void checkAllUserSolvedStreak() throws JsonProcessingException { for (User user : users) { UserSetting userSetting = userSettingSearchService.findByBojHandleSafe(user.getBojHandle()); if (!userSetting.getWarningOn()) { + log.info("Warning is off for user: {}", user.getBojHandle()); continue; } diff --git a/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java index e61c413..503349d 100644 --- a/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/parser/BojParserImpl.java @@ -8,11 +8,13 @@ import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; +@Slf4j @RequiredArgsConstructor @Component @Qualifier("bojParserToUse") @@ -31,6 +33,7 @@ public class BojParserImpl implements Parser { public List getSolvedProblemList(String bojHandle) throws JsonProcessingException { UserSetting setting = userSettingSearchService.findByBojHandleSafe(bojHandle); if (!setting.getScrapingOn()) { + log.info("Scraping is off for user: {}", bojHandle); return new ArrayList<>(); } diff --git a/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java index e6923a8..4beaa55 100644 --- a/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/parser/BojProfileParserImpl.java @@ -8,11 +8,13 @@ import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; +@Slf4j @RequiredArgsConstructor @Component @Qualifier("bojProfileParserToUse") @@ -31,6 +33,7 @@ public class BojProfileParserImpl implements Parser { public List getSolvedProblemList(String bojHandle) throws JsonProcessingException { UserSetting setting = userSettingSearchService.findByBojHandleSafe(bojHandle); if (!setting.getScrapingOn()) { + log.info("Scraping is off for user: {}", bojHandle); return new ArrayList<>(); } diff --git a/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java b/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java index 96ee482..a39eef7 100644 --- a/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java +++ b/src/main/java/com/randps/randomdefence/global/component/parser/SolvedacParserImpl.java @@ -12,11 +12,13 @@ import java.util.List; import lombok.Getter; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.jsoup.nodes.Element; import org.springframework.stereotype.Component; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; +@Slf4j @Getter @RequiredArgsConstructor @Component @@ -46,6 +48,7 @@ public void setStartOfActiveDay(LocalDateTime startOfActiveDay) { public JsonNode crawlingUserInfo(String bojHandle) throws JsonProcessingException { UserSetting setting = userSettingSearchService.findByBojHandleSafe(bojHandle); if (!setting.getScrapingOn()) { + log.info("Scraping is off for user: {}", bojHandle); return null; } From c1cf07bb9e06b9be89c7006fbe12fb2ecf4ba694 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 19:06:45 +0900 Subject: [PATCH 12/14] =?UTF-8?q?[Fix]=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EC=B2=AB=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EA=B0=80=20=EC=83=9D=EC=84=B1=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserInfoService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java index 3810cc4..60adbeb 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java @@ -120,7 +120,14 @@ public void crawlUserInfo(String bojHandle) throws JsonProcessingException { .orElseThrow(() -> new IllegalArgumentException("존재하지 않는 유저입니다.")); user.setScrapingUserInfo(solvedacParser.getSolvedUserInfo(user.getBojHandle())); - user.setIsTodaySolved(userSolvedProblemService.isTodaySolved(user.getBojHandle())); + // 오늘 문제 푼 것을 축하하는 알림을 발행한다. + Boolean isTodaySolved = userSolvedProblemService.isTodaySolved(user.getBojHandle()); + if (!user.getIsTodaySolved() && isTodaySolved) { + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), + "😊🥳 오늘도 문제를 해결하셨네요! 정말 정말 잘 했어요!", + NotifyType.SYSTEM, null)); + } + user.setIsTodaySolved(isTodaySolved); user.setTodaySolvedProblemCount( userSolvedProblemService.getTodaySolvedProblemCount(user.getBojHandle())); userRepository.save(user); From 1417f22bb78e109d4bfa6e8b79b3bda8870c002f Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 19:12:55 +0900 Subject: [PATCH 13/14] =?UTF-8?q?[Fix]=20=EC=98=A4=EB=8A=98=EC=9D=98=20?= =?UTF-8?q?=EC=B2=AB=20=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EA=B0=80=20=EC=83=9D=EC=84=B1=EB=90=98=EC=A7=80=20?= =?UTF-8?q?=EC=95=8A=EB=8A=94=20=EB=B2=84=EA=B7=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/user/service/UserInfoService.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java index 60adbeb..32619f9 100644 --- a/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java +++ b/src/main/java/com/randps/randomdefence/domain/user/service/UserInfoService.java @@ -142,7 +142,14 @@ public void crawlUserInfoAll() throws JsonProcessingException { for (User user : users) { user.setScrapingUserInfo(solvedacParser.getSolvedUserInfo(user.getBojHandle())); - user.setIsTodaySolved(userSolvedProblemService.isTodaySolved(user.getBojHandle())); + // 오늘 문제 푼 것을 축하하는 알림을 발행한다. + Boolean isTodaySolved = userSolvedProblemService.isTodaySolved(user.getBojHandle()); + if (!user.getIsTodaySolved() && isTodaySolved) { + applicationContext.publishEvent(new NotifyToUserBySystemEvent(this, user.getBojHandle(), + "😊🥳 오늘도 문제를 해결하셨네요! 정말 정말 잘 했어요!", + NotifyType.SYSTEM, null)); + } + user.setIsTodaySolved(isTodaySolved); user.setTodaySolvedProblemCount( userSolvedProblemService.getTodaySolvedProblemCount(user.getBojHandle())); userRepository.save(user); From 70fcf8d1e3a402feaee15e5c79d4064b6e3395b0 Mon Sep 17 00:00:00 2001 From: fing9 Date: Tue, 4 Jun 2024 19:18:58 +0900 Subject: [PATCH 14/14] =?UTF-8?q?[Feat]=20Scheduler=20logging=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/scheduler/Scheduler.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java index 7c8a9be..60c777e 100644 --- a/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java +++ b/src/main/java/com/randps/randomdefence/global/scheduler/Scheduler.java @@ -14,10 +14,12 @@ import javax.transaction.Transactional; import lombok.Builder; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.Scheduled; +@Slf4j @Builder @RequiredArgsConstructor @SpringBootApplication @@ -50,15 +52,27 @@ public class Scheduler { @Transactional @Scheduled(cron = "0 0/20 * * * *") public void everyTermJob() throws JsonProcessingException { + log.info("[Every Term Crawling Start]"); crawlingLock.lock(); // 크롤링 중복 방지를 위한 락 try { + log.info("모든 유저의 맞았습니다를 크롤링해서 해결한 문제 DB를 업데이트 한다."); userSolvedProblemService.crawlTodaySolvedProblemAll(); // 모든 유저의 맞았습니다를 크롤링해서 해결한 문제 DB를 업데이트한다. + log.info("[SUCCESS]"); + log.info("모든 유저의 프로필 정보를 크롤링해서 DB를 업데이트한다."); userInfoService.crawlUserInfoAll(); // 모든 유저의 프로필 정보를 크롤링해서 DB를 업데이트한다. + log.info("[SUCCESS]"); + log.info("모든 유저의 오늘의 추첨 랜덤 문제 풀었는지 여부를 체크하고 DB를 업데이트한다."); userRandomStreakService.solvedCheckAll(); // 모든 유저의 오늘의 추첨 랜덤 문제 풀었는지 여부를 체크하고 DB를 업데이트한다. + log.info("[SUCCESS]"); + log.info("모든 유저의 문제 풀었는지 여부를 체크해서 저장한다."); userInfoService.updateAllUserInfo(); // 모든 유저의 문제 풀었는지 여부를 체크해서 저장한다. + log.info("[SUCCESS]"); + log.info("게시글과 이어지지 않고 기준시간(6시간)이상 지난 모든 이미지를 삭제한다."); s3BatchService.deleteDetachedImages(); // 게시글과 이어지지 않고 기준시간(6시간)이상 지난 모든 이미지를 삭제한다. + log.info("[SUCCESS]"); } finally { crawlingLock.unlock(); // 크롤링 중복 방지를 위한 락 해제 + log.info("[Crawling Done]"); } } @@ -68,11 +82,23 @@ public void everyTermJob() throws JsonProcessingException { @Transactional @Scheduled(cron = "0 25 6 * * *") public void everyDayTermJob() throws JsonProcessingException { + log.info("[Every Day Term Start]"); + log.info("모든 유저의 오늘 잔디를 생성한다."); userGrassService.makeTodayGrassAll(); // 모든 유저의 오늘 잔디를 생성한다. + log.info("[SUCCESS]"); + log.info("모든 유저의 랜덤 문제를 1문제를 뽑아 저장한다."); userRandomStreakService.makeUpUserRandomProblemAll(); // 모든 유저의 랜덤 문제를 1문제를 뽑아 저장한다. + log.info("[SUCCESS]"); + log.info("모든 유저에 대해 유저의 전일 문제가 풀리지 않았다면 랜덤 스트릭을 끊는다."); userRandomStreakService.streakCheckAll(); // 모든 유저에 대해 유저의 전일 문제가 풀리지 않았다면 랜덤 스트릭을 끊는다. + log.info("[SUCCESS]"); + log.info("모든 유저에 대해 전 일 스트릭이 끊겼다면(랜덤 스트릭이 아닌 Solvedac 스트릭) 경고를 1회 올린다."); userInfoService.checkAllUserSolvedStreak(); // 모든 유저에 대해 전 일 스트릭이 끊겼다면(랜덤 스트릭이 아닌 Solvedac 스트릭) 경고를 1회 올린다. + log.info("[SUCCESS]"); + log.info("모든 유저의 일간 통계를 초기화한다."); userStatisticsService.initAllDailyStat(); // 모든 유저의 일간 통계를 초기화한다. + log.info("[SUCCESS]"); + log.info("[Done]"); } /* @@ -81,10 +107,20 @@ public void everyDayTermJob() throws JsonProcessingException { @Transactional @Scheduled(cron = "0 26 6 * * 1") public void weekInitJob() { + log.info("[Week Initialize Start]"); + log.info("모든 유저의 주간 통계를 초기화한다."); userStatisticsService.initAllWeeklyStat(); // 모든 유저의 주간 통계를 초기화한다. + log.info("[SUCCESS]"); + log.info("승리 팀에게 승리 포인트 지급"); teamService.weeklyTeamPointDistribution(); // 승리 팀에게 승리 포인트 지급 + log.info("[SUCCESS]"); + log.info("팀 포인트 주간 초기화"); teamSettingService.initWeekly(); // 팀 포인트 주간 초기화 + log.info("[SUCCESS]"); + log.info("모든 유저 팀 할당"); teamSettingService.setUsers(); // 모든 유저 팀 할당 + log.info("[SUCCESS]"); + log.info("[Done]"); } /* @@ -93,7 +129,11 @@ public void weekInitJob() { @Transactional @Scheduled(cron = "0 30 6 * * SAT,SUN") public void weekendWarningJob() { + log.info("[Weekend Warning Start]"); + log.info("경고가 3회인 유저에게 경고 알림을 발행한다."); autoNotifyService.weekendWarningNotify(); // 경고가 3회인 유저에게 경고 알림을 발행한다. + log.info("[SUCCESS]"); + log.info("[Done]"); } }