From a58bae4966f202348936d4c210b4fae192842f85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Tue, 28 Nov 2023 13:17:18 +0900 Subject: [PATCH 1/4] =?UTF-8?q?fix=20:=20=EB=B6=88=EB=8D=98=EC=A7=80?= =?UTF-8?q?=EA=B8=B0=20URL=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FireThrowAlarmUseCase.java | 6 ++-- .../application/service/FireThrowUseCase.java | 17 +++++++++-- .../repository/FireCustomRepository.java | 3 +- .../repository/FireCustomRepositoryImpl.java | 28 +++++++++++++++++-- .../fire/domain/service/FireQueryService.java | 5 ++-- .../fire/presentation/FireController.java | 6 ++-- .../representation/FireControllerTest.java | 4 +-- 7 files changed, 54 insertions(+), 15 deletions(-) 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..117ccb0b 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..fa5ab01e 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,8 +1,11 @@ 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.impl.JPAQueryFactory; @@ -46,9 +49,27 @@ public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMembe } - public Optional> getFireReceivers(Long teamId, Long missionId) { + public Optional> getFireReceivers(Long teamId, Long missionId, Long memberId) { + + LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1); // 현재 시간에서 1시간을 뺀 시간 + + BooleanExpression oneHourStatus = JPAExpressions + .select() + .from(fire) + .where( + fire.throwMemberId.eq(memberId), + fire.receiveMemberId.eq(teamMember.member.memberId), + 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 + )) .from(teamMember) .where( teamMember.team.teamId.eq(teamId), @@ -57,7 +78,8 @@ public Optional> getFireReceivers(Long teamId, Long missionId) { .select(missionArchive.member.memberId) .from(missionArchive,mission) .where(missionArchive.mission.id.eq(missionId), - mission.id.eq(missionId)) + mission.id.eq(missionId), + missionArchive.member.memberId.notIn(memberId)) .groupBy(missionArchive.member.memberId, missionArchive.mission.id, missionArchive.count, mission.number) .having( 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/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) ); From 2c5b71b52111052837d742ee19e1726cf320efe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:07:41 +0900 Subject: [PATCH 2/4] =?UTF-8?q?fix=20:=20=EC=99=84=EB=A3=8C=EB=90=9C=20?= =?UTF-8?q?=EB=AF=B8=EC=85=98=20=EC=A4=91=20=EC=84=B1=EA=B3=B5/=EC=8B=A4?= =?UTF-8?q?=ED=8C=A8=20=EA=B8=B0=EC=A4=80=20=EB=B3=B4=EC=99=84=20(?= =?UTF-8?q?=EA=B0=9C=EC=9D=B8=EB=B3=84)=20::=20coalesce(FAIL)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/MissionArchiveCustomRepositoryImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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() ); From 629d6ca627c2e11ac4ebd8fa56517d0959ef42b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:57:31 +0900 Subject: [PATCH 3/4] =?UTF-8?q?fix=20:=20=EB=8B=A8=EC=9D=BC=20=EB=AF=B8?= =?UTF-8?q?=EC=85=98=20WAIT=20=EC=83=81=ED=83=9C=20=EB=A6=AC=ED=84=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mission/domain/repository/MissionCustomRepositoryImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 1198e968f4f8fc4df6246f8a15e5b207d190f8c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=A0=95=20=EC=8A=B9=20=EC=97=B0?= <53565255+seungyeonnnnnni@users.noreply.github.com> Date: Wed, 29 Nov 2023 18:58:12 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix=20:=20=EB=B6=88=EB=8D=98=EC=A7=80?= =?UTF-8?q?=EA=B8=B0=20=EB=AA=A9=EB=A1=9D=EC=97=90=EC=84=9C=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=ED=95=9C=20=EC=82=AC=EC=9A=A9=EC=9E=90=20?= =?UTF-8?q?=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/dto/res/FireReceiveRes.java | 7 ++++ .../application/service/FireThrowUseCase.java | 14 +++---- .../repository/FireCustomRepositoryImpl.java | 39 +++++++++++-------- 3 files changed, 36 insertions(+), 24 deletions(-) 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/FireThrowUseCase.java b/src/main/java/com/moing/backend/domain/fire/application/service/FireThrowUseCase.java index 117ccb0b..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 @@ -65,13 +65,13 @@ public List getFireReceiveList(String userId,Long teamId, Long m 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()); - } +// 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/FireCustomRepositoryImpl.java b/src/main/java/com/moing/backend/domain/fire/domain/repository/FireCustomRepositoryImpl.java index fa5ab01e..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 @@ -7,6 +7,7 @@ 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; @@ -51,6 +52,20 @@ public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMembe 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 @@ -58,35 +73,25 @@ public Optional> getFireReceivers(Long teamId, Long mission .from(fire) .where( fire.throwMemberId.eq(memberId), - fire.receiveMemberId.eq(teamMember.member.memberId), + fire.receiveMemberId.notIn(missionDonePeople), fire.createdDate.after(oneHourAgo) // createdDate가 oneHourAgo 이후인 데이터 ) + .exists(); return Optional.ofNullable(queryFactory .select(Projections.constructor(FireReceiveRes.class, teamMember.member.memberId, - teamMember.member.nickName, - oneHourStatus + 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), - missionArchive.member.memberId.notIn(memberId)) - .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());