Skip to content

Commit

Permalink
Merge pull request #48 from Modagbul/feat/mission
Browse files Browse the repository at this point in the history
feat : mission 관련 dto 객체 lombok 추가 및 API 문서 수정 /  팀별 미션 인증물 리턴
  • Loading branch information
seungueonn authored Oct 30, 2023
2 parents a12dbbd + 3e1dc8c commit 2a28f81
Show file tree
Hide file tree
Showing 17 changed files with 192 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.moing.backend.domain.mission.application.dto.req;

import lombok.Builder;
import lombok.Getter;
import lombok.*;

@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
public class MissionReq {

private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
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 com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes;
import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,7 +21,9 @@
public class MissionGatherBoardUseCase {

private final MissionQueryService missionQueryService;
private final MissionArchiveQueryService missionArchiveQueryService;
private final MemberGetService memberGetService;
private final TeamGetService teamGetService;

public List<GatherSingleMissionRes> getAllActiveSingleMissions(String userId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();
Expand All @@ -30,6 +36,15 @@ public List<GatherRepeatMissionRes> getAllActiveRepeatMissions(String userId) {

}

public List<MissionArchivePhotoRes> getArchivePhotoByTeamRes(String userId) {
Long memberId = memberGetService.getMemberBySocialId(userId).getMemberId();

List<Long> teamIdByMemberId = teamGetService.getTeamIdByMemberId(memberId);

return missionArchiveQueryService.findTop5ArchivesByTeam(teamIdByMemberId);
}




}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.moing.backend.domain.missionArchive.application.dto.req;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
public class MissionArchiveReq {

private String status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.moing.backend.domain.missionArchive.application.dto.res;

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

import java.util.List;

@Builder
@Getter
@NoArgsConstructor
@AllArgsConstructor
public class MissionArchivePhotoRes {
Long teamId;
List<String> photo;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.moing.backend.domain.missionArchive.application.dto.res;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

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

@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
@Setter
public class MissionArchiveRes {

private Long archiveId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.moing.backend.domain.missionArchive.application.dto.res;

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

@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
public class MissionArchiveStatusRes {
private String total;
private String done;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.moing.backend.domain.missionArchive.application.dto.res;

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.*;

@Getter
@Setter
@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
public class PersonalArchiveRes {

private Long archiveId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import com.moing.backend.domain.member.domain.service.MemberGetService;
import com.moing.backend.domain.mission.domain.entity.Mission;
import com.moing.backend.domain.mission.domain.service.MissionQueryService;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes;
import com.moing.backend.domain.missionArchive.application.dto.res.PersonalArchiveRes;
import com.moing.backend.domain.missionArchive.application.mapper.MissionArchiveMapper;
import com.moing.backend.domain.missionArchive.domain.service.MissionArchiveQueryService;
import com.moing.backend.domain.team.domain.entity.Team;
import com.moing.backend.domain.team.domain.repository.TeamRepository;
import com.moing.backend.domain.team.domain.service.TeamGetService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -27,15 +29,15 @@ public class MissionArchiveReadUseCase {
private final MemberGetService memberGetService;
private final MissionQueryService missionQueryService;
private final MissionArchiveQueryService missionArchiveQueryService;
private final TeamRepository teamRepository;
private final TeamGetService teamGetService;


// 미션 인증 조회
public List<MissionArchiveRes> getMyArchive(String userSocialId, Long missionId) {

Long memberId = memberGetService.getMemberBySocialId(userSocialId).getMemberId();

return MissionArchiveMapper.mapToMissionArchiveResList(missionArchiveQueryService.findMyArchive(memberId, missionId),memberId);
return MissionArchiveMapper.mapToMissionArchiveResList(missionArchiveQueryService.findMyArchive(memberId, missionId), memberId);
}

// 모두의 미션 인증 목록 조회
Expand All @@ -44,7 +46,7 @@ public List<PersonalArchiveRes> getPersonalArchive(String userSocialId, Long mis
List<PersonalArchiveRes> personalArchives = new ArrayList<>();

Long memberId = memberGetService.getMemberBySocialId(userSocialId).getMemberId();
return MissionArchiveMapper.mapToPersonalArchiveList(missionArchiveQueryService.findOthersArchive(memberId, missionId),memberId);
return MissionArchiveMapper.mapToPersonalArchiveList(missionArchiveQueryService.findOthersArchive(memberId, missionId), memberId);
}

public MissionArchiveStatusRes getMissionDoneStatus(Long missionId) {
Expand All @@ -59,4 +61,6 @@ public MissionArchiveStatusRes getMissionDoneStatus(Long missionId) {
}




}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public enum MissionArchiveResponseMessage {
MISSION_ARCHIVE_PEOPLE_STATUS_SUCCESS("미션 인증 성공한 인원 상태 조회를 완료 했습니다."),
ACTIVE_SINGLE_MISSION_SUCCESS("진행 중인 한번 인증 미션 조회를 완료 했습니다."),
ACTIVE_REPEAT_MISSION_SUCCESS("진행 중인 반복 인증 미션 조회를 완료 했습니다."),
FINISH_ALL_MISSION_SUCCESS("종료된 미션 조회를 완료하였습니다.");
FINISH_ALL_MISSION_SUCCESS("종료된 미션 조회를 완료하였습니다."),
MISSION_ARCHIVE_BY_TEAM("팀별 미션 인증물 사진 조회를 완료했습니더.");

private final String message;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.moing.backend.domain.missionArchive.domain.repository;

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.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus;
import org.springframework.stereotype.Repository;
Expand All @@ -24,5 +24,7 @@ public interface MissionArchiveCustomRepository {

Optional<List<FinishMissionBoardRes>> findFinishMissionsByStatus(Long memberId, Long teamId);

Optional<List<MissionArchivePhotoRes>> findTop5ArchivesByTeam(List<Long> teamIds);


}
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
package com.moing.backend.domain.missionArchive.domain.repository;

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.constant.MissionStatus;
import com.moing.backend.domain.mission.domain.entity.constant.MissionType;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchiveStatus;
import com.moing.backend.domain.team.domain.entity.Team;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Expression;
import com.querydsl.core.types.Order;
import com.querydsl.core.types.OrderSpecifier;
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import feign.Param;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.EntityManager;
import java.util.ArrayList;
Expand All @@ -26,7 +22,6 @@

import static com.moing.backend.domain.mission.domain.entity.QMission.mission;
import static com.moing.backend.domain.missionArchive.domain.entity.QMissionArchive.*;
import static com.moing.backend.domain.missionHeart.domain.entity.QMissionHeart.missionHeart;
import static javax.swing.Spring.constant;

public class MissionArchiveCustomRepositoryImpl implements MissionArchiveCustomRepository {
Expand Down Expand Up @@ -181,4 +176,38 @@ public Optional<List<FinishMissionBoardRes>> findFinishMissionsByStatus(Long mem
}


public Optional<List<MissionArchivePhotoRes>> findTop5ArchivesByTeam(List<Long> teamIds) {
List<Tuple> queryResults = queryFactory
.select(missionArchive.mission.team.teamId, missionArchive.archive)
.from(missionArchive)
.where(missionArchive.mission.team.teamId.in(teamIds))
.orderBy(missionArchive.createdDate.desc())
.limit(14)
.fetch();

List<MissionArchivePhotoRes> resultDTOs = new ArrayList<>();

for (Tuple tuple : queryResults) {
Long teamId = tuple.get(missionArchive.mission.team.teamId);
String photo = tuple.get(missionArchive.archive);

// Check if a TeamPhotoDTO with the same teamId already exists in the list
MissionArchivePhotoRes existingDTO = resultDTOs.stream()
.filter(dto -> dto.getTeamId().equals(teamId))
.findFirst()
.orElse(null);

if (existingDTO != null) {
existingDTO.getPhoto().add(photo);
} else {
List<String> photoList = new ArrayList<>();
photoList.add(photo);
resultDTOs.add(new MissionArchivePhotoRes(teamId, photoList));
}
}

return Optional.ofNullable(resultDTOs);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes;
import com.moing.backend.domain.mission.domain.entity.constant.MissionStatus;
import com.moing.backend.domain.mission.domain.repository.MissionRepository;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes;
import com.moing.backend.domain.missionArchive.domain.entity.MissionArchive;
import com.moing.backend.domain.missionArchive.domain.repository.MissionArchiveRepository;
import com.moing.backend.domain.missionArchive.exception.NotFoundMissionArchiveException;
Expand Down Expand Up @@ -99,6 +100,9 @@ public List<FinishMissionBoardRes> findMyFinishMissions(Long memberId, Long team
return missionArchiveRepository.findFinishMissionsByStatus(memberId, teamId).orElseThrow(NotFoundMissionArchiveException::new);
}

public List<MissionArchivePhotoRes> findTop5ArchivesByTeam(List<Long> teamIds) {
return missionArchiveRepository.findTop5ArchivesByTeam(teamIds).orElse(null);
}



Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.moing.backend.domain.missionArchive.presentation;

import com.moing.backend.domain.mission.application.dto.res.GatherRepeatMissionRes;
import com.moing.backend.domain.missionArchive.application.dto.req.MissionArchiveReq;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveRes;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchiveStatusRes;
Expand Down Expand Up @@ -131,4 +132,6 @@ public ResponseEntity<SuccessResponse<MissionArchiveStatusRes>> getMyMissionDone





}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.moing.backend.domain.mission.application.dto.res.RepeatMissionBoardRes;
import com.moing.backend.domain.mission.application.service.MissionArchiveBoardUseCase;
import com.moing.backend.domain.mission.application.service.MissionGatherBoardUseCase;
import com.moing.backend.domain.missionArchive.application.dto.res.MissionArchivePhotoRes;
import com.moing.backend.domain.missionArchive.application.service.MissionArchiveReadUseCase;
import com.moing.backend.global.config.security.dto.User;
import com.moing.backend.global.response.SuccessResponse;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -50,4 +52,14 @@ public ResponseEntity<SuccessResponse<List<GatherRepeatMissionRes>>> getMyActive
}


@GetMapping("/my-teams")
public ResponseEntity<SuccessResponse<List<MissionArchivePhotoRes>>> getArchivesByTeam(@AuthenticationPrincipal User user) {
return ResponseEntity.ok(SuccessResponse.create(MISSION_ARCHIVE_BY_TEAM.getMessage(), this.missionGatherBoardUseCase.getArchivePhotoByTeamRes(user.getSocialId())));
}






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

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

@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
@Getter
public class MissionHeartRes {
private Long missionArchiveId;
private String missionHeartStatus;
Expand Down
Loading

0 comments on commit 2a28f81

Please sign in to comment.