-
Notifications
You must be signed in to change notification settings - Fork 0
[feat/98] 이번주 문제 영역 조회 #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
27 changes: 27 additions & 0 deletions
27
src/main/java/com/moplus/moplus_server/client/homefeed/controller/HomeFeedController.java
This file contains hidden or 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,27 @@ | ||
| package com.moplus.moplus_server.client.homefeed.controller; | ||
|
|
||
| import com.moplus.moplus_server.client.homefeed.dto.response.HomeFeedResponse; | ||
| import com.moplus.moplus_server.client.homefeed.service.HomeFeedFacadeService; | ||
| import com.moplus.moplus_server.global.annotation.AuthUser; | ||
| import com.moplus.moplus_server.member.domain.Member; | ||
| import io.swagger.v3.oas.annotations.Operation; | ||
| import io.swagger.v3.oas.annotations.tags.Tag; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
|
|
||
| @Tag(name = "홈 피드 조회", description = "홈 피드 관련 API") | ||
| @RestController | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/api/v1/client/home-feed") | ||
| public class HomeFeedController { | ||
|
|
||
| private final HomeFeedFacadeService homeFeedFacadeService; | ||
|
|
||
| @Operation(summary = "홈 피드 조회", description = "회원의 홈 피드 정보를 조회합니다.") | ||
| @GetMapping("") | ||
| public HomeFeedResponse getHomeFeed(@AuthUser Member member) { | ||
| return homeFeedFacadeService.getHomeFeed(member); | ||
| } | ||
| } |
68 changes: 68 additions & 0 deletions
68
src/main/java/com/moplus/moplus_server/client/homefeed/dto/response/HomeFeedResponse.java
This file contains hidden or 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,68 @@ | ||
| package com.moplus.moplus_server.client.homefeed.dto.response; | ||
|
|
||
| import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSetGetResponse; | ||
| import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSummaryResponse; | ||
| import java.time.LocalDate; | ||
| import java.util.List; | ||
|
|
||
| public record HomeFeedResponse( | ||
| List<DailyProgressResponse> dailyProgresses, | ||
| List<ProblemSetHomeFeedResponse> problemSets | ||
| ) { | ||
| public static HomeFeedResponse of( | ||
| List<DailyProgressResponse> dailyProgresses, | ||
| List<ProblemSetHomeFeedResponse> problemSets | ||
| ) { | ||
| return new HomeFeedResponse(dailyProgresses, problemSets); | ||
| } | ||
|
|
||
| public record DailyProgressResponse( | ||
| LocalDate date, | ||
| double progressRate | ||
| ) { | ||
| public static DailyProgressResponse of(LocalDate date, double progressRate) { | ||
| return new DailyProgressResponse(date, progressRate); | ||
| } | ||
| } | ||
|
|
||
| public record ProblemSetHomeFeedResponse( | ||
| LocalDate date, | ||
| Long problemSetId, | ||
| String title, | ||
| Long submitCount, | ||
| ProblemHomeFeedResponse problemHomeFeedResponse | ||
| ) { | ||
| public static ProblemSetHomeFeedResponse of(LocalDate date, ProblemSetGetResponse problemSetGetResponse, | ||
| Long submitCount) { | ||
| return new ProblemSetHomeFeedResponse( | ||
| date, | ||
| problemSetGetResponse.id(), | ||
| problemSetGetResponse.title(), | ||
| submitCount, | ||
| ProblemHomeFeedResponse.of(problemSetGetResponse.problemSummaries().get(0)) | ||
| ); | ||
| } | ||
|
|
||
| public static ProblemSetHomeFeedResponse of(LocalDate date) { | ||
| return new ProblemSetHomeFeedResponse( | ||
| date, | ||
| null, | ||
| null, | ||
| null, | ||
| null | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| public record ProblemHomeFeedResponse( | ||
| Long problemId, | ||
| String mainProblemImageUrl | ||
| ) { | ||
| public static ProblemHomeFeedResponse of(ProblemSummaryResponse problemSummaryResponse) { | ||
| return new ProblemHomeFeedResponse( | ||
| problemSummaryResponse.problemId(), | ||
| problemSummaryResponse.mainProblemImageUrl() | ||
| ); | ||
| } | ||
| } | ||
| } | ||
75 changes: 75 additions & 0 deletions
75
src/main/java/com/moplus/moplus_server/client/homefeed/service/HomeFeedFacadeService.java
This file contains hidden or 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,75 @@ | ||
| package com.moplus.moplus_server.client.homefeed.service; | ||
|
|
||
| import com.moplus.moplus_server.admin.problemset.dto.response.ProblemSetGetResponse; | ||
| import com.moplus.moplus_server.admin.publish.domain.Publish; | ||
| import com.moplus.moplus_server.admin.publish.service.PublishGetService; | ||
| import com.moplus.moplus_server.client.homefeed.dto.response.HomeFeedResponse; | ||
| import com.moplus.moplus_server.client.homefeed.dto.response.HomeFeedResponse.DailyProgressResponse; | ||
| import com.moplus.moplus_server.client.homefeed.dto.response.HomeFeedResponse.ProblemSetHomeFeedResponse; | ||
| import com.moplus.moplus_server.domain.problemset.service.ProblemSetGetService; | ||
| import com.moplus.moplus_server.member.domain.Member; | ||
| import com.moplus.moplus_server.statistic.Problem.domain.ProblemSetStatistic; | ||
| import com.moplus.moplus_server.statistic.Problem.repository.ProblemSetStatisticRepository; | ||
| import java.time.DayOfWeek; | ||
| import java.time.LocalDate; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class HomeFeedFacadeService { | ||
|
|
||
| private final ProblemSetStatisticRepository problemSetStatisticRepository; | ||
| private final PublishGetService publishGetService; | ||
| private final ProblemSetGetService problemSetGetService; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public HomeFeedResponse getHomeFeed(Member member) { | ||
| Long memberId = member.getId(); | ||
|
|
||
| List<DailyProgressResponse> dailyProgresses = new ArrayList<>(); // 다음 PR에서 구현 | ||
| List<ProblemSetHomeFeedResponse> problemSets = getWeekdayProblemSets(); | ||
|
|
||
| return HomeFeedResponse.of(dailyProgresses, problemSets); | ||
| } | ||
|
|
||
| private List<ProblemSetHomeFeedResponse> getWeekdayProblemSets() { | ||
| LocalDate today = LocalDate.now(); | ||
| LocalDate monday = today.with(DayOfWeek.MONDAY); | ||
| LocalDate friday = today.with(DayOfWeek.FRIDAY); | ||
|
|
||
| // 월요일부터 금요일까지의 발행된 문제 세트 조회 | ||
| List<Publish> publishes = publishGetService.getPublishesBetweenDates(monday, friday); | ||
| Map<LocalDate, Publish> publishByDate = publishes.stream() | ||
| .collect(Collectors.toMap(Publish::getPublishedDate, publish -> publish)); | ||
|
|
||
| // 문제 세트 정보 조회 | ||
| List<Long> problemSetIds = publishes.stream() | ||
| .map(Publish::getProblemSetId) | ||
| .toList(); | ||
| Map<Long, ProblemSetGetResponse> problemSetMap = problemSetGetService.getProblemSets(problemSetIds).stream() | ||
| .collect(Collectors.toMap(ProblemSetGetResponse::id, response -> response)); | ||
|
|
||
| // 월요일부터 금요일까지의 모든 날짜에 대한 응답 생성 | ||
| List<ProblemSetHomeFeedResponse> responses = new ArrayList<>(); | ||
| for (LocalDate date = monday; !date.isAfter(friday); date = date.plusDays(1)) { | ||
| Publish publish = publishByDate.get(date); | ||
| if (publish != null) { | ||
| ProblemSetGetResponse problemSet = problemSetMap.get(publish.getProblemSetId()); | ||
| Long submitCount = problemSetStatisticRepository.findById(problemSet.id()) | ||
| .map(ProblemSetStatistic::getSubmitCount) | ||
| .orElse(0L); | ||
| responses.add(ProblemSetHomeFeedResponse.of(date, problemSet, submitCount)); | ||
| } else { | ||
| responses.add(ProblemSetHomeFeedResponse.of(date)); | ||
| } | ||
| } | ||
|
|
||
| return responses; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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
...in/java/com/moplus/moplus_server/statistic/Problem/service/CountStatisticsGetService.java
This file contains hidden or 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 com.moplus.moplus_server.statistic.Problem.service; | ||
|
|
||
| import com.moplus.moplus_server.statistic.Problem.repository.ProblemSetStatisticRepository; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| public class CountStatisticsGetService { | ||
|
|
||
| private final ProblemSetStatisticRepository problemSetStatisticRepository; | ||
|
|
||
| @Transactional(readOnly = true) | ||
| public Long getProblemSetCount(Long id) { | ||
| return problemSetStatisticRepository.findByIdElseThrow(id).getSubmitCount(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오 record안에 또 record를 만들 수 있군요... 어차피 해당 응답 Dto에서만 사용하는 Dto들은 한 곳에 모아둔걸까요?