-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Alarm 인터페이스 구현 * feat: ServerToUserAlarm 구현체 생성 * refactor: 기존 UserToUserAlarm을 Alarm 구현체로 변경 * feat: 매칭 결과 알람 생성 로직 구현 * feat: 알람 자동 생성 로직 구현 (trigger: 매칭 완료) * test: 테스트 작성 * refactor: 메서드 분리 * feat: 피드백 완료 알람 타입 추가 * feat: 피드백 완료 알람 기능 구현 * test: 피드백 작성 알람 생성 테스트 * test: 개발/소셜 피드백 테스트 중복 부분 `@BeforeEach` 로 처리 * fix: 깨지는 CI 해결 --------- Co-authored-by: ashsty <[email protected]>
- Loading branch information
1 parent
00cf45c
commit 903a722
Showing
31 changed files
with
716 additions
and
264 deletions.
There are no files selected for viewing
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,22 @@ | ||
package corea.alarm.domain; | ||
|
||
import corea.member.domain.Member; | ||
|
||
public interface Alarm { | ||
|
||
boolean isStatus(boolean status); | ||
|
||
boolean isNotReceiver(Member member); | ||
|
||
void read(); | ||
|
||
String getActionType(); | ||
|
||
Long getId(); | ||
|
||
Long getActorId(); | ||
|
||
Long getInteractionId(); | ||
|
||
Long getReceiverId(); | ||
} |
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 |
---|---|---|
|
@@ -3,4 +3,7 @@ | |
public enum AlarmActionType { | ||
REVIEW_COMPLETE, | ||
REVIEW_URGE, | ||
MATCH_COMPLETE, | ||
MATCH_FAIL, | ||
FEEDBACK_CREATED, | ||
} |
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
60 changes: 60 additions & 0 deletions
60
backend/src/main/java/corea/alarm/domain/ServerToUserAlarm.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,60 @@ | ||
package corea.alarm.domain; | ||
|
||
import corea.global.BaseTimeEntity; | ||
import corea.member.domain.Member; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import static jakarta.persistence.GenerationType.IDENTITY; | ||
|
||
@Entity | ||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Getter | ||
public class ServerToUserAlarm extends BaseTimeEntity implements Alarm { | ||
|
||
@Id | ||
@GeneratedValue(strategy = IDENTITY) | ||
private Long id; | ||
|
||
@Enumerated(EnumType.STRING) | ||
private AlarmActionType alarmActionType; | ||
|
||
private Long receiverId; | ||
|
||
private Long interactionId; | ||
|
||
private boolean isRead; | ||
|
||
public ServerToUserAlarm(AlarmActionType alarmActionType, long receiverId, long interactionId, boolean isRead) { | ||
this(null, alarmActionType, receiverId, interactionId, isRead); | ||
} | ||
|
||
@Override | ||
public boolean isStatus(boolean status) { | ||
return isRead == status; | ||
} | ||
|
||
@Override | ||
public String getActionType() { | ||
return alarmActionType.name(); | ||
} | ||
|
||
@Override | ||
public Long getActorId() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isNotReceiver(Member member) { | ||
return !receiverId.equals(member.getId()); | ||
} | ||
|
||
@Override | ||
public void read() { | ||
isRead = true; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
backend/src/main/java/corea/alarm/domain/ServerToUserAlarmReader.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,40 @@ | ||
package corea.alarm.domain; | ||
|
||
import corea.alarm.repository.ServerToUserAlarmRepository; | ||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.global.annotation.Reader; | ||
import corea.member.domain.Member; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.EnumMap; | ||
import java.util.stream.Collectors; | ||
|
||
@Reader | ||
@RequiredArgsConstructor | ||
public class ServerToUserAlarmReader { | ||
|
||
private final ServerToUserAlarmRepository serverToUserAlarmRepository; | ||
|
||
public long countReceivedAlarm(Member member, boolean isRead) { | ||
return serverToUserAlarmRepository.findAllByReceiverId(member.getId()) | ||
.stream() | ||
.filter(alarm -> alarm.isStatus(isRead)) | ||
.count(); | ||
} | ||
|
||
public ServerToUserAlarm find(long actionId) { | ||
return serverToUserAlarmRepository.findById(actionId) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.NOT_RECEIVED_ALARM)); | ||
} | ||
|
||
public AlarmsByActionType findAllByReceiver(Member member) { | ||
return new AlarmsByActionType(serverToUserAlarmRepository.findAllByReceiverId(member.getId()) | ||
.stream() | ||
.collect(Collectors.groupingBy( | ||
ServerToUserAlarm::getAlarmActionType, | ||
() -> new EnumMap<>(AlarmActionType.class), | ||
Collectors.toList() | ||
))); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
backend/src/main/java/corea/alarm/domain/ServerToUserAlarmWriter.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,27 @@ | ||
package corea.alarm.domain; | ||
|
||
import corea.alarm.repository.ServerToUserAlarmRepository; | ||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.global.annotation.Writer; | ||
import corea.member.domain.Member; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
@Writer | ||
@RequiredArgsConstructor | ||
public class ServerToUserAlarmWriter { | ||
|
||
private final ServerToUserAlarmRepository serverToUserAlarmRepository; | ||
|
||
public ServerToUserAlarm create(ServerToUserAlarm serverToUserAlarm) { | ||
return serverToUserAlarmRepository.save(serverToUserAlarm); | ||
} | ||
|
||
public ServerToUserAlarm check(Member member, ServerToUserAlarm serverToUserAlarm) { | ||
if (serverToUserAlarm.isNotReceiver(member)) { | ||
throw new CoreaException(ExceptionType.NOT_RECEIVED_ALARM); | ||
} | ||
serverToUserAlarm.read(); | ||
return serverToUserAlarm; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/corea/alarm/dto/CreateServerToUserAlarmInput.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,18 @@ | ||
package corea.alarm.dto; | ||
|
||
import corea.alarm.domain.AlarmActionType; | ||
import corea.alarm.domain.ServerToUserAlarm; | ||
|
||
public record CreateServerToUserAlarmInput(AlarmActionType alarmType, | ||
long receiverId, | ||
long interactionId) { | ||
|
||
public ServerToUserAlarm toEntity() { | ||
return new ServerToUserAlarm( | ||
alarmType, | ||
receiverId, | ||
interactionId, | ||
false | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
backend/src/main/java/corea/alarm/repository/ServerToUserAlarmRepository.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,11 @@ | ||
package corea.alarm.repository; | ||
|
||
import corea.alarm.domain.ServerToUserAlarm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface ServerToUserAlarmRepository extends JpaRepository<ServerToUserAlarm, Long> { | ||
|
||
List<ServerToUserAlarm> findAllByReceiverId(long receiverId); | ||
} |
3 changes: 2 additions & 1 deletion
3
...arm/domain/UserToUserAlarmRepository.java → ...repository/UserToUserAlarmRepository.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
Oops, something went wrong.