From ae4f79a8ab796e2ad7ec4829b3c7ac3198dab75a Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 13:22:11 +0900 Subject: [PATCH 01/12] =?UTF-8?q?:recycle:=20refactor:=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=20=ED=81=B4=EB=9E=98=EC=8A=A4,=20enum=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 시간 설정 수정 --- .../foreggserver/domain/Notification.java | 31 ------------------- .../foreggserver/domain/enums/NotifType.java | 7 ----- 2 files changed, 38 deletions(-) delete mode 100644 src/main/java/foregg/foreggserver/domain/Notification.java delete mode 100644 src/main/java/foregg/foreggserver/domain/enums/NotifType.java diff --git a/src/main/java/foregg/foreggserver/domain/Notification.java b/src/main/java/foregg/foreggserver/domain/Notification.java deleted file mode 100644 index 89f6aaf..0000000 --- a/src/main/java/foregg/foreggserver/domain/Notification.java +++ /dev/null @@ -1,31 +0,0 @@ -package foregg.foreggserver.domain; - -import foregg.foreggserver.domain.common.BaseEntity; -import foregg.foreggserver.domain.enums.NotifType; -import jakarta.persistence.*; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -@Entity -@Getter -@AllArgsConstructor -@NoArgsConstructor -@Builder -public class Notification extends BaseEntity { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private Long id; - - @Enumerated(EnumType.STRING) - private NotifType notificationType; - - @Column(nullable = false) - private String content; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "user_id") - private User user; -} diff --git a/src/main/java/foregg/foreggserver/domain/enums/NotifType.java b/src/main/java/foregg/foreggserver/domain/enums/NotifType.java deleted file mode 100644 index d81e8ac..0000000 --- a/src/main/java/foregg/foreggserver/domain/enums/NotifType.java +++ /dev/null @@ -1,7 +0,0 @@ -package foregg.foreggserver.domain.enums; - -public enum NotifType { - NOTIF_A, - NOTIF_B, - NOTIF_C -} From dcac5889a9c84f306d063636ed14cac3f11b31b3 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 13:22:50 +0900 Subject: [PATCH 02/12] =?UTF-8?q?:recycle:=20refactor:=20vibration=20null?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vibration null 처리 --- .../foregg/foreggserver/service/fcmService/FcmService.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java b/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java index 78230cf..e5f6811 100644 --- a/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java +++ b/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java @@ -68,6 +68,10 @@ private String getAccessToken() throws IOException { private String makeMessage(String fcmToken, String title, String body, String type, String targetId, String time, Boolean vibration) throws JsonProcessingException { ObjectMapper om = new ObjectMapper(); + Boolean vib = null; + if (vibration != null) { + vib = vibration; + } FcmMessageDTO fcmMessageDto = FcmMessageDTO.builder() .message(FcmMessageDTO.Message.builder() .token(fcmToken) @@ -77,7 +81,7 @@ private String makeMessage(String fcmToken, String title, String body, String ty .type(type) .targetId(targetId) .time(time) - .vibration(vibration.toString()) + .vibration(vib.toString()) .build() ) .android(FcmMessageDTO.Android.builder() From 434473eac2aa152e0282d2b3f395e331967b40a7 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:42:23 +0900 Subject: [PATCH 03/12] =?UTF-8?q?:recycle:=20refactor:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=B0=8C=EB=A5=B4=EA=B8=B0=20API=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 챌린지 찌르기 리스트, 챌린지 찌르기 API 생성 --- .../controller/ChallengeController.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/main/java/foregg/foreggserver/controller/ChallengeController.java b/src/main/java/foregg/foreggserver/controller/ChallengeController.java index 6574e45..5ab3777 100644 --- a/src/main/java/foregg/foreggserver/controller/ChallengeController.java +++ b/src/main/java/foregg/foreggserver/controller/ChallengeController.java @@ -1,10 +1,12 @@ package foregg.foreggserver.controller; import foregg.foreggserver.apiPayload.ApiResponse; +import foregg.foreggserver.domain.enums.NotificationType; import foregg.foreggserver.domain.enums.ChallengeSuccessDayType; import foregg.foreggserver.dto.challengeDTO.ChallengeRequestDTO.ChallengeCreateRequestDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeRequestDTO.ChallengeNameRequestDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO; +import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeCheerResponseDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.MyChallengeDTO; import foregg.foreggserver.service.challengeService.ChallengeQueryService; import foregg.foreggserver.service.challengeService.ChallengeService; @@ -179,4 +181,34 @@ public ApiResponse getChallengeName() { return ApiResponse.onSuccess(userQueryService.getChallengeName()); } + @Operation(summary = "챌린지 찌르기 리스트") + @GetMapping("{id}/participantsList") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4002", description = "존재하지 않는 챌린지입니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4003", description = "참여히고 있는 챌린지가 아닙니다") + }) + public ApiResponse> getParticipantsList(@PathVariable(name = "id") Long id) { + List result = challengeQueryService.getParticipantsList(id); + return ApiResponse.onSuccess(result); + } + + @Operation(summary = "챌린지 찌르기") + @PostMapping("{challengeId}") + @ApiResponses({ + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "COMMON200", description = "OK, 성공"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4002", description = "존재하지 않는 챌린지입니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4003", description = "참여하고 있는 챌린지가 아닙니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4013", description = "응원과 박수는 각각 하루에 세 번까지 가능합니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4014", description = "이미 오늘 찌르기를 한 유저입니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4015", description = "성공하지 않은 유저에게는 박수를 보낼 수 없습니다"), + @io.swagger.v3.oas.annotations.responses.ApiResponse(responseCode = "CHALLENGE4016", description = "성공한 유저에게는 응원을 보낼 수 없습니다"), + }) + public ApiResponse cheer(@PathVariable(name = "challengeId") Long challengeId, + @RequestParam(name = "cheerType") NotificationType cheerType, + @RequestParam(name = "receiverId") Long receiverId) { + challengeService.cheer(receiverId, cheerType, challengeId); + return ApiResponse.onSuccess(); + } + } From 2b146f3238d52ee101c4eb0f0ff38c172a0bedda Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:42:56 +0900 Subject: [PATCH 04/12] =?UTF-8?q?:recycle:=20refactor:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=B0=8C=EB=A5=B4=EA=B8=B0=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 챌린지 찌르기 리스트 서비스 로직 생성 --- .../ChallengeQueryService.java | 62 ++++++++++++++++++- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java index 1fbc0e9..4cf6c61 100644 --- a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java +++ b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeQueryService.java @@ -4,12 +4,15 @@ import foregg.foreggserver.converter.ChallengeConverter; import foregg.foreggserver.domain.Challenge; import foregg.foreggserver.domain.ChallengeParticipation; +import foregg.foreggserver.domain.Notification; import foregg.foreggserver.domain.User; -import foregg.foreggserver.dto.challengeDTO.ChallengeMyResponseDTO; +import foregg.foreggserver.domain.enums.NotificationType; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO; +import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeCheerResponseDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.ChallengeDTO; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.MyChallengeDTO; import foregg.foreggserver.jwt.SecurityUtil; +import foregg.foreggserver.repository.NotificationRepository; import foregg.foreggserver.repository.ChallengeParticipationRespository; import foregg.foreggserver.repository.ChallengeRepository; import foregg.foreggserver.service.userService.UserQueryService; @@ -23,8 +26,7 @@ import java.util.*; import java.util.stream.Collectors; -import static foregg.foreggserver.apiPayload.code.status.ErrorStatus.MAKE_NICKNAME_FIRST; -import static foregg.foreggserver.apiPayload.code.status.ErrorStatus.NOT_FOUND_MY_CHALLENGE; +import static foregg.foreggserver.apiPayload.code.status.ErrorStatus.*; @Transactional(readOnly = true) @Service @@ -35,6 +37,7 @@ public class ChallengeQueryService { private final ChallengeRepository challengeRepository; private final ChallengeParticipationRespository challengeParticipationRespository; private final UserQueryService userQueryService; + private final NotificationRepository notificationRepository; public ChallengeResponseDTO challengeMain() { User user = userQueryService.getUser(SecurityUtil.getCurrentUser()); @@ -76,6 +79,59 @@ public List getMyChallenges() { return result; } + public List getParticipantsList(Long id) { + User currentUser = userQueryService.getUser(SecurityUtil.getCurrentUser()); + Challenge challenge = challengeRepository.findById(id) + .orElseThrow(() -> new ChallengeHandler(CHALLENGE_NOT_FOUND)); + + ChallengeParticipation challengeParticipation = challengeParticipationRespository.findByUserAndChallenge(currentUser, challenge) + .orElseThrow(() -> new ChallengeHandler(NO_PARTICIPATING_CHALLENGE)); + + if (!challengeParticipation.isParticipating()) { + throw new ChallengeHandler(NO_PARTICIPATING_CHALLENGE); + } + + String today = LocalDate.now().toString(); + List challengeParticipations = challengeParticipationRespository.findByChallenge(challenge) + .orElseThrow(()-> new ChallengeHandler(CHALLENGE_NOT_FOUND)); + + // 자신을 제외한 참여자 리스트 + challengeParticipations.removeIf(cp -> cp.getUser().equals(currentUser)); + if (challengeParticipations.isEmpty()) { + return null; + } + + return challengeParticipations.stream() + .map(cp -> createChallengeCheerResponseDTO(currentUser, cp, today)) + .collect(Collectors.toList()); + } + + private ChallengeCheerResponseDTO createChallengeCheerResponseDTO(User sender, ChallengeParticipation cp, String today) { + boolean success = cp.getSuccessDays().contains(DateUtil.getTodayDayOfWeek()); + boolean clap = false; + boolean support = false; + List notifications = notificationRepository.findBySenderAndReceiverAndDate(sender, cp.getUser(), today); + + for (Notification notification : notifications) { + if (notification.getNotificationType().equals(NotificationType.CLAP)) { + clap = true; + } + if (notification.getNotificationType().equals(NotificationType.SUPPORT)) { + support = true; + } + } + + return ChallengeCheerResponseDTO.builder() + .id(cp.getUser().getId()) + .challengeNickname(cp.getUser().getChallengeName()) + .thought(cp.getThoughts()) + .success(success) + .clap(clap) + .support(support) + .build(); + } + + //챌린지 검색 메서드 public ChallengeResponseDTO searchChallenge(String keyword) { User user = userQueryService.getUser(SecurityUtil.getCurrentUser()); From 4be9f601b5645ac74c85c367be3947ecc0f53978 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:44:05 +0900 Subject: [PATCH 05/12] =?UTF-8?q?:recycle:=20refactor:=20ChallengeCheerRes?= =?UTF-8?q?ponseDTO=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ChallengeCheerResponseDTO 생성 --- .../dto/challengeDTO/ChallengeResponseDTO.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java b/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java index e9afdc9..6cba809 100644 --- a/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java +++ b/src/main/java/foregg/foreggserver/dto/challengeDTO/ChallengeResponseDTO.java @@ -39,4 +39,17 @@ public static class MyChallengeDTO { private List successDays; } + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class ChallengeCheerResponseDTO { + private Long id; + private String challengeNickname; + private String thought; + private boolean success; + private boolean clap; + private boolean support; + } + } From 4d2634e2a1e178dac167e84eedb33a3224c3291f Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:44:52 +0900 Subject: [PATCH 06/12] =?UTF-8?q?:recycle:=20refactor:=20=EC=B1=8C?= =?UTF-8?q?=EB=A6=B0=EC=A7=80=20=EC=B0=8C=EB=A5=B4=EA=B8=B0=20=EC=84=9C?= =?UTF-8?q?=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 챌린지 찌르기 서비스 로직 생성 --- .../challengeService/ChallengeService.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java index bb61b15..1d6432a 100644 --- a/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java +++ b/src/main/java/foregg/foreggserver/service/challengeService/ChallengeService.java @@ -1,15 +1,20 @@ package foregg.foreggserver.service.challengeService; import foregg.foreggserver.apiPayload.exception.handler.ChallengeHandler; +import foregg.foreggserver.apiPayload.exception.handler.UserHandler; import foregg.foreggserver.converter.ChallengeConverter; import foregg.foreggserver.domain.Challenge; import foregg.foreggserver.domain.ChallengeParticipation; +import foregg.foreggserver.domain.Notification; import foregg.foreggserver.domain.User; +import foregg.foreggserver.domain.enums.NotificationType; import foregg.foreggserver.dto.challengeDTO.ChallengeResponseDTO.MyChallengeDTO; import foregg.foreggserver.jwt.SecurityUtil; import foregg.foreggserver.repository.ChallengeParticipationRespository; import foregg.foreggserver.repository.ChallengeRepository; +import foregg.foreggserver.repository.NotificationRepository; import foregg.foreggserver.repository.UserRepository; +import foregg.foreggserver.service.notificationService.NotificationService; import foregg.foreggserver.service.userService.UserQueryService; import foregg.foreggserver.util.DateUtil; import lombok.RequiredArgsConstructor; @@ -36,6 +41,8 @@ public class ChallengeService { private final UserQueryService userQueryService; private final UserRepository userRepository; private final ChallengeQueryService challengeQueryService; + private final NotificationService notificationService; + private final NotificationRepository notificationRepository; public void participate(Long id) { User user = userQueryService.getUser(SecurityUtil.getCurrentUser()); @@ -154,4 +161,43 @@ public void initSuccessDays() { } challengeParticipationRepository.saveAll(challengeParticipations); // 변경 사항 저장 } + + public void cheer(Long id, NotificationType type, Long challengeId) { + User receiver = userRepository.findById(id).orElseThrow(() -> new UserHandler(USER_NOT_FOUND)); + User sender = userQueryService.getUser(SecurityUtil.getCurrentUser()); + Challenge challenge = challengeRepository.findById(challengeId).orElseThrow(() -> new ChallengeHandler(CHALLENGE_NOT_FOUND)); + + ChallengeParticipation cp = challengeParticipationRepository.findByUserAndChallenge(sender, challenge).orElseThrow(() -> new ChallengeHandler(NO_PARTICIPATING_CHALLENGE)); + if (!cp.isParticipating()) { + throw new ChallengeHandler(NO_PARTICIPATING_CHALLENGE); + } + ChallengeParticipation challengeParticipation = challengeParticipationRepository.findByUserAndChallenge(receiver, challenge).orElseThrow(() -> new ChallengeHandler(NO_PARTICIPATING_CHALLENGE)); + if (!challengeParticipation.isParticipating()) { + throw new ChallengeHandler(NO_PARTICIPATING_CHALLENGE); + } + + catchCheerException(challengeParticipation, type); + + List notificationList = notificationRepository.findBySenderAndDateAndNotificationType(sender, LocalDate.now().toString(), type); + if (notificationList.size() >= 3) { + throw new ChallengeHandler(NO_MORE_THAN_THIRD_TIME); + } + + if (notificationRepository.findBySenderAndReceiverAndDateAndNotificationType(sender, receiver, LocalDate.now().toString(), type) != null) { + throw new ChallengeHandler(ALREADY_SEND_CHEER); + } + + Notification notification = notificationService.createNotification(type, receiver, sender); + notificationRepository.save(notification); + } + + private void catchCheerException(ChallengeParticipation challengeParticipation, NotificationType notificationType) { + if (challengeParticipation.getSuccessDays().contains(DateUtil.getTodayDayOfWeek()) && notificationType.equals(NotificationType.SUPPORT)) { + throw new ChallengeHandler(UNABLE_TO_SEND_SUPPORT); + } + + if (!challengeParticipation.getSuccessDays().contains(DateUtil.getTodayDayOfWeek()) && notificationType.equals(NotificationType.CLAP)) { + throw new ChallengeHandler(UNABLE_TO_SEND_CLAP); + } + } } From 568d65dbeb4ba96658b790109cfd866d5dc9fa8a Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:45:26 +0900 Subject: [PATCH 07/12] =?UTF-8?q?:recycle:=20refactor:=20DateUtil=20?= =?UTF-8?q?=EB=A9=94=EC=84=9C=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DateUtil 메서드 수정 --- src/main/java/foregg/foreggserver/util/DateUtil.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/foregg/foreggserver/util/DateUtil.java b/src/main/java/foregg/foreggserver/util/DateUtil.java index 4eed6d1..423c4d5 100644 --- a/src/main/java/foregg/foreggserver/util/DateUtil.java +++ b/src/main/java/foregg/foreggserver/util/DateUtil.java @@ -257,10 +257,10 @@ public static LocalDate toLocalDate(String dateString) { } public static String getDayOfWeekFromString(String dateTimeString) { - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - LocalDateTime localDateTime = LocalDateTime.parse(dateTimeString, formatter); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + LocalDate localDate = LocalDate.parse(dateTimeString, formatter); // 만약 날짜 부분만 필요하다면 localDateTime.toLocalDate()를 사용 - return localDateTime.getDayOfWeek().toString(); + return localDate.getDayOfWeek().toString(); } public static String convertToMonthDay(String dateTimeStr) { @@ -281,5 +281,4 @@ public static String getYesterdayDayOfWeek() { return dayOfWeek.getDisplayName(TextStyle.SHORT, Locale.ENGLISH); } - } From d5b27b9130ce237944703e2cbc4d284b6e3459e0 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:46:16 +0900 Subject: [PATCH 08/12] =?UTF-8?q?:recycle:=20refactor:=20=EC=97=90?= =?UTF-8?q?=EB=9F=AC=20=EC=83=81=ED=83=9C=20=EC=BD=94=EB=93=9C=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 에러 상태 코드 추가 --- .../foreggserver/apiPayload/code/status/ErrorStatus.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java b/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java index 4b6e820..3d3cb9e 100644 --- a/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java +++ b/src/main/java/foregg/foreggserver/apiPayload/code/status/ErrorStatus.java @@ -50,7 +50,7 @@ public enum ErrorStatus implements BaseErrorCode { //챌린지 관련 에러 - CHALLENGE_NOT_FOUND(BAD_REQUEST, "CHALLENGE4001", "존재하지 않는 챌린지입니다"), + CHALLENGE_NOT_FOUND(BAD_REQUEST, "CHALLENGE4002", "존재하지 않는 챌린지입니다"), NOT_FOUND_MY_CHALLENGE(BAD_REQUEST, "CHALLENGE4002", "나의 챌린지가 존재하지 않습니다"), NO_PARTICIPATING_CHALLENGE(BAD_REQUEST, "CHALLENGE4003", "참여하고 있는 챌린지가 아닙니다"), ALREADY_PARTICIPATING(BAD_REQUEST, "CHALLENGE4004", "이미 참여하고 있는 챌린지입니다"), @@ -62,6 +62,10 @@ public enum ErrorStatus implements BaseErrorCode { ALREADY_OPEN(BAD_REQUEST, "CHALLENGE4010", "이미 오픈된 챌린지입니다"), MAKE_NICKNAME_FIRST(BAD_REQUEST, "CHALLENGE4011", "챌린지 닉네임을 먼저 만들어주세요"), OUT_OF_VALIDATE_DAYS(BAD_REQUEST, "CHALLENGE4012", "오늘, 어제 날짜 이외에는 챌린지 성공 할 수 없습니다"), + NO_MORE_THAN_THIRD_TIME(BAD_REQUEST, "CHALLENGE4013", "응원과 박수는 각각 하루에 세 번까지 가능합니다"), + ALREADY_SEND_CHEER(BAD_REQUEST, "CHALLENGE4014", "이미 오늘 찌르기를 한 유저입니다"), + UNABLE_TO_SEND_CLAP(BAD_REQUEST, "CHALLENGE4015", "성공하지 않은 유저에게는 박수를 보낼 수 없습니다"), + UNABLE_TO_SEND_SUPPORT(BAD_REQUEST, "CHALLENGE4016", "성공한 유저에게는 응원을 보낼 수 없습니다"), //가계부 관련 에러 From d8870f010a23946888a373e0570af59df1301398 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:46:41 +0900 Subject: [PATCH 09/12] =?UTF-8?q?:recycle:=20refactor:=20vibration=20null?= =?UTF-8?q?=20=EC=97=90=EB=9F=AC=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit vibration null 에러 처리 --- .../foregg/foreggserver/service/fcmService/FcmService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java b/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java index e5f6811..143d7b4 100644 --- a/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java +++ b/src/main/java/foregg/foreggserver/service/fcmService/FcmService.java @@ -68,9 +68,9 @@ private String getAccessToken() throws IOException { private String makeMessage(String fcmToken, String title, String body, String type, String targetId, String time, Boolean vibration) throws JsonProcessingException { ObjectMapper om = new ObjectMapper(); - Boolean vib = null; + String vib = null; if (vibration != null) { - vib = vibration; + vib = vibration.toString(); } FcmMessageDTO fcmMessageDto = FcmMessageDTO.builder() .message(FcmMessageDTO.Message.builder() @@ -81,7 +81,7 @@ private String makeMessage(String fcmToken, String title, String body, String ty .type(type) .targetId(targetId) .time(time) - .vibration(vib.toString()) + .vibration(vib) .build() ) .android(FcmMessageDTO.Android.builder() From 5f178b6f9dbd099f711c00a1429fede24ce68e45 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:47:36 +0900 Subject: [PATCH 10/12] =?UTF-8?q?:recycle:=20refactor:=20=EC=95=8C?= =?UTF-8?q?=EB=A6=BC=20=EB=A7=8C=EB=93=9C=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 알림 만드는 로직 생성 --- .../notificationService/NotificationService.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java b/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java index c388ad2..0c3f055 100644 --- a/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java +++ b/src/main/java/foregg/foreggserver/service/notificationService/NotificationService.java @@ -1,8 +1,10 @@ package foregg.foreggserver.service.notificationService; +import foregg.foreggserver.domain.Notification; import foregg.foreggserver.domain.Record; import foregg.foreggserver.domain.RepeatTime; import foregg.foreggserver.domain.User; +import foregg.foreggserver.domain.enums.NotificationType; import foregg.foreggserver.repository.UserRepository; import foregg.foreggserver.service.fcmService.FcmService; import lombok.RequiredArgsConstructor; @@ -179,6 +181,14 @@ public void cancelScheduledTasks(Long recordId) { } } - + //알림 만드는 로직 + public Notification createNotification(NotificationType notificationType, User receiver, User sender) { + return Notification.builder() + .notificationType(notificationType) + .receiver(receiver) + .sender(sender) + .date(LocalDate.now().toString()) + .build(); + } } From b1b0ba3371efa0bc6da2f2efd1530ce983a18b1f Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:48:08 +0900 Subject: [PATCH 11/12] =?UTF-8?q?:recycle:=20refactor:=20User=20=EC=97=B0?= =?UTF-8?q?=EA=B4=80=EA=B4=80=EA=B3=84=20=EC=97=90=EB=9F=AC=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit User 연관관계 에러 수정 --- src/main/java/foregg/foreggserver/domain/User.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/foregg/foreggserver/domain/User.java b/src/main/java/foregg/foreggserver/domain/User.java index 9856396..e89bb5d 100644 --- a/src/main/java/foregg/foreggserver/domain/User.java +++ b/src/main/java/foregg/foreggserver/domain/User.java @@ -62,7 +62,7 @@ public class User extends BaseEntity implements UserDetails { @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) private List schedules; - @OneToMany(mappedBy = "user", cascade = CascadeType.ALL) + @OneToMany(mappedBy = "receiver", cascade = CascadeType.ALL, orphanRemoval = true) private List notifications; @OneToMany(mappedBy = "user", cascade = CascadeType.ALL, orphanRemoval = true) From 96b731a24ddceb76ece74a1cbded2d364daa5ed7 Mon Sep 17 00:00:00 2001 From: kimdongjun Date: Wed, 20 Nov 2024 16:48:49 +0900 Subject: [PATCH 12/12] =?UTF-8?q?:sparkles:=20feat:=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=ED=81=B4=EB=9E=98=EC=8A=A4=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 알림 관련 클래스 생성 --- .../foreggserver/domain/Notification.java | 37 +++++++++++++++++++ .../domain/enums/NotificationType.java | 5 +++ .../repository/NotificationRepository.java | 17 +++++++++ 3 files changed, 59 insertions(+) create mode 100644 src/main/java/foregg/foreggserver/domain/Notification.java create mode 100644 src/main/java/foregg/foreggserver/domain/enums/NotificationType.java create mode 100644 src/main/java/foregg/foreggserver/repository/NotificationRepository.java diff --git a/src/main/java/foregg/foreggserver/domain/Notification.java b/src/main/java/foregg/foreggserver/domain/Notification.java new file mode 100644 index 0000000..7d9a763 --- /dev/null +++ b/src/main/java/foregg/foreggserver/domain/Notification.java @@ -0,0 +1,37 @@ +package foregg.foreggserver.domain; + +import foregg.foreggserver.domain.common.BaseEntity; +import foregg.foreggserver.domain.enums.NotificationType; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Getter +public class Notification extends BaseEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "sender_id") + private User sender; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "receiver_id") + private User receiver; + + @Column(nullable = false) + private String date; // String -> LocalDateTime으로 변경 + + @Enumerated(EnumType.STRING) + private NotificationType notificationType; + +} + diff --git a/src/main/java/foregg/foreggserver/domain/enums/NotificationType.java b/src/main/java/foregg/foreggserver/domain/enums/NotificationType.java new file mode 100644 index 0000000..6913326 --- /dev/null +++ b/src/main/java/foregg/foreggserver/domain/enums/NotificationType.java @@ -0,0 +1,5 @@ +package foregg.foreggserver.domain.enums; + +public enum NotificationType { + CLAP, SUPPORT, REPLY +} diff --git a/src/main/java/foregg/foreggserver/repository/NotificationRepository.java b/src/main/java/foregg/foreggserver/repository/NotificationRepository.java new file mode 100644 index 0000000..824ceaa --- /dev/null +++ b/src/main/java/foregg/foreggserver/repository/NotificationRepository.java @@ -0,0 +1,17 @@ +package foregg.foreggserver.repository; + +import foregg.foreggserver.domain.Notification; +import foregg.foreggserver.domain.User; +import foregg.foreggserver.domain.enums.NotificationType; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.List; + +public interface NotificationRepository extends JpaRepository { + + List findBySenderAndReceiverAndDate(User sender, User receiver, String date); + + Notification findBySenderAndReceiverAndDateAndNotificationType(User sender, User receiver, String date, NotificationType notificationType); + + List findBySenderAndDateAndNotificationType(User sender, String date, NotificationType notificationType); +}