-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[Feat] 챌린지 그룹 상세조회 api 개발
- Loading branch information
Showing
11 changed files
with
200 additions
and
14 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
7 changes: 7 additions & 0 deletions
7
...pp/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupImageReader.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,7 @@ | ||
package org.haedal.zzansuni.domain.challengegroup; | ||
|
||
import java.util.List; | ||
|
||
public interface ChallengeGroupImageReader { | ||
List<ChallengeGroupImage> getByChallengeGroupId(Long challengeGroupId); | ||
} |
77 changes: 77 additions & 0 deletions
77
...rver/app/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupModel.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,77 @@ | ||
package org.haedal.zzansuni.domain.challengegroup; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import org.haedal.zzansuni.domain.challengegroup.challenge.ChallengeModel; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public class ChallengeGroupModel { | ||
@Builder | ||
@Getter | ||
public static class Main { | ||
private Long id; | ||
private ChallengeCategory category; | ||
private String title; | ||
private String content; | ||
private Integer cumulativeCount; | ||
|
||
public static Main from(ChallengeGroup challengeGroup) { | ||
return Main.builder() | ||
.id(challengeGroup.getId()) | ||
.category(challengeGroup.getCategory()) | ||
.title(challengeGroup.getTitle()) | ||
.content(challengeGroup.getContent()) | ||
.cumulativeCount(challengeGroup.getCumulativeCount()) | ||
.build(); | ||
} | ||
} | ||
|
||
@Getter | ||
@Builder | ||
public static class Detail { | ||
private Long id; | ||
private ChallengeCategory category; | ||
private String title; | ||
private String content; | ||
private String guide; | ||
private Integer cumulativeCount; | ||
private List<String> imageUrls; | ||
private List<ChallengeModel> challenges; | ||
|
||
public LocalDate getMinStartDate() { | ||
return challenges.stream() | ||
.map(ChallengeModel::getStartDate) | ||
.min(LocalDate::compareTo) | ||
.orElse(LocalDate.now()); | ||
} | ||
|
||
public LocalDate getMaxEndDate() { | ||
return challenges.stream() | ||
.map(ChallengeModel::getEndDate) | ||
.max(LocalDate::compareTo) | ||
.orElse(LocalDate.now()); | ||
} | ||
|
||
public static Detail from(ChallengeGroup challengeGroup, List<ChallengeGroupImage> challengeGroupImages) { | ||
var challenges = challengeGroup.getChallenges().stream() | ||
.map(ChallengeModel::from) | ||
.toList(); | ||
var imageUrls = challengeGroupImages.stream() | ||
.map(ChallengeGroupImage::getImageUrl) | ||
.toList(); | ||
return Detail.builder() | ||
.id(challengeGroup.getId()) | ||
.category(challengeGroup.getCategory()) | ||
.title(challengeGroup.getTitle()) | ||
.content(challengeGroup.getContent()) | ||
.guide(challengeGroup.getGuide()) | ||
.cumulativeCount(challengeGroup.getCumulativeCount()) | ||
.imageUrls(imageUrls) | ||
.challenges(challenges) | ||
.build(); | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...p/src/main/java/org/haedal/zzansuni/domain/challengegroup/ChallengeGroupQueryService.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,21 @@ | ||
package org.haedal.zzansuni.domain.challengegroup; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ChallengeGroupQueryService { | ||
private final ChallengeGroupReader challengeGroupReader; | ||
private final ChallengeGroupImageReader challengeGroupImageReader; | ||
|
||
@Transactional(readOnly = true) | ||
public ChallengeGroupModel.Detail getChallengeGroupDetail(Long challengeGroupId) { | ||
ChallengeGroup challengeGroup = challengeGroupReader.getById(challengeGroupId); | ||
List<ChallengeGroupImage> challengeGroupImages = challengeGroupImageReader.getByChallengeGroupId(challengeGroupId); | ||
return ChallengeGroupModel.Detail.from(challengeGroup, challengeGroupImages); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...java/org/haedal/zzansuni/infrastructure/challengegroup/ChallengeGroupImageReaderImpl.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,18 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupImage; | ||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupImageReader; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class ChallengeGroupImageReaderImpl implements ChallengeGroupImageReader { | ||
private final ChallengeGroupImageRepository challengeGroupImageRepository; | ||
@Override | ||
public List<ChallengeGroupImage> getByChallengeGroupId(Long challengeGroupId) { | ||
return challengeGroupImageRepository.findByChallengeGroupId(challengeGroupId); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...java/org/haedal/zzansuni/infrastructure/challengegroup/ChallengeGroupImageRepository.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,10 @@ | ||
package org.haedal.zzansuni.infrastructure.challengegroup; | ||
|
||
import org.haedal.zzansuni.domain.challengegroup.ChallengeGroupImage; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface ChallengeGroupImageRepository extends JpaRepository<ChallengeGroupImage, Long> { | ||
List<ChallengeGroupImage> findByChallengeGroupId(Long challengeGroupId); | ||
} |
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