diff --git a/src/main/java/com/moing/backend/domain/fire/application/dto/res/FireReceiveRes.java b/src/main/java/com/moing/backend/domain/fire/application/dto/res/FireReceiveRes.java index 7b59d0a9..87ac3456 100644 --- a/src/main/java/com/moing/backend/domain/fire/application/dto/res/FireReceiveRes.java +++ b/src/main/java/com/moing/backend/domain/fire/application/dto/res/FireReceiveRes.java @@ -1,16 +1,23 @@ package com.moing.backend.domain.fire.application.dto.res; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @Builder @Getter +@AllArgsConstructor public class FireReceiveRes { private Long receiveMemberId; private String nickname; private String fireStatus; + public FireReceiveRes(Long receiveMemberId, String nickname) { + this.receiveMemberId = receiveMemberId; + this.nickname = nickname; + } + public void updateFireStatus(boolean status) { if (status) this.fireStatus = "True"; diff --git a/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowAlarmUseCase.java b/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowAlarmUseCase.java index 83eb1b25..ffddb4b7 100644 --- a/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowAlarmUseCase.java +++ b/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowAlarmUseCase.java @@ -23,9 +23,11 @@ public class FireThrowAlarmUseCase { public void sendFireThrowAlarm(Member throwMember, Member receiveMember) { Random random = new Random(System.currentTimeMillis()); - String title = getTitle(throwMember.getNickName(), receiveMember.getNickName(), random.nextInt(2)); + int randomNum = random.nextInt(2); + + String title = getTitle(throwMember.getNickName(), receiveMember.getNickName(), randomNum); + String message = getMessage(throwMember.getNickName(), receiveMember.getNickName(), randomNum); - String message = getMessage(throwMember.getNickName(), receiveMember.getNickName(), random.nextInt(2)); SingleRequest singleRequest = new SingleRequest(receiveMember.getFcmToken(), title, message); fcmService.sendSingleDevice(singleRequest); diff --git a/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowUseCase.java b/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowUseCase.java index 1f07c6fe..2c3faca8 100644 --- a/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowUseCase.java +++ b/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowUseCase.java @@ -9,6 +9,7 @@ import com.moing.backend.domain.fire.exception.NoAuthThrowFireException; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.member.domain.service.MemberGetService; +import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService; import com.moing.backend.global.config.fcm.dto.request.SingleRequest; import com.moing.backend.global.config.fcm.service.FcmService; import lombok.RequiredArgsConstructor; @@ -30,6 +31,8 @@ public class FireThrowUseCase { private final FireThrowAlarmUseCase fireThrowAlarmUseCase; + private final MissionArchiveQueryService missionArchiveQueryService; + public FireThrowRes createFireThrow(String userId, Long receiveMemberId) { Member throwMember = memberGetService.getMemberBySocialId(userId); @@ -54,15 +57,25 @@ public FireThrowRes createFireThrow(String userId, Long receiveMemberId) { } public List getFireReceiveList(String userId,Long teamId, Long missionId) { - Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId(); + Member member = memberGetService.getMemberBySocialId(userId); + Long memberId = member.getMemberId(); - List fireReceiveRes = FireMapper.mapToFireReceiversList(fireQueryService.getNotYetMissionMember(teamId, missionId)); + List fireReceiveRes = fireQueryService.getNotYetMissionMember(teamId, missionId,memberId); fireReceiveRes.forEach( res -> res.updateFireStatus(fireQueryService.hasFireCreatedWithinOneHour(memberId,res.getReceiveMemberId()) )); +// if (!missionArchiveQueryService.isDone(memberId, missionId)) { +// fireReceiveRes.add(0,FireReceiveRes.builder() +// .receiveMemberId(memberId) +// .nickname(member.getNickName()) +// .fireStatus("False") +// .build()); +// } + return fireReceiveRes; } + } diff --git a/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepository.java b/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepository.java index 4e2d2b10..12470073 100644 --- a/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepository.java +++ b/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepository.java @@ -1,6 +1,7 @@ package com.moing.backend.domain.fire.domain.repository; +import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes; import com.moing.backend.domain.fire.domain.entity.Fire; import com.moing.backend.domain.member.domain.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; @@ -11,6 +12,6 @@ public interface FireCustomRepository { boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMemberId); - Optional> getFireReceivers(Long teamId, Long missionId); + Optional> getFireReceivers(Long teamId, Long missionId, Long memberId); } diff --git a/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepositoryImpl.java index 8e90d441..29abcb5a 100644 --- a/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepositoryImpl.java @@ -1,9 +1,13 @@ package com.moing.backend.domain.fire.domain.repository; +import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes; import com.moing.backend.domain.fire.domain.entity.Fire; import com.moing.backend.domain.member.domain.entity.Member; import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive; +import com.querydsl.core.types.Projections; +import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.JPAExpressions; +import com.querydsl.jpa.JPQLQuery; import com.querydsl.jpa.impl.JPAQueryFactory; import javax.persistence.EntityManager; @@ -46,25 +50,48 @@ public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMembe } - public Optional> getFireReceivers(Long teamId, Long missionId) { + public Optional> getFireReceivers(Long teamId, Long missionId, Long memberId) { + + JPQLQuery missionDonePeople = select(missionArchive.member.memberId) + .from(missionArchive, mission) + .where(missionArchive.mission.id.eq(missionId), + mission.id.eq(missionId) + ) + .groupBy(missionArchive.member.memberId, + missionArchive.mission.id, + missionArchive.count, + mission.number) + .having( + missionArchive.mission.id.eq(missionId), + missionArchive.count.max().goe(mission.number) + ); + + LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1); // 현재 시간에서 1시간을 뺀 시간 + + BooleanExpression oneHourStatus = JPAExpressions + .select() + .from(fire) + .where( + fire.throwMemberId.eq(memberId), + fire.receiveMemberId.notIn(missionDonePeople), + fire.createdDate.after(oneHourAgo) // createdDate가 oneHourAgo 이후인 데이터 + ) + + .exists(); + + return Optional.ofNullable(queryFactory - .select(teamMember.member) + .select(Projections.constructor(FireReceiveRes.class, + teamMember.member.memberId, + teamMember.member.nickName +// oneHourStatus.stringValue() +// teamMember.member.nickName + )) .from(teamMember) .where( teamMember.team.teamId.eq(teamId), - teamMember.member.memberId.notIn( - JPAExpressions - .select(missionArchive.member.memberId) - .from(missionArchive,mission) - .where(missionArchive.mission.id.eq(missionId), - mission.id.eq(missionId)) - .groupBy(missionArchive.member.memberId, missionArchive.mission.id, - missionArchive.count, mission.number) - .having( - missionArchive.mission.id.eq(missionId), - missionArchive.count.max().goe(mission.number) - ) - ) + teamMember.member.memberId.ne(memberId), + teamMember.member.memberId.notIn(missionDonePeople) ) .fetch()); diff --git a/src/main/java/com/moing/backend/domain/fire/domain/service/FireQueryService.java b/src/main/java/com/moing/backend/domain/fire/domain/service/FireQueryService.java index abb94e44..2bcaef0c 100644 --- a/src/main/java/com/moing/backend/domain/fire/domain/service/FireQueryService.java +++ b/src/main/java/com/moing/backend/domain/fire/domain/service/FireQueryService.java @@ -1,5 +1,6 @@ package com.moing.backend.domain.fire.domain.service; +import com.moing.backend.domain.fire.application.dto.res.FireReceiveRes; import com.moing.backend.domain.fire.domain.entity.Fire; import com.moing.backend.domain.fire.domain.repository.FireCustomRepository; import com.moing.backend.domain.fire.domain.repository.FireRepository; @@ -21,8 +22,8 @@ public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMembe return fireRepository.hasFireCreatedWithinOneHour(throwMemberId,receiveMemberId); } - public List getNotYetMissionMember(Long teamId, Long missionId) { - return fireRepository.getFireReceivers(teamId, missionId).orElseThrow(NotFoundFireReceiversException::new); + public List getNotYetMissionMember(Long teamId, Long missionId, Long memberId) { + return fireRepository.getFireReceivers(teamId, missionId,memberId).orElseThrow(NotFoundFireReceiversException::new); } } diff --git a/src/main/java/com/moing/backend/domain/fire/presentation/FireController.java b/src/main/java/com/moing/backend/domain/fire/presentation/FireController.java index a9210481..f302d0f2 100644 --- a/src/main/java/com/moing/backend/domain/fire/presentation/FireController.java +++ b/src/main/java/com/moing/backend/domain/fire/presentation/FireController.java @@ -19,7 +19,7 @@ @RestController @AllArgsConstructor -@RequestMapping("/api/{teamId}/missions/{missionId}/fire") +@RequestMapping("/api/team/{teamId}/missions/{missionId}/fire") public class FireController { private final FireThrowUseCase fireThrowUseCase; @@ -30,7 +30,7 @@ public class FireController { * 작성자 : 정승연 */ - @PostMapping("{receiveMemberId}") + @PostMapping("/{receiveMemberId}") public ResponseEntity> throwFire (@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId, @PathVariable("receiveMemberId") Long receiveMemberId) { return ResponseEntity.ok(SuccessResponse.create(THROW_FIRE_SUCCESS.getMessage(), this.fireThrowUseCase.createFireThrow(user.getSocialId(),receiveMemberId))); @@ -42,7 +42,7 @@ public ResponseEntity> throwFire (@AuthenticationP * 작성자 : 정승연 */ - @GetMapping("") + @GetMapping() public ResponseEntity>> throwFireList (@AuthenticationPrincipal User user, @PathVariable("teamId") Long teamId, @PathVariable("missionId") Long missionId) { return ResponseEntity.ok(SuccessResponse.create(GET_RECEIVERS_SUCCESS.getMessage(), this.fireThrowUseCase.getFireReceiveList(user.getSocialId(),teamId,missionId))); diff --git a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java index 9455fe5a..d90ab4e8 100644 --- a/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/mission/domain/repository/MissionCustomRepositoryImpl.java @@ -65,7 +65,7 @@ public Optional> findRepeatMissionByMemberId(Long m @Override public Optional> findMissionByDueTo() { - LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1); + LocalDateTime oneHourAgo = LocalDateTime.now(); return Optional.ofNullable(queryFactory .selectFrom(mission) diff --git a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java index f9781c43..9aba3d60 100644 --- a/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java +++ b/src/main/java/com/moing/backend/domain/missionArchive/domain/repository/MissionArchiveCustomRepositoryImpl.java @@ -206,7 +206,7 @@ public Optional> findFinishMissionsByStatus(Long mem mission.id, mission.dueTo.stringValue(), mission.title, - missionArchive.status.stringValue().coalesce("INCOMPLETE").as("status"), + missionArchive.status.stringValue().coalesce("FAIL").as("status"), mission.type.stringValue(), mission.way.stringValue() )) @@ -215,7 +215,7 @@ public Optional> findFinishMissionsByStatus(Long mem .on(missionArchive.member.memberId.eq(memberId)) .where( mission.team.teamId.eq(teamId), - mission.status.eq(MissionStatus.SUCCESS).or(mission.status.eq(MissionStatus.FAIL)) + mission.status.eq(MissionStatus.SUCCESS).or(mission.status.eq(MissionStatus.END)) ) .fetch() ); diff --git a/src/test/java/com/moing/backend/domain/fire/representation/FireControllerTest.java b/src/test/java/com/moing/backend/domain/fire/representation/FireControllerTest.java index 767f6e4c..8aa1e1b0 100644 --- a/src/test/java/com/moing/backend/domain/fire/representation/FireControllerTest.java +++ b/src/test/java/com/moing/backend/domain/fire/representation/FireControllerTest.java @@ -51,7 +51,7 @@ public class FireControllerTest extends CommonControllerTest { Long missionId = 1L; //when ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. - get("/api/{teamId}/missions/{missionId}/fire",teamId,missionId) + get("/api/team/{teamId}/missions/{missionId}/fire",teamId,missionId) .header("Authorization", "Bearer ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) @@ -99,7 +99,7 @@ public class FireControllerTest extends CommonControllerTest { Long receiveMemberId = 2L; //when ResultActions actions = mockMvc.perform(RestDocumentationRequestBuilders. - post("/api/{teamId}/missions/{missionId}/fire/{receiveMemberId}",teamId,missionId,receiveMemberId) + post("/api/team/{teamId}/missions/{missionId}/fire/{receiveMemberId}",teamId,missionId,receiveMemberId) .header("Authorization", "Bearer ACCESS_TOKEN") .contentType(MediaType.APPLICATION_JSON) );