Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ public BusinessPlan getOrThrow(Long id) {
);
}

@Override
public BusinessPlan getOrThrowWithAllSubSections(Long id) {
return businessPlanRepository.findByIdWithAllSubSections(id).orElseThrow(
() -> new BusinessPlanException(BusinessPlanErrorType.BUSINESS_PLAN_NOT_FOUND)
);
}

@Override
public BusinessPlan save(BusinessPlan businessPlan) {
return businessPlanRepository.save(businessPlan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,33 @@ public interface BusinessPlanRepository extends JpaRepository<BusinessPlan, Long
Optional<BusinessPlan> findById(Long id);

@Query("""
SELECT bp
FROM BusinessPlan bp
WHERE bp.memberId = :memberId
ORDER BY COALESCE(bp.modifiedAt, bp.createdAt) DESC, bp.id DESC
""")
SELECT bp
FROM BusinessPlan bp
WHERE bp.memberId = :memberId
ORDER BY COALESCE(bp.modifiedAt, bp.createdAt) DESC, bp.id DESC
""")
Page<BusinessPlan> findAllByMemberIdOrderedByLastSavedAt(@Param("memberId") Long memberId, Pageable pageable);

@Query("""
SELECT DISTINCT bp
FROM BusinessPlan bp
LEFT JOIN FETCH bp.overview o
LEFT JOIN FETCH o.overviewBasic
LEFT JOIN FETCH bp.problemRecognition pr
LEFT JOIN FETCH pr.problemBackground
LEFT JOIN FETCH pr.problemPurpose
LEFT JOIN FETCH pr.problemMarket
LEFT JOIN FETCH bp.feasibility f
LEFT JOIN FETCH f.feasibilityStrategy
LEFT JOIN FETCH f.feasibilityMarket
LEFT JOIN FETCH bp.growthTactic gt
LEFT JOIN FETCH gt.growthModel
LEFT JOIN FETCH gt.growthFunding
LEFT JOIN FETCH gt.growthEntry
LEFT JOIN FETCH bp.teamCompetence tc
LEFT JOIN FETCH tc.teamFounder
LEFT JOIN FETCH tc.teamMembers
WHERE bp.id = :id
""")
Optional<BusinessPlan> findByIdWithAllSubSections(@Param("id") Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public BusinessPlanResponse.Result getBusinessPlanInfo(Long planId, Long memberI
@Override
@Transactional(readOnly = true)
public BusinessPlanResponse.Detail getBusinessPlanDetail(Long planId, Long memberId) {
BusinessPlan plan = getOwnedBusinessPlanOrThrow(planId, memberId);
BusinessPlan plan = businessPlanQuery.getOrThrowWithAllSubSections(planId);
if (!plan.isOwnedBy(memberId)) {
throw new BusinessPlanException(BusinessPlanErrorType.UNAUTHORIZED_ACCESS);
}

List<SubSectionResponse.Detail> subSectionDetailList = Arrays.stream(SubSectionType.values())
.map(type -> getSectionByPlanAndType(plan, type.getSectionType()).getSubSectionByType(type))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public interface BusinessPlanQuery {

BusinessPlan getOrThrow(Long id);

BusinessPlan getOrThrowWithAllSubSections(Long id);

BusinessPlan save(BusinessPlan businessPlan);

void delete(BusinessPlan businessPlan);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ void getBusinessPlanSubSections_returnsExistingSubSectionList() {
List.of(false, false, false, false, false));
plan.getProblemRecognition().putSubSection(problem);

when(businessPlanQuery.getOrThrow(1L)).thenReturn(plan);
when(businessPlanQuery.getOrThrowWithAllSubSections(1L)).thenReturn(plan);

BusinessPlanResponse.Detail detail = sut.getBusinessPlanDetail(1L, 10L);

Expand All @@ -355,7 +355,7 @@ void getBusinessPlanSubSections_returnsExistingSubSectionList() {
void getBusinessPlanDetail_unauthorized_throws() {
BusinessPlan plan = mock(BusinessPlan.class);
when(plan.isOwnedBy(10L)).thenReturn(false);
when(businessPlanQuery.getOrThrow(1L)).thenReturn(plan);
when(businessPlanQuery.getOrThrowWithAllSubSections(1L)).thenReturn(plan);

org.junit.jupiter.api.Assertions.assertThrows(BusinessPlanException.class,
() -> sut.getBusinessPlanDetail(1L, 10L));
Expand Down
Loading