diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/GetAlarmCountResponse.java b/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/GetAlarmCountResponse.java new file mode 100644 index 0000000..ae14645 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/GetAlarmCountResponse.java @@ -0,0 +1,13 @@ +package com.moing.bo.backend.domain.history.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +@Getter +@AllArgsConstructor +@Builder +public class GetAlarmCountResponse { + + private String count; +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/GetAlarmHistoryResponse.java b/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/GetAlarmHistoryResponse.java new file mode 100644 index 0000000..461a891 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/GetAlarmHistoryResponse.java @@ -0,0 +1,62 @@ +package com.moing.bo.backend.domain.history.application.dto.response; + +import com.moing.bo.backend.domain.history.domain.entity.AlarmType; +import com.querydsl.core.annotations.QueryProjection; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +@Getter +@AllArgsConstructor +@Builder +public class GetAlarmHistoryResponse { + + private Long alarmHistoryId; + + private AlarmType type; + + private String path; + + private String idInfo; + + private String title; + + private String body; + + private String name; + + private Boolean isRead; + + private String createdDate; + + @QueryProjection + public GetAlarmHistoryResponse(Long alarmHistoryId, AlarmType type, String path, String idInfo, String title, String body, String name, boolean isRead, LocalDateTime createdDate) { + this.alarmHistoryId = alarmHistoryId; + this.type = type; + this.path = path; + this.idInfo = idInfo; + this.title = title; + this.body = body; + this.name = name; + this.isRead = isRead; + this.createdDate = formatCreatedDate(createdDate); + } + + public String formatCreatedDate(LocalDateTime createdDate) { + LocalDateTime currentDateTime = LocalDateTime.now(); + + LocalDateTime midnightOfCreatedDate = createdDate.toLocalDate().atStartOfDay(); + + if (currentDateTime.isAfter(midnightOfCreatedDate.plusDays(1))) { + DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("M월 d일"); + return midnightOfCreatedDate.plusDays(1).format(dateFormatter); + } else { + DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("a h:mm"); + return currentDateTime.format(timeFormatter); + } + } + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/MemberIdAndToken.java b/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/MemberIdAndToken.java new file mode 100644 index 0000000..f453e2f --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/application/dto/response/MemberIdAndToken.java @@ -0,0 +1,17 @@ +package com.moing.bo.backend.domain.history.application.dto.response; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@Builder +@AllArgsConstructor +@NoArgsConstructor +public class MemberIdAndToken { + + private String fcmToken; + private Long memberId; + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/application/mapper/AlarmHistoryMapper.java b/backend/src/main/java/com/moing/bo/backend/domain/history/application/mapper/AlarmHistoryMapper.java new file mode 100644 index 0000000..caa45ce --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/application/mapper/AlarmHistoryMapper.java @@ -0,0 +1,51 @@ +package com.moing.bo.backend.domain.history.application.mapper; + +import com.moing.bo.backend.domain.history.application.dto.response.MemberIdAndToken; +import com.moing.bo.backend.domain.history.domain.entity.AlarmHistory; +import com.moing.bo.backend.domain.history.domain.entity.AlarmType; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.Collections; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@Component +@RequiredArgsConstructor +public class AlarmHistoryMapper { + + public AlarmHistory toAlarmHistory(AlarmType type, String path, String idInfo, Long receiverId, String title, String body, String name) { + return AlarmHistory.builder() + .type(type) + .path(path) + .idInfo(idInfo) + .receiverId(receiverId) + .title(title) + .body(body) + .name(name) + .isRead(false) + .build(); + } + + public List getFcmTokens(Optional> memberIdAndTokens) { + return memberIdAndTokens.map(list -> list.stream() + .map(MemberIdAndToken::getFcmToken) + .collect(Collectors.toList())) + .orElse(Collections.emptyList()); + } + + public List getMemberIds(Optional> memberIdAndTokens) { + return memberIdAndTokens.map(list -> list.stream() + .map(MemberIdAndToken::getMemberId) + .collect(Collectors.toList())) + .orElse(Collections.emptyList()); + } + + public List getAlarmHistories(String idInfo, List memberIds, String title, String body, String teamName, AlarmType alarmType, String path) { + return memberIds.stream() + .map(memberId -> toAlarmHistory(alarmType, path, idInfo, memberId, title, body, teamName)) + .collect(Collectors.toList()); + } + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/application/service/SaveMultiAlarmHistoryUseCase.java b/backend/src/main/java/com/moing/bo/backend/domain/history/application/service/SaveMultiAlarmHistoryUseCase.java new file mode 100644 index 0000000..ee919f9 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/application/service/SaveMultiAlarmHistoryUseCase.java @@ -0,0 +1,28 @@ +package com.moing.bo.backend.domain.history.application.service; + +import com.moing.bo.backend.domain.history.application.dto.response.MemberIdAndToken; +import com.moing.bo.backend.domain.history.application.mapper.AlarmHistoryMapper; +import com.moing.bo.backend.domain.history.domain.entity.AlarmHistory; +import com.moing.bo.backend.domain.history.domain.entity.AlarmType; +import com.moing.bo.backend.domain.history.domain.service.AlarmHistorySaveService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Optional; + +@Service +@RequiredArgsConstructor +public class SaveMultiAlarmHistoryUseCase { + + private final AlarmHistoryMapper alarmHistoryMapper; + private final AlarmHistorySaveService alarmHistorySaveService; + + @Async + public void saveAlarmHistories(Optional> memberIdAndTokens, String idInfo, String title, String body, String name, AlarmType alarmType, String path) { + List memberIds = alarmHistoryMapper.getMemberIds(memberIdAndTokens); + List alarmHistories = alarmHistoryMapper.getAlarmHistories(idInfo, memberIds, title, body, name, alarmType, path); + alarmHistorySaveService.saveAlarmHistories(alarmHistories); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/application/service/SaveSingleAlarmHistoryUseCase.java b/backend/src/main/java/com/moing/bo/backend/domain/history/application/service/SaveSingleAlarmHistoryUseCase.java new file mode 100644 index 0000000..78be230 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/application/service/SaveSingleAlarmHistoryUseCase.java @@ -0,0 +1,23 @@ +package com.moing.bo.backend.domain.history.application.service; + +import com.moing.bo.backend.domain.history.application.mapper.AlarmHistoryMapper; +import com.moing.bo.backend.domain.history.domain.entity.AlarmHistory; +import com.moing.bo.backend.domain.history.domain.entity.AlarmType; +import com.moing.bo.backend.domain.history.domain.service.AlarmHistorySaveService; +import lombok.RequiredArgsConstructor; +import org.springframework.scheduling.annotation.Async; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class SaveSingleAlarmHistoryUseCase { + + private final AlarmHistoryMapper alarmHistoryMapper; + private final AlarmHistorySaveService alarmHistorySaveService; + + @Async + public void saveAlarmHistory(Long memberId, String idInfo, String title, String body, String name, AlarmType alarmType, String path) { + AlarmHistory alarmHistory = alarmHistoryMapper.toAlarmHistory(alarmType, path, idInfo, memberId, title, body, name); + alarmHistorySaveService.saveAlarmHistory(alarmHistory); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/AlarmHistory.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/AlarmHistory.java new file mode 100644 index 0000000..8135d44 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/AlarmHistory.java @@ -0,0 +1,47 @@ +package com.moing.bo.backend.domain.history.domain.entity; + +import com.moing.bo.backend.global.entity.BaseTimeEntity; +import jakarta.persistence.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Entity +@Builder +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class AlarmHistory extends BaseTimeEntity { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "alarm_history_id") + private Long id; + + @Enumerated(EnumType.STRING) + @Column(nullable = false) + private AlarmType type; + + @Column(nullable = false) + private String path; + + private String idInfo; + + private Long receiverId; + + @Column(nullable = false) + private String title; + + @Column(nullable = false) + private String body; + + @Column(nullable = false) + private String name; + + private boolean isRead; + + public void readAlarmHistory() { + this.isRead = true; + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/AlarmType.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/AlarmType.java new file mode 100644 index 0000000..a87a63f --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/AlarmType.java @@ -0,0 +1,12 @@ +package com.moing.bo.backend.domain.history.domain.entity; + +import lombok.Getter; + +@Getter +public enum AlarmType { + NEW_UPLOAD, + FIRE, + REMIND, + APPROVE_TEAM, + REJECT_TEAM +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/PagePath.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/PagePath.java new file mode 100644 index 0000000..eb37d57 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/entity/PagePath.java @@ -0,0 +1,21 @@ +package com.moing.bo.backend.domain.history.domain.entity; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +@Getter +@AllArgsConstructor +public enum PagePath { + + NOTICE_PATH("/post/detail"), + + MISSION_PATH("/missions/prove"), + + MISSION_ALL_PTAH("/missions"), + + HOME_PATH("/home"); + + + private final String value; + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryCustomRepository.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryCustomRepository.java new file mode 100644 index 0000000..95a4a34 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryCustomRepository.java @@ -0,0 +1,12 @@ +package com.moing.bo.backend.domain.history.domain.repository; + +import com.moing.bo.backend.domain.history.application.dto.response.GetAlarmHistoryResponse; + +import java.util.List; + +public interface AlarmHistoryCustomRepository { + + List findAlarmHistoriesByMemberId(Long memberId); + + String findUnreadAlarmCount(Long memberId); +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryCustomRepositoryImpl.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryCustomRepositoryImpl.java new file mode 100644 index 0000000..68708cc --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryCustomRepositoryImpl.java @@ -0,0 +1,47 @@ +package com.moing.bo.backend.domain.history.domain.repository; + +import com.moing.backend.domain.history.application.dto.response.GetAlarmHistoryResponse; +import com.moing.backend.domain.history.application.dto.response.QGetAlarmHistoryResponse; +import com.querydsl.jpa.impl.JPAQueryFactory; + +import javax.persistence.EntityManager; +import java.util.List; + +import static com.moing.backend.domain.history.domain.entity.QAlarmHistory.alarmHistory; + +public class AlarmHistoryCustomRepositoryImpl implements AlarmHistoryCustomRepository { + + private final JPAQueryFactory queryFactory; + + public AlarmHistoryCustomRepositoryImpl(EntityManager em) { + this.queryFactory = new JPAQueryFactory(em); + } + + @Override + public List findAlarmHistoriesByMemberId(Long memberId) { + return queryFactory.select(new QGetAlarmHistoryResponse(alarmHistory.id, + alarmHistory.type, + alarmHistory.path, + alarmHistory.idInfo, + alarmHistory.title, + alarmHistory.body, + alarmHistory.name, + alarmHistory.isRead, + alarmHistory.createdDate)) + .from(alarmHistory) + .where(alarmHistory.receiverId.eq(memberId)) + .orderBy(alarmHistory.createdDate.desc()) + .fetch(); + } + + @Override + public String findUnreadAlarmCount(Long memberId) { + Long count = queryFactory.select(alarmHistory.count()) + .from(alarmHistory) + .where(alarmHistory.receiverId.eq(memberId) + .and(alarmHistory.isRead.eq(false))) + .fetchOne(); + + return count != null ? (count > 99 ? "99+" : count.toString()) : "0"; + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryRepository.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryRepository.java new file mode 100644 index 0000000..cb53cbb --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/repository/AlarmHistoryRepository.java @@ -0,0 +1,12 @@ +package com.moing.bo.backend.domain.history.domain.repository; + +import com.moing.bo.backend.domain.history.domain.entity.AlarmHistory; +import org.springframework.data.jpa.repository.JpaRepository; + +import java.util.Optional; + +public interface AlarmHistoryRepository extends JpaRepository, AlarmHistoryCustomRepository { + + Optional findAlarmHistoryByIdAndReceiverId(Long id, Long receiverId); + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/service/AlarmHistoryGetService.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/service/AlarmHistoryGetService.java new file mode 100644 index 0000000..806a4c6 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/service/AlarmHistoryGetService.java @@ -0,0 +1,31 @@ +package com.moing.bo.backend.domain.history.domain.service; + + +import com.moing.bo.backend.domain.history.application.dto.response.GetAlarmHistoryResponse; +import com.moing.bo.backend.domain.history.domain.entity.AlarmHistory; +import com.moing.bo.backend.domain.history.domain.repository.AlarmHistoryRepository; +import com.moing.bo.backend.global.annotation.DomainService; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class AlarmHistoryGetService { + + private final AlarmHistoryRepository alarmHistoryRepository; + + public List getAlarmHistories(Long memberId) { + return alarmHistoryRepository.findAlarmHistoriesByMemberId(memberId); + } + + public AlarmHistory getAlarmHistory(Long alarmHistoryId, Long memberId) { + return alarmHistoryRepository.findAlarmHistoryByIdAndReceiverId(alarmHistoryId, memberId).orElseThrow(NotFoundAlarmHistoryException::new); + } + + public String getUnreadAlarmCount(Long memberId) { + return alarmHistoryRepository.findUnreadAlarmCount(memberId); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/domain/service/AlarmHistorySaveService.java b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/service/AlarmHistorySaveService.java new file mode 100644 index 0000000..af786de --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/domain/service/AlarmHistorySaveService.java @@ -0,0 +1,26 @@ +package com.moing.bo.backend.domain.history.domain.service; + +import com.moing.bo.backend.domain.history.domain.entity.AlarmHistory; +import com.moing.bo.backend.domain.history.domain.repository.AlarmHistoryRepository; +import com.moing.bo.backend.global.annotation.DomainService; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class AlarmHistorySaveService { + + private final AlarmHistoryRepository alarmHistoryRepository; + + public void saveAlarmHistories(List alarmHistories) { + alarmHistoryRepository.saveAll(alarmHistories); + } + + public void saveAlarmHistory(AlarmHistory alarmHistory) { + alarmHistoryRepository.save(alarmHistory); + } + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/exception/AlarmHistoryException.java b/backend/src/main/java/com/moing/bo/backend/domain/history/exception/AlarmHistoryException.java new file mode 100644 index 0000000..dc5a4b4 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/exception/AlarmHistoryException.java @@ -0,0 +1,11 @@ +package com.moing.bo.backend.domain.history.exception; + +import com.moing.bo.backend.global.exception.ApplicationException; +import com.moing.bo.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public abstract class AlarmHistoryException extends ApplicationException { + protected AlarmHistoryException(ErrorCode errorCode, HttpStatus httpStatus) { + super(errorCode, httpStatus); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/history/exception/NotFoundAlarmHistoryException.java b/backend/src/main/java/com/moing/bo/backend/domain/history/exception/NotFoundAlarmHistoryException.java new file mode 100644 index 0000000..4844608 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/history/exception/NotFoundAlarmHistoryException.java @@ -0,0 +1,11 @@ +package com.moing.bo.backend.domain.history.exception; + +import com.moing.bo.backend.global.response.ErrorCode; +import org.springframework.http.HttpStatus; + +public class NotFoundAlarmHistoryException extends AlarmHistoryException { + public NotFoundAlarmHistoryException() { + super(ErrorCode.NOT_FOUND_BY_ALARM_HISOTRY_ID_ERROR, + HttpStatus.NOT_FOUND); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberCheckService.java b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberCheckService.java new file mode 100644 index 0000000..1b4a97d --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberCheckService.java @@ -0,0 +1,18 @@ +package com.moing.bo.backend.domain.member.domain.service; + +import com.moing.backend.domain.member.domain.repository.MemberRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class MemberCheckService { + private final MemberRepository memberRepository; + public boolean checkNickname(String nickname) { + return memberRepository.checkNickname(nickname); + } + +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberDeleteService.java b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberDeleteService.java new file mode 100644 index 0000000..3b2d7bc --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberDeleteService.java @@ -0,0 +1,20 @@ +package com.moing.bo.backend.domain.member.domain.service; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.repository.MemberRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class MemberDeleteService { + + private final MemberRepository memberRepository; + + public void deleteMember(Member member){ + this.memberRepository.delete(member); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberGetService.java b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberGetService.java new file mode 100644 index 0000000..c44fdc0 --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberGetService.java @@ -0,0 +1,22 @@ +package com.moing.bo.backend.domain.member.domain.service; + +import com.moing.bo.backend.domain.member.domain.entity.Member; +import com.moing.bo.backend.domain.member.domain.repository.MemberRepository; +import com.moing.bo.backend.global.annotation.DomainService; +import jakarta.transaction.Transactional; +import lombok.RequiredArgsConstructor; + +@DomainService +@Transactional +@RequiredArgsConstructor +public class MemberGetService { + private final MemberRepository memberRepository; + + public Member getMemberBySocialId(String socialId) { + return memberRepository.findNotDeletedBySocialId(socialId).orElseThrow(() -> new NotFoundBySocialIdException()); + } + + public Member getMemberByMemberId(Long memberId) { + return memberRepository.findNotDeletedByMemberId(memberId).orElseThrow(() -> new NotFoundBySocialIdException()); + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberSaveService.java b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberSaveService.java new file mode 100644 index 0000000..840e62e --- /dev/null +++ b/backend/src/main/java/com/moing/bo/backend/domain/member/domain/service/MemberSaveService.java @@ -0,0 +1,29 @@ +package com.moing.bo.backend.domain.member.domain.service; + +import com.moing.backend.domain.member.domain.entity.Member; +import com.moing.backend.domain.member.domain.repository.MemberRepository; +import com.moing.backend.global.annotation.DomainService; +import lombok.AllArgsConstructor; + +import javax.transaction.Transactional; +import java.time.LocalDateTime; +import java.util.Optional; + +@DomainService +@Transactional +@AllArgsConstructor +public class MemberSaveService { + + private final MemberRepository memberRepository; + + public Member saveMember(Member member) { + OptionalfindMember=memberRepository.findNotDeletedBySocialId(member.getSocialId()); + if(findMember.isEmpty()){ + return memberRepository.save(member); + } else { + findMember.get().updateFcmToken(member.getFcmToken()); + findMember.get().updateLastSignInTime(LocalDateTime.now()); + return findMember.get(); + } + } +} diff --git a/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/ApproveTeamUseCase.java b/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/ApproveTeamUseCase.java index a9a1fd6..2d127d4 100644 --- a/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/ApproveTeamUseCase.java +++ b/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/ApproveTeamUseCase.java @@ -1,5 +1,7 @@ package com.moing.bo.backend.domain.team.application.service; +import com.moing.bo.backend.domain.history.application.service.SaveSingleAlarmHistoryUseCase; +import com.moing.bo.backend.domain.history.domain.entity.AlarmType; import com.moing.bo.backend.domain.team.application.dto.response.GetLeaderInfoResponse; import com.moing.bo.backend.domain.team.domain.service.TeamGetService; import com.moing.bo.backend.domain.team.domain.service.TeamUpdateService; @@ -11,6 +13,7 @@ import java.util.List; +import static com.moing.bo.backend.domain.history.domain.entity.PagePath.HOME_PATH; import static com.moing.bo.backend.global.config.fcm.constant.ApproveTeamMessage.APPROVE_TEAM_MESSAGE; @Service @@ -20,6 +23,7 @@ public class ApproveTeamUseCase { private final TeamUpdateService teamUpdateService; private final TeamGetService teamGetService; + private final SaveSingleAlarmHistoryUseCase saveAlarmHistoryUseCase; private final FcmService fcmService; public void approveTeams(List teamIds) { @@ -28,6 +32,7 @@ public void approveTeams(List teamIds) { for (GetLeaderInfoResponse info : leaderInfos) { String title = APPROVE_TEAM_MESSAGE.title(info.getLeaderName(), info.getTeamName()); String body = APPROVE_TEAM_MESSAGE.body(); + saveAlarmHistoryUseCase.saveAlarmHistory(info.getLeaderId(), "", title, body, info.getTeamName(), AlarmType.APPROVE_TEAM, HOME_PATH.getValue()); fcmService.sendSingleDevice(new SingleRequest(info.getLeaderFcmToken(), title, body)); } } diff --git a/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/RejectTeamUseCase.java b/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/RejectTeamUseCase.java index f75f91d..f64f4dc 100644 --- a/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/RejectTeamUseCase.java +++ b/backend/src/main/java/com/moing/bo/backend/domain/team/application/service/RejectTeamUseCase.java @@ -1,5 +1,7 @@ package com.moing.bo.backend.domain.team.application.service; +import com.moing.bo.backend.domain.history.application.service.SaveSingleAlarmHistoryUseCase; +import com.moing.bo.backend.domain.history.domain.entity.AlarmType; import com.moing.bo.backend.domain.team.application.dto.response.GetLeaderInfoResponse; import com.moing.bo.backend.domain.team.domain.service.TeamGetService; import com.moing.bo.backend.domain.team.domain.service.TeamUpdateService; @@ -12,6 +14,7 @@ import java.util.Collections; import java.util.List; +import static com.moing.bo.backend.domain.history.domain.entity.PagePath.HOME_PATH; import static com.moing.bo.backend.global.config.fcm.constant.ApproveTeamMessage.REJECT_TEAM_MESSAGE; @Service @@ -22,6 +25,8 @@ public class RejectTeamUseCase { private final TeamUpdateService teamUpdateService; private final TeamGetService teamGetService; private final ApplicationEventPublisher eventPublisher; + private final SaveSingleAlarmHistoryUseCase saveAlarmHistoryUseCase; + public void rejectTeams(List teamIds) { teamUpdateService.updateTeamStatus(false, teamIds); @@ -29,6 +34,7 @@ public void rejectTeams(List teamIds) { for (GetLeaderInfoResponse info : leaderInfos) { String title = REJECT_TEAM_MESSAGE.title(info.getLeaderName(), info.getTeamName()); String body = REJECT_TEAM_MESSAGE.body(); + saveAlarmHistoryUseCase.saveAlarmHistory(info.getLeaderId(), "", title, body, info.getTeamName(), AlarmType.REJECT_TEAM, HOME_PATH.getValue()); eventPublisher.publishEvent(new FcmEvent(title, body, Collections.singletonList(info.getLeaderFcmToken()))); } } diff --git a/backend/src/main/java/com/moing/bo/backend/global/response/ErrorCode.java b/backend/src/main/java/com/moing/bo/backend/global/response/ErrorCode.java index e227530..4711668 100644 --- a/backend/src/main/java/com/moing/bo/backend/global/response/ErrorCode.java +++ b/backend/src/main/java/com/moing/bo/backend/global/response/ErrorCode.java @@ -21,9 +21,11 @@ public enum ErrorCode { //FCM 토큰 관련 INITIALIZE_ERROR("F0001", "Firebase Admin SDK 초기화에 실패했습니다."), NOTIFICATION_ERROR("F0002", "메시지 전송에 실패했습니다."), - MESSAGING_ERROR("F0003", "firebaseConfigPath를 읽어오는데 실패하였습니다"); + MESSAGING_ERROR("F0003", "firebaseConfigPath를 읽어오는데 실패하였습니다"), + NOT_FOUND_BY_ALARM_HISOTRY_ID_ERROR("AH0001", "해당 alarmHistoryId인 알림이 존재하지 않습니다."); + private final String errorCode; private final String message;