Skip to content

Commit

Permalink
Merge pull request #39 from Modagbul/feat/mission_archive
Browse files Browse the repository at this point in the history
feat : 미션 인증 좋아요, 미션 모아보기(단일,반복)
  • Loading branch information
minsu20 authored Oct 20, 2023
2 parents 9c7bfb0 + eeab55e commit ef1d274
Show file tree
Hide file tree
Showing 41 changed files with 783 additions and 200 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ out/
application.yml
application-local.yml
.DS_Store
firebase-key.json
src/main/resources/firebase-key.json

src/test/resources/
.jpb
Expand Down
16 changes: 16 additions & 0 deletions src/docs/asciidoc/MissionGatherBoard-API.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


[[MissionGatherBoard-API]]
= MissionBoard API

[[MissionBoard-미션-모아보기-단일]]
=== 미션_모아보기_단일_미션
operation::mission-gather-controller-test/미션_모아보기_단일_미션[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

---

[[MissionBoard-미션-모아보기-반복]]
=== 미션_모아보기_반복_미션
operation::mission-gather-controller-test/미션_모아보기_반복_미션[snippets='http-request,path-parameters,request-fields,http-response,response-fields']

---
2 changes: 2 additions & 0 deletions src/docs/asciidoc/api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ include::MissionArchive-API.adoc[]

include::MissionBoard-API.adoc[]

include::MissionGatherBoard-API.adoc[]

include::Fire-API.adoc[]

include::Board-API.adoc[]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.moing.backend.domain.mission.application.dto.res;

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

@Getter
@Builder
@AllArgsConstructor
public class GatherRepeatMissionRes {

private Long missionId;
private String teamName;
private String missionTitle;
private String totalNum;
private String doneNum;

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

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

@Getter
@Builder
@AllArgsConstructor
public class GatherSingleMissionRes {
private Long missionId;
private String teamName;
private String missionTitle;
private String dueTo;


}
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.member.domain.service.MemberGetService;
import com.moing.backend.domain.mission.application.dto.res.FinishMissionBoardRes;
import com.moing.backend.domain.mission.application.dto.res.GatherSingleMissionRes;
import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes;
import com.moing.backend.domain.mission.application.dto.res.SingleMissionBoardRes;
import com.moing.backend.domain.mission.domain.entity.Mission;
Expand Down Expand Up @@ -80,4 +81,7 @@ public List<RepeatMissionBoardRes> getActiveRepeatMissions(Long teamId, String m

}




}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.moing.backend.domain.mission.application.service;

import com.moing.backend.domain.member.domain.entity.Member;
import com.moing.backend.domain.member.domain.service.MemberGetService;
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.domain.service.MissionQueryService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
@RequiredArgsConstructor
public class MissionGatherBoardUseCase {

private final MissionQueryService missionQueryService;
private final MemberGetService memberGetService;

public List<GatherSingleMissionRes> getAllActiveSingleMissions(String userId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();
return missionQueryService.findAllSingleMission(memberId);

}
public List<GatherRepeatMissionRes> getAllActiveRepeatMissions(String userId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();
return missionQueryService.findAllRepeatMission(memberId);

}



}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.moing.backend.domain.mission.domain.repository;

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.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import org.springframework.stereotype.Repository;
Expand All @@ -10,6 +12,10 @@
@Repository
public interface MissionCustomRepository {
Long findMissionsCountByTeam(Long teamId);
Optional<List<Mission>> findRepeatMissionByMemberId(Long teamId, MissionStatus status);

Optional<List<GatherSingleMissionRes>> findSingleMissionByMemberId(Long memberId, List<Long> teams);

Optional<List<GatherRepeatMissionRes>> findRepeatMissionByMemberId(Long memberId, List<Long>teams);


}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.moing.backend.domain.mission.domain.repository;

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.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.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQueryFactory;

import javax.persistence.EntityManager;
Expand All @@ -11,6 +14,7 @@
import java.util.Optional;

import static com.moing.backend.domain.mission.domain.entity.QMission.mission;
import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.missionArchive;

public class MissionCustomRepositoryImpl implements MissionCustomRepository{

Expand All @@ -32,16 +36,47 @@ public Long findMissionsCountByTeam(Long teamId) {
}

@Override
public Optional<List<Mission>> findRepeatMissionByMemberId(Long teamId, MissionStatus status) {
public Optional<List<GatherRepeatMissionRes>> findRepeatMissionByMemberId(Long memberId,List<Long>teams) {

return Optional.ofNullable(queryFactory
.select(mission)
.select(Projections.constructor(GatherRepeatMissionRes.class,
mission.id,
mission.team.name,
mission.title,
mission.number.stringValue(),
missionArchive.count().stringValue()

))
.from(mission)
.leftJoin(missionArchive)
.on(missionArchive.mission.eq(mission), missionArchive.member.memberId.eq(memberId))
.where(
mission.team.teamId.eq(teamId),
mission.status.eq(status),
mission.team.teamId.in(teams),
mission.status.eq(MissionStatus.ONGOING),
mission.type.eq(MissionType.REPEAT)
)
.groupBy(mission.id)
.fetch());
}

@Override
public Optional<List<GatherSingleMissionRes>> findSingleMissionByMemberId(Long memberId, List<Long> teams) {
return Optional.ofNullable(queryFactory
.select(Projections.constructor(GatherSingleMissionRes.class,
mission.id,
mission.team.name,
mission.title,
mission.dueTo.stringValue()
))
.from(mission)
.where(
mission.team.teamId.in(teams),
mission.status.eq(MissionStatus.ONGOING),
mission.type.eq(MissionType.ONCE)

)
.fetch()

);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package com.moing.backend.domain.mission.domain.service;

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.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.mission.exception.NotFoundMissionException;
import com.moing.backend.domain.mission.domain.repository.MissionRepository;
import com.moing.backend.domain.team.application.dto.response.GetTeamResponse;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import com.moing.backend.global.annotation.DomainService;
import lombok.RequiredArgsConstructor;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@DomainService
Expand All @@ -16,6 +22,7 @@
public class MissionQueryService {

private final MissionRepository missionRepository;
private final TeamGetService teamGetService;

public Mission findMissionById(Long missionId) {
return missionRepository.findById(missionId).orElseThrow(NotFoundMissionException::new);
Expand All @@ -25,7 +32,13 @@ public Long findMissionsCountByTeam(Long teamId) {
return missionRepository.findMissionsCountByTeam(teamId);
}

public List<Mission> findRepeatMissionByTeamId(Long teamId) {
return missionRepository.findRepeatMissionByMemberId(teamId, MissionStatus.ONGOING).orElseThrow(NotFoundMissionException::new);
public List<GatherRepeatMissionRes> findAllRepeatMission(Long memberId) {
List<Long> teams = teamGetService.getTeamIdByMemberId(memberId);
return missionRepository.findRepeatMissionByMemberId(memberId,teams).orElseThrow(NotFoundMissionException::new);
}

public List<GatherSingleMissionRes> findAllSingleMission(Long memberId) {
List<Long> teams = teamGetService.getTeamIdByMemberId(memberId);
return missionRepository.findSingleMissionByMemberId(memberId, teams).orElseThrow(NotFoundMissionException::new);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

@RestController
@AllArgsConstructor
@RequestMapping("/api/{teamId}/missions")
@RequestMapping("/api/team/{teamId}/missions")
public class MissionController {


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Getter;
import lombok.Setter;

import javax.annotation.Nullable;
import java.util.List;

@Builder
Expand All @@ -14,9 +15,18 @@ public class MissionArchiveRes {
private Long archiveId;
private String archive;
private String createdDate;
private int hearts;
private String status;
private Long count;
private String heartStatus;
private Long hearts;

public void updateHeartStatus(boolean status) {
if (status) {
this.heartStatus = "True";
}else{
this.heartStatus = "False";
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class PersonalArchiveRes {
private String archive;
private String createdDate;

private String heartStatus;
private int hearts;

private String status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus;
import com.moing.backend.domain.missionHeart.domain.constant.MissionHeartStatus;
import com.moing.backend.global.annotation.Mapper;

import java.util.ArrayList;
Expand All @@ -25,47 +26,58 @@ public static MissionArchive mapToMissionArchive(MissionArchiveReq missionArchiv
.status(MissionArchiveStatus.valueOf(missionArchiveReq.getStatus()))
.member(member)
.mission(mission)
.heartList(new ArrayList<>())
.build();
}

public static MissionArchiveRes mapToMissionArchiveRes(MissionArchive missionArchive) {
public static MissionArchiveRes mapToMissionArchiveRes(MissionArchive missionArchive,Long memberId) {
return MissionArchiveRes.builder()
.archiveId(missionArchive.getId())
.archive(missionArchive.getArchive())
.createdDate(missionArchive.getCreatedDate().toString())
.hearts(missionArchive.getHearts())
.status(missionArchive.getStatus().name())
.count(missionArchive.getCount())
.heartStatus(
String.valueOf(missionArchive.getHeartList().stream().anyMatch(
missionHeart -> missionHeart.getPushMemberId().equals(memberId) &&
missionHeart.getHeartStatus().equals(MissionHeartStatus.True)
)))
.hearts(missionArchive.getHeartList().stream().filter(
missionHeart -> missionHeart.getHeartStatus().equals(MissionHeartStatus.True)
).count())
.build();
}

public static List<MissionArchiveRes> mapToMissionArchiveResList(List<MissionArchive> missionArchiveList) {
public static List<MissionArchiveRes> mapToMissionArchiveResList(List<MissionArchive> missionArchiveList,Long memberId) {
List<MissionArchiveRes> missionArchiveResList = new ArrayList<>();
missionArchiveList.forEach(
missionArchive -> missionArchiveResList.add(MissionArchiveMapper.mapToMissionArchiveRes(missionArchive))
missionArchive -> missionArchiveResList.add(MissionArchiveMapper.mapToMissionArchiveRes(missionArchive,memberId))
);
return missionArchiveResList;
}


public static PersonalArchiveRes mapToPersonalArchive(MissionArchive missionArchive) {
public static PersonalArchiveRes mapToPersonalArchive(MissionArchive missionArchive,Long memberId) {
Member member = missionArchive.getMember();
return PersonalArchiveRes.builder()
.archiveId(missionArchive.getId())
.nickname(member.getNickName())
.profileImg(member.getProfileImage())
.archive(missionArchive.getArchive())
.createdDate(missionArchive.getCreatedDate().toString())
.hearts(missionArchive.getHearts())
.status(missionArchive.getStatus().name())
.count(missionArchive.getCount())
.heartStatus(
String.valueOf(missionArchive.getHeartList().stream().anyMatch(
missionHeart -> missionHeart.getPushMemberId().equals(memberId))))
.hearts(missionArchive.getHeartList().size())
.build();
}

public static List<PersonalArchiveRes> mapToPersonalArchiveList(List<MissionArchive> missionArchiveList) {
public static List<PersonalArchiveRes> mapToPersonalArchiveList(List<MissionArchive> missionArchiveList,Long memberId) {
List<PersonalArchiveRes> personalArchiveList = new ArrayList<>();
missionArchiveList.forEach(
missionArchive -> personalArchiveList.add(MissionArchiveMapper.mapToPersonalArchive(missionArchive))
missionArchive -> personalArchiveList.add(MissionArchiveMapper.mapToPersonalArchive(missionArchive,memberId))
);
return personalArchiveList;
}
Expand Down Expand Up @@ -96,7 +108,6 @@ public static List<SingleMissionBoardRes> mapToSingleMissionBoardResList( List<M
public static MissionArchiveHeartRes mapToMissionArchiveHeartRes(MissionArchive missionArchive,Boolean heartStatus) {
return MissionArchiveHeartRes.builder()
.archiveId(missionArchive.getId())
.hearts(missionArchive.getHearts())
.heartStatus(heartStatus.toString())
.build();
}
Expand Down
Loading

0 comments on commit ef1d274

Please sign in to comment.