Skip to content

Commit

Permalink
Merge pull request #93 from Modagbul/feat/mission-closing
Browse files Browse the repository at this point in the history
Feat/mission closing
  • Loading branch information
seungueonn authored Nov 29, 2023
2 parents f85fcb3 + 1198e96 commit 770a986
Show file tree
Hide file tree
Showing 10 changed files with 81 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -54,15 +57,25 @@ public FireThrowRes createFireThrow(String userId, Long receiveMemberId) {
}

public List<FireReceiveRes> getFireReceiveList(String userId,Long teamId, Long missionId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();
Member member = memberGetService.getMemberBySocialId(userId);
Long memberId = member.getMemberId();

List<FireReceiveRes> fireReceiveRes = FireMapper.mapToFireReceiversList(fireQueryService.getNotYetMissionMember(teamId, missionId));
List<FireReceiveRes> 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;
}



}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -11,6 +12,6 @@
public interface FireCustomRepository {

boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMemberId);
Optional<List<Member>> getFireReceivers(Long teamId, Long missionId);
Optional<List<FireReceiveRes>> getFireReceivers(Long teamId, Long missionId, Long memberId);

}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -46,25 +50,48 @@ public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMembe
}


public Optional<List<Member>> getFireReceivers(Long teamId, Long missionId) {
public Optional<List<FireReceiveRes>> getFireReceivers(Long teamId, Long missionId, Long memberId) {

JPQLQuery<Long> 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());

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,8 +22,8 @@ public boolean hasFireCreatedWithinOneHour(Long throwMemberId, Long receiveMembe
return fireRepository.hasFireCreatedWithinOneHour(throwMemberId,receiveMemberId);
}

public List<Member> getNotYetMissionMember(Long teamId, Long missionId) {
return fireRepository.getFireReceivers(teamId, missionId).orElseThrow(NotFoundFireReceiversException::new);
public List<FireReceiveRes> getNotYetMissionMember(Long teamId, Long missionId, Long memberId) {
return fireRepository.getFireReceivers(teamId, missionId,memberId).orElseThrow(NotFoundFireReceiversException::new);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +30,7 @@ public class FireController {
* 작성자 : 정승연
*/

@PostMapping("{receiveMemberId}")
@PostMapping("/{receiveMemberId}")
public ResponseEntity<SuccessResponse<FireThrowRes>> 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)));
Expand All @@ -42,7 +42,7 @@ public ResponseEntity<SuccessResponse<FireThrowRes>> throwFire (@AuthenticationP
* 작성자 : 정승연
*/

@GetMapping("")
@GetMapping()
public ResponseEntity<SuccessResponse<List<FireReceiveRes>>> 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)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public Optional<List<GatherRepeatMissionRes>> findRepeatMissionByMemberId(Long m
@Override
public Optional<List<Mission>> findMissionByDueTo() {

LocalDateTime oneHourAgo = LocalDateTime.now().minusHours(1);
LocalDateTime oneHourAgo = LocalDateTime.now();

return Optional.ofNullable(queryFactory
.selectFrom(mission)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public Optional<List<FinishMissionBoardRes>> 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()
))
Expand All @@ -215,7 +215,7 @@ public Optional<List<FinishMissionBoardRes>> 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()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
);
Expand Down

0 comments on commit 770a986

Please sign in to comment.