-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 미션 상세 조회 서비스 구현 * test: 미션 상세 조회 api 테스트 * feat: mission api swagger 적용
- Loading branch information
Showing
8 changed files
with
175 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 22 additions & 1 deletion
23
backend/src/main/java/develup/application/mission/MissionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,42 @@ | ||
package develup.application.mission; | ||
|
||
import java.util.List; | ||
import develup.api.exception.DevelupException; | ||
import develup.api.exception.ExceptionType; | ||
import develup.application.auth.Accessor; | ||
import develup.domain.mission.Mission; | ||
import develup.domain.mission.MissionRepository; | ||
import develup.domain.solution.SolutionRepository; | ||
import develup.domain.solution.SolutionStatus; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class MissionService { | ||
|
||
private final MissionRepository missionRepository; | ||
private final SolutionRepository solutionRepository; | ||
|
||
public MissionService(MissionRepository missionRepository) { | ||
public MissionService(MissionRepository missionRepository, SolutionRepository solutionRepository) { | ||
this.missionRepository = missionRepository; | ||
this.solutionRepository = solutionRepository; | ||
} | ||
|
||
public List<MissionResponse> getMissions() { | ||
return missionRepository.findAll().stream() | ||
.map(MissionResponse::from) | ||
.toList(); | ||
} | ||
|
||
public MissionWithStartedResponse getMission(Accessor accessor, Long missionId) { | ||
Mission mission = missionRepository.findById(missionId) | ||
.orElseThrow(() -> new DevelupException(ExceptionType.MISSION_NOT_FOUND)); | ||
|
||
if (accessor.isGuest()) { | ||
return MissionWithStartedResponse.guest(mission); | ||
} | ||
|
||
boolean isStarted = solutionRepository | ||
.existsByMember_IdAndMission_IdAndStatus(accessor.id(), missionId, SolutionStatus.IN_PROGRESS); | ||
return MissionWithStartedResponse.of(mission, isStarted); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/develup/application/mission/MissionWithStartedResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package develup.application.mission; | ||
|
||
import develup.domain.mission.Mission; | ||
|
||
public record MissionWithStartedResponse( | ||
Long id, | ||
String title, | ||
String descriptionUrl, | ||
String thumbnail, | ||
String url, | ||
boolean isStarted | ||
) { | ||
|
||
public static MissionWithStartedResponse of(Mission mission, boolean isStarted) { | ||
return new MissionWithStartedResponse( | ||
mission.getId(), | ||
mission.getTitle(), | ||
mission.getDescriptionUrl(), | ||
mission.getThumbnail(), | ||
mission.getUrl(), | ||
isStarted | ||
); | ||
} | ||
|
||
public static MissionWithStartedResponse guest(Mission mission) { | ||
return of(mission, false); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/develup/domain/solution/SolutionRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package develup.domain.solution; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface SolutionRepository extends JpaRepository<Solution, Long> { | ||
|
||
boolean existsByMember_IdAndMission_IdAndStatus(Long memberId, Long missionId, SolutionStatus status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
spring: | ||
profiles: | ||
active: local | ||
group: | ||
local: local, common | ||
dev: dev, common |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters