-
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
5 changed files
with
93 additions
and
0 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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/groom/orbit/goal/app/dto/response/GoalSearchDetailResponseDto.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,5 @@ | ||
package com.groom.orbit.goal.app.dto.response; | ||
|
||
import java.util.List; | ||
|
||
public record GoalSearchDetailResponseDto(String category, String goalName, List<String> quests) {} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/groom/orbit/goal/app/query/GoalSearchService.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,51 @@ | ||
package com.groom.orbit.goal.app.query; | ||
|
||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.groom.orbit.common.exception.CommonException; | ||
import com.groom.orbit.common.exception.ErrorCode; | ||
import com.groom.orbit.goal.app.MemberGoalService; | ||
import com.groom.orbit.goal.app.dto.response.GoalSearchDetailResponseDto; | ||
import com.groom.orbit.goal.dao.entity.Goal; | ||
import com.groom.orbit.goal.dao.entity.MemberGoal; | ||
import com.groom.orbit.goal.dao.entity.Quest; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class GoalSearchService { | ||
|
||
private final MemberGoalService memberGoalService; | ||
|
||
public GoalSearchDetailResponseDto findGoal(Long goalId) { | ||
List<MemberGoal> memberGoals = memberGoalService.findAllMemberGoal(goalId); | ||
Goal goal = findGoal(memberGoals); | ||
List<String> questTitles = | ||
memberGoals.stream() | ||
.map(MemberGoal::getQuests) | ||
.flatMap(Collection::stream) | ||
.collect(Collectors.toSet()) | ||
.stream() | ||
.sorted(Comparator.comparing(Quest::getCreatedAt).reversed()) | ||
.map(Quest::getTitle) | ||
.toList(); | ||
|
||
return new GoalSearchDetailResponseDto( | ||
goal.getCategory().getCategory(), goal.getTitle(), questTitles); | ||
} | ||
|
||
private static Goal findGoal(List<MemberGoal> memberGoals) { | ||
if (memberGoals.isEmpty()) { | ||
throw new CommonException(ErrorCode.NOT_FOUND_GOAL); | ||
} | ||
return memberGoals.getFirst().getGoal(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/com/groom/orbit/goal/controller/query/GoalSearchController.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,26 @@ | ||
package com.groom.orbit.goal.controller.query; | ||
|
||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.groom.orbit.common.dto.ResponseDto; | ||
import com.groom.orbit.goal.app.dto.response.GoalSearchDetailResponseDto; | ||
import com.groom.orbit.goal.app.query.GoalSearchService; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/goal/search") | ||
public class GoalSearchController { | ||
|
||
private final GoalSearchService goalSearchService; | ||
|
||
@GetMapping("/{goal_id}") | ||
public ResponseDto<GoalSearchDetailResponseDto> getSearchDetail( | ||
@PathVariable("goal_id") Long goalId) { | ||
return ResponseDto.ok(goalSearchService.findGoal(goalId)); | ||
} | ||
} |
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