-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #204 from TEAM-SAMSION/main
release : 1.2.0 배포
- Loading branch information
Showing
27 changed files
with
270 additions
and
96 deletions.
There are no files selected for viewing
28 changes: 12 additions & 16 deletions
28
Alarm-Module/src/main/java/com/pawith/alarmmodule/exception/AlarmError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
package com.pawith.alarmmodule.exception; | ||
|
||
import com.pawith.commonmodule.exception.Error; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.HttpStatusCode; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@RequiredArgsConstructor | ||
public enum AlarmError implements Error { | ||
DEVICE_TOKEN_NOT_FOUND("FCM 디바이스 토큰이 없습니다.", 5000), | ||
FCM_SEND_ERROR("FCM 전송에 실패하였습니다.", 5001),; | ||
DEVICE_TOKEN_NOT_FOUND("FCM 디바이스 토큰이 없습니다.", 5000, HttpStatus.NOT_FOUND), | ||
FCM_SEND_ERROR("FCM 전송에 실패하였습니다.", 5001, HttpStatus.INTERNAL_SERVER_ERROR), | ||
; | ||
|
||
private String message; | ||
private Integer errorCode; | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
@Override | ||
public int getErrorCode() { | ||
return errorCode; | ||
} | ||
private final String message; | ||
private final int errorCode; | ||
private final HttpStatusCode httpStatusCode; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
Common-Module/src/main/java/com/pawith/commonmodule/exception/Error.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package com.pawith.commonmodule.exception; | ||
|
||
import org.springframework.http.HttpStatusCode; | ||
|
||
|
||
public interface Error { | ||
String getMessage(); | ||
int getErrorCode(); | ||
|
||
HttpStatusCode getHttpStatusCode(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../Todo-Application/src/main/java/com/pawith/todoapplication/handler/TodoRemindHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.pawith.todoapplication.handler; | ||
|
||
import com.pawith.commonmodule.cache.CacheTemplate; | ||
import com.pawith.commonmodule.event.MultiNotificationEvent; | ||
import com.pawith.commonmodule.event.NotificationEvent; | ||
import com.pawith.todoapplication.handler.event.TodoAssignStatusChangeEvent; | ||
import com.pawith.tododomain.entity.CompletionStatus; | ||
import com.pawith.tododomain.repository.dao.IncompleteAssignInfoDao; | ||
import com.pawith.tododomain.service.AssignQueryService; | ||
import com.pawith.userdomain.entity.User; | ||
import com.pawith.userdomain.service.UserQueryService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.ApplicationEventPublisher; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class TodoRemindHandler { | ||
private static final String NOTIFICATION_MESSAGE = "'%s'을 %d명이 완료했어요! %s님도 얼른 완료해볼까요?"; | ||
private static final String REMIND_CACHE_KEY = "Remind:%s"; | ||
|
||
private final AssignQueryService assignQueryService; | ||
private final UserQueryService userQueryService; | ||
private final CacheTemplate<String, String> cacheTemplate; | ||
private final ApplicationEventPublisher applicationEventPublisher; | ||
|
||
@EventListener | ||
public void remindTodo(final TodoAssignStatusChangeEvent todoAssignStatusChangeEvent){ | ||
final Long todoId = todoAssignStatusChangeEvent.todoId(); | ||
final String cacheKey = String.format(REMIND_CACHE_KEY, todoId); | ||
final long completeAssignNumber = assignQueryService.countAssignByTodoIdAndCompleteStatus(todoId, CompletionStatus.COMPLETE); | ||
if(isRemindable(todoId, completeAssignNumber)&& !cacheTemplate.opsForSet().contains(cacheKey)){ | ||
cacheTemplate.opsForSet().addWithExpireAfterToday(cacheKey); | ||
final List<NotificationEvent> todoNotificationList = buildNotificationEvent(todoId, completeAssignNumber); | ||
applicationEventPublisher.publishEvent(new MultiNotificationEvent(todoNotificationList)); | ||
} | ||
} | ||
|
||
private List<NotificationEvent> buildNotificationEvent(final Long todoId, final long completeAssignNumber) { | ||
final List<IncompleteAssignInfoDao> incompleteAssignInfoDaoList = assignQueryService.findAllIncompleteAssignInfoByTodoId(todoId); | ||
final List<Long> incompleteTodoUserIds = incompleteAssignInfoDaoList.stream() | ||
.map(IncompleteAssignInfoDao::getUserId) | ||
.toList(); | ||
final Map<Long, User> incompleteTodoUserMap = userQueryService.findMapWithUserIdKeyByIds(incompleteTodoUserIds); | ||
return incompleteAssignInfoDaoList.stream() | ||
.map(incompleteAssignInfo -> { | ||
final User incompleteTodoUser = incompleteTodoUserMap.get(incompleteAssignInfo.getUserId()); | ||
final String notificationMessage = String.format(NOTIFICATION_MESSAGE, incompleteAssignInfo.getTodoDescription(), completeAssignNumber, incompleteTodoUser.getNickname()); | ||
return new NotificationEvent(incompleteTodoUser.getId(),incompleteAssignInfo.getTodoTeamName(), notificationMessage, todoId); | ||
}) | ||
.toList(); | ||
} | ||
|
||
private boolean isRemindable(final Long todoId, final long completeAssignNumber){ | ||
final long totalAssignNumber = assignQueryService.countAssignByTodoId(todoId); | ||
return (float) completeAssignNumber >= (float) totalAssignNumber * 0.5; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...n/src/main/java/com/pawith/todoapplication/handler/event/TodoAssignStatusChangeEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package com.pawith.todoapplication.handler.event; | ||
|
||
public record TodoAssignStatusChangeEvent(Long todoId) { | ||
} |
4 changes: 0 additions & 4 deletions
4
...tion/src/main/java/com/pawith/todoapplication/handler/event/TodoCompletionCheckEvent.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.