Skip to content

Commit

Permalink
Merge branch 'main' into feat/mission-alarm
Browse files Browse the repository at this point in the history
  • Loading branch information
seungueonn authored Dec 6, 2023
2 parents ea5f269 + e84953f commit 6b63796
Show file tree
Hide file tree
Showing 25 changed files with 200 additions and 46 deletions.
6 changes: 6 additions & 0 deletions src/docs/asciidoc/Mission-API.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,9 @@ operation::mission-controller-test/미션_추천[snippets='http-request,path-par

---

[[Mission-종료]]
=== Mission 종료
operation::mission-controller-test/미션_종료[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

---

Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@ public class MissionCreateRes {
private String status;
private String way;

private Boolean isLeader;

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.moing.backend.domain.mission.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;

@Getter
@Builder
@AllArgsConstructor
public class MissionReadRes {

private String title;
Expand All @@ -16,4 +18,6 @@ public class MissionReadRes {
private String type;
private String way;

private Boolean isLeader;

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public static MissionCreateRes mapToMissionCreateRes(Mission mission) {
.type(mission.getType().name())
.status(mission.getStatus().name())
.number(mission.getNumber())
.isLeader(Boolean.TRUE)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ public class MissionReadUseCase {
public MissionReadRes getMission(String userSocialId, Long missionId) {

Member member = memberGetService.getMemberBySocialId(userSocialId);

Mission mission = missionQueryService.findMissionById(missionId);
return MissionMapper.mapToMissionReadRes(mission);
return missionQueryService.findMissionByIds(member.getMemberId(),missionId);
}

public String getTeamCategory(Long teamId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mission.application.dto.req.MissionReq;
import com.moing.backend.domain.mission.application.dto.res.MissionCreateRes;
import com.moing.backend.domain.mission.application.dto.res.MissionReadRes;
import com.moing.backend.domain.mission.application.mapper.MissionMapper;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.mission.domain.entity.constant.MissionType;
import com.moing.backend.domain.mission.domain.service.MissionQueryService;
import com.moing.backend.domain.mission.domain.service.MissionSaveService;
import com.moing.backend.domain.mission.exception.NoAccessCreateMission;
import com.moing.backend.global.util.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -23,7 +26,7 @@ public class MissionUpdateUseCase {
private final MissionQueryService missionQueryService;
private final MemberGetService memberGetService;

public MissionCreateRes updateMission(String userSocialId,Long missionId, MissionReq missionReq) {
public MissionCreateRes updateMission(String userSocialId, Long missionId, MissionReq missionReq) {


Member member = memberGetService.getMemberBySocialId(userSocialId);
Expand All @@ -36,4 +39,20 @@ public MissionCreateRes updateMission(String userSocialId,Long missionId, Missio

}

public MissionReadRes updateMissionStatus(String userSocialId, Long missionId) {


Member member = memberGetService.getMemberBySocialId(userSocialId);

Mission findMission = missionQueryService.findMissionById(missionId);

if (findMission.getTeam().getLeaderId().equals(member.getMemberId())) {
findMission.updateStatus(MissionStatus.END);
} else {
throw new NoAccessCreateMission();
}

return MissionMapper.mapToMissionReadRes(findMission);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.teamMember.domain.service.TeamMemberGetService;
import com.moing.backend.global.config.fcm.dto.event.FcmEvent;
import com.moing.backend.global.config.fcm.dto.request.MultiRequest;
import com.moing.backend.global.config.fcm.service.FcmService;
import com.moing.backend.global.response.BaseServiceResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.EventListener;
import java.util.List;
import java.util.Optional;

Expand All @@ -24,20 +27,16 @@
public class SendMissionCreateAlarmUseCase {

private final TeamMemberGetService teamMemberGetService;
private final FcmService fcmService;
private final ApplicationEventPublisher eventPublisher;

public void sendNewMissionUploadAlarm(Member member, Mission mission) {
Team team = mission.getTeam();
Optional<List<String>> fcmTokensExceptMe = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());

String title = team.getName() + " " + NEW_SINGLE_MISSION_COMING.getTitle();
String message = mission.getTitle();

Optional<List<String>> fcmTokens = teamMemberGetService.getFcmTokensExceptMe(team.getTeamId(), member.getMemberId());
if (fcmTokens.isPresent() && !fcmTokens.get().isEmpty()) {
MultiRequest toMultiRequest = new MultiRequest(fcmTokens.get(), title, message);
fcmService.sendMultipleDevices(toMultiRequest);

eventPublisher.publishEvent(new FcmEvent(title, message, fcmTokens.get()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,4 @@ public void setTeam(Team team) {
public void updateStatus(MissionStatus missionStatus) {
this.status = missionStatus;
}

public void makeEnd() {
this.status = MissionStatus.END;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.moing.backend.domain.mission.application.dto.res.GatherRepeatMissionRes;
import com.moing.backend.domain.mission.application.dto.res.GatherSingleMissionRes;
import com.moing.backend.domain.mission.application.dto.res.MissionReadRes;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import org.springframework.stereotype.Repository;
Expand All @@ -25,5 +26,7 @@ public interface MissionCustomRepository {

boolean findRepeatMissionsByTeamId(Long teamId);

Optional<MissionReadRes> findByIds(Long memberId, Long missionId);


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import com.moing.backend.domain.mission.application.dto.res.GatherRepeatMissionRes;
import com.moing.backend.domain.mission.application.dto.res.GatherSingleMissionRes;
import com.moing.backend.domain.mission.application.dto.res.MissionReadRes;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.mission.domain.entity.constant.MissionType;
import com.moing.backend.domain.missionState.domain.entity.QMissionState;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;

Expand Down Expand Up @@ -138,4 +140,26 @@ public boolean findRepeatMissionsByTeamId(Long teamId) {
).fetchCount() > 2;
}

@Override
public Optional<MissionReadRes> findByIds(Long memberId, Long missionId) {


BooleanExpression isLeader = mission.team.leaderId.eq(memberId);

return Optional.ofNullable(queryFactory
.select(Projections.constructor(MissionReadRes.class,
mission.title,
mission.dueTo.stringValue(),
mission.rule,
mission.content,
mission.type.stringValue(),
mission.way.stringValue(),
isLeader))
.from(mission)
.where(mission.id.eq(missionId))
.fetchOne()
);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.mission.application.dto.res.GatherRepeatMissionRes;
import com.moing.backend.domain.mission.application.dto.res.GatherSingleMissionRes;
import com.moing.backend.domain.mission.application.dto.res.MissionReadRes;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.mission.exception.*;
Expand All @@ -28,6 +29,9 @@ public class MissionQueryService {
public Mission findMissionById(Long missionId) {
return missionRepository.findById(missionId).orElseThrow(NotFoundMissionException::new);
}
public MissionReadRes findMissionByIds(Long memberId, Long missionId) {
return missionRepository.findByIds(memberId,missionId).orElseThrow(NotFoundMissionException::new);
}

public Long findMissionsCountByTeam(Long teamId) {
return missionRepository.findMissionsCountByTeam(teamId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ public ResponseEntity<SuccessResponse<MissionCreateRes>> updateMission(@Authenti
return ResponseEntity.ok(SuccessResponse.create(UPDATE_MISSION_SUCCESS.getMessage(), this.missionUpdateUseCase.updateMission(user.getSocialId(),missionId, missionReq)));
}

/**
* 미션 종료
* [PUT] {teamId}/missions/{missionId}/end
* 작성자 : 정승연
*/
@PutMapping("/{missionId}/end")
public ResponseEntity<SuccessResponse<MissionReadRes>> endMission(@AuthenticationPrincipal User user,@PathVariable("teamId") Long teamId,@PathVariable Long missionId) {
return ResponseEntity.ok(SuccessResponse.create(END_MISSION_SUCCESS.getMessage(), this.missionUpdateUseCase.updateMissionStatus(user.getSocialId(),missionId)));
}

/**
* 미션 삭제
* [DELETE] {teamId}/missions/{missionId}
Expand All @@ -86,4 +96,9 @@ public ResponseEntity<SuccessResponse<String>> recommendMission(@AuthenticationP
}







}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public enum MissionResponseMessage {
CREATE_MISSION_SUCCESS("미션 생성을 완료 했습니다"),
READ_MISSION_SUCCESS("미션 조회를 완료 했습니다"),
UPDATE_MISSION_SUCCESS("미션 수정을 완료 했습니다"),
END_MISSION_SUCCESS("미션 종료를 완료 했습니다"),
DELETE_MISSION_SUCCESS("미션 삭제를 완료 했습니다"),
RECOMMEND_MISSION_SUCCESS("미션 추천을 위한 팀 카테고리를 조회 했습니다");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class MissionArchiveDeleteUseCase {
private final MissionStateQueryService missionStateQueryService;


public Long deleteArchive(String userSocialId, Long missionId) {
public Long deleteArchive(String userSocialId, Long missionId,Long count) {

Member member = memberGetService.getMemberBySocialId(userSocialId);
Long memberId = member.getMemberId();
Expand All @@ -63,7 +63,7 @@ public Long deleteArchive(String userSocialId, Long missionId) {

}

MissionArchive deleteArchive = missionArchiveQueryService.findMyArchive(memberId, missionId).get(0);
MissionArchive deleteArchive = missionArchiveQueryService.findOneMyArchive(memberId, missionId,count).get(0);
missionArchiveDeleteService.deleteMissionArchive(deleteArchive);

MissionState missionState = missionStateQueryService.findMissionState(member, mission);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface MissionArchiveCustomRepository {
Optional<List<SingleMissionBoardRes>> findSingleMissionInComplete(Long memberId, Long teamId, MissionStatus status,OrderCondition orderCondition);
Optional<List<SingleMissionBoardRes>> findSingleMissionComplete(Long memberId, Long teamId, MissionStatus status,OrderCondition orderCondition);
Optional<List<MissionArchive>> findMyArchives(Long memberId,Long missionId);
Optional<List<MissionArchive>> findOneMyArchives(Long memberId,Long missionId,Long count);

Optional<List<MissionArchive>> findOthersArchives(Long memberId, Long missionId) ;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,23 @@ private OrderSpecifier[] createOrderSpecifier(OrderCondition orderCondition) {
}

@Override
public Optional<List<MissionArchive>> findOneMyArchives(Long memberId,Long missionId,Long count) {

return Optional.ofNullable(queryFactory
.select(missionArchive)
.from(missionArchive)
.where(
missionArchive.mission.id.eq(missionId),
missionArchive.member.memberId.eq(memberId),
missionArchive.count.eq(count)
)
.orderBy(missionArchive.createdDate.desc())
.fetch()

);
}

@Override
public Optional<List<MissionArchive>> findMyArchives(Long memberId,Long missionId) {

return Optional.ofNullable(queryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,19 @@ public MissionArchive findArchive(Long memberId, Long missionId) {
public List<MissionArchive> findMyArchive(Long memberId, Long missionId) {

Optional<List<MissionArchive>> optional = missionArchiveRepository.findMyArchives(memberId, missionId);

if (optional.isPresent() && optional.get().size() == 0) {
return new ArrayList<>();
} else {
return optional.get();
}
}
public List<MissionArchive> findOneMyArchive(Long memberId, Long missionId, Long count) {

Optional<List<MissionArchive>> optional = missionArchiveRepository.findMyArchives(memberId, missionId);

if (optional.isPresent() && optional.get().size() == 0) {
return new ArrayList<>();
// throw new NotFoundMissionArchiveException();
} else {
return optional.get();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ public ResponseEntity<SuccessResponse<MissionArchiveRes>> updateArchive(@Authent
* 작성자 : 정승연
**/

@DeleteMapping()
@DeleteMapping("/{count}")
public ResponseEntity<SuccessResponse<Long>> deleteArchive(@AuthenticationPrincipal User user,
@PathVariable("teamId") Long teamId,
@PathVariable("missionId") Long missionId) {
return ResponseEntity.ok(SuccessResponse.create(UPDATE_ARCHIVE_SUCCESS.getMessage(), this.missionArchiveDeleteUseCase.deleteArchive(user.getSocialId(), missionId)));
@PathVariable("teamId") Long teamId,
@PathVariable("missionId") Long missionId,
@PathVariable("count") Long count) {
return ResponseEntity.ok(SuccessResponse.create(DELETE_ARCHIVE_SUCCESS.getMessage(), this.missionArchiveDeleteUseCase.deleteArchive(user.getSocialId(), missionId,count)));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void RepeatMissionStart() {
// @Scheduled(cron = "8 0 0 * * *")
// public void MissionRemindAlarm() {
//
//
// missionRemindAlarmUseCase.sendRemindMissionAlarm();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void updateCount(Long count){
}

public void updateMemberName(String nickName){
this.memberName=memberName;
this.memberName=nickName;
}

@QueryProjection
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
public interface TeamMemberCustomRepository {
List<Long> findMemberIdsByTeamId(Long teamId);
Optional<List<String>> findFcmTokensByTeamIdAndMemberId(Long teamId, Long memberId);
Optional<List<String>> findFcmTokensByTeamId(Long teamId);
List<TeamMemberInfo> findTeamMemberInfoByTeamId(Long teamId);
List<TeamMember> findTeamMemberByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,8 @@ public Optional<List<String>> findFcmTokensByTeamIdAndMemberId(Long teamId, Long
.from(teamMember)
.where(teamMember.team.teamId.eq(teamId)
.and(teamMember.member.isNewUploadPush.eq(true))
.and(teamMember.member.memberId.ne(memberId)))
.fetch();

return result.isEmpty() ? Optional.empty() : Optional.of(result);
}

@Override
public Optional<List<String>> findFcmTokensByTeamId(Long teamId) {
List<String> result = queryFactory.select(teamMember.member.fcmToken)
.from(teamMember)
.where(teamMember.team.teamId.eq(teamId)
.and(teamMember.member.isNewUploadPush.eq(true)))
.and(teamMember.member.memberId.ne(memberId))
.and(teamMember.isDeleted.eq(false)))
.fetch();

return result.isEmpty() ? Optional.empty() : Optional.of(result);
Expand Down
Loading

0 comments on commit 6b63796

Please sign in to comment.