Skip to content
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

feat: ai quest 추천 query limit 추가 -> ai prompt api 호출 추가 #126

Merged
merged 1 commit into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/main/java/com/groom/orbit/goal/app/MemberGoalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import com.groom.orbit.goal.app.dto.response.GetMemberGoalResponseDto;
import com.groom.orbit.goal.app.dto.response.GetQuestResponseDto;
import com.groom.orbit.goal.app.query.GoalQueryService;
import com.groom.orbit.goal.app.query.QuestQueryService;
import com.groom.orbit.goal.dao.MemberGoalRepository;
import com.groom.orbit.goal.dao.entity.Goal;
import com.groom.orbit.goal.dao.entity.MemberGoal;
Expand All @@ -30,7 +29,6 @@
public class MemberGoalService {

private final MemberGoalRepository memberGoalRepository;
private final QuestQueryService questQueryService;
private final MemberQueryService memberQueryService;
private final GoalQueryService goalQueryService;
private final GoalCommandService goalCommandService;
Expand All @@ -43,6 +41,14 @@ public MemberGoal findMemberGoal(Long memberId, Long goalId) {
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_GOAL));
}

@Transactional(readOnly = true)
public MemberGoal findMemberGoal(Long memberGoalId) {

return memberGoalRepository
.findById(memberGoalId)
.orElseThrow(() -> new CommonException(ErrorCode.NOT_FOUND_GOAL));
}

public CommonSuccessDto deleteGoal(Long memberId, Long goalId) {
MemberGoal memberGoal = findMemberGoal(memberId, goalId);
Goal goal = memberGoal.getGoal();
Expand Down Expand Up @@ -126,4 +132,8 @@ private List<String> getGoalTitle(List<Long> startIds) {

return goals.stream().map(Goal::getTitle).toList();
}

public List<MemberGoal> findMemberGoalsByGoalId(Long goalId) {
return memberGoalRepository.findAllByGoalId(goalId);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package com.groom.orbit.goal.app.query;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
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.GetQuestResponseDto;
import com.groom.orbit.goal.dao.QuestRepository;
import com.groom.orbit.goal.dao.entity.MemberGoal;
import com.groom.orbit.goal.dao.entity.Quest;

import lombok.RequiredArgsConstructor;
Expand All @@ -19,6 +24,7 @@
public class QuestQueryService {

private final QuestRepository questRepository;
private final MemberGoalService memberGoalService;

public Quest findQuest(Long questId) {
return questRepository
Expand Down Expand Up @@ -49,11 +55,18 @@ public List<Quest> findByQuestIdIn(List<Long> questIds) {
return questRepository.findByQuestIdIn(questIds);
}

public long getTotalQuestCount(Long goalId) {
return questRepository.countByMemberGoal_GoalId(goalId);
}
public List<String> getRecommendedQuests(Long memberGoalId) {
MemberGoal memberGoal = memberGoalService.findMemberGoal(memberGoalId);
Set<Quest> myQuests = new HashSet<>(memberGoal.getQuests());

List<MemberGoal> memberGoals =
memberGoalService.findMemberGoalsByGoalId(memberGoal.getGoal().getGoalId()); // goal 조회
Set<Quest> quests =
memberGoals.stream()
.map(MemberGoal::getQuests)
.flatMap(List::stream)
.collect(Collectors.toSet());

public long getFinishQuestCount(Long goalId) {
return questRepository.countCompletedByMemberGoal_GoalId(goalId);
return quests.stream().filter(quest -> !myQuests.contains(quest)).map(Quest::getTitle).toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public ResponseDto<List<GetQuestResponseDto>> findQuest(
@AuthMember Long memberId, @RequestParam("goal_id") Long goalId) {
return ResponseDto.ok(questQueryService.findQuestsByGoalId(memberId, goalId));
}

@GetMapping("/recommend")
public ResponseDto<?> getRecommendedQuests(@RequestParam("member_goal_id") Long memberGoalId) {
return ResponseDto.ok(questQueryService.getRecommendedQuests(memberGoalId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ List<MemberGoal> findByMemberIdAndIsComplete(

@Query("select mg from MemberGoal mg" + " join fetch mg.member m" + " join fetch mg.goal g")
List<MemberGoal> findNotCompletedByMemberId(Long memberId);

@Query("select mg from MemberGoal mg" + " join fetch mg.goal g" + " where g.goalId=:goal_id")
List<MemberGoal> findAllByGoalId(@Param("goal_id") Long goalId);
}
Loading