Skip to content

Commit

Permalink
Refactor(#88): 개인, 팀 대시보드 전체 조회 페이지네이션 제거 (#95)
Browse files Browse the repository at this point in the history
* Revert "Refactor(#88): 개인, 팀 대시보드 전체 조회 페이지네이션 제거 (#89)"

This reverts commit dc3dd78.

* Refactor(#88): 개인, 팀 대시보드 전체 조회 페이지네이션 제거
  • Loading branch information
giwoong01 authored Aug 31, 2024
1 parent f43c940 commit 61ed67f
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@

public interface DashboardCustomRepository {

Page<PersonalDashboard> findForPersonalDashboard(Member member, Pageable pageable);
List<PersonalDashboard> findForPersonalDashboard(Member member);

List<String> findForPersonalDashboardByCategory(Member member);

Page<TeamDashboard> findForTeamDashboard(Member member, Pageable pageable);

List<TeamDashboard> findForTeamDashboard(Member member);

List<Member> findForMembersByQuery(String query);

double calculateCompletionPercentage(Long dashboardId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,15 @@ public DashboardCustomRepositoryImpl(JPAQueryFactory queryFactory) {
}

@Override
public Page<PersonalDashboard> findForPersonalDashboard(Member member, Pageable pageable) {
long total = queryFactory
.selectFrom(personalDashboard)
.where(personalDashboard._super.member.eq(member))
.stream()
.count();

List<PersonalDashboard> dashboards = queryFactory
public List<PersonalDashboard> findForPersonalDashboard(Member member) {
return queryFactory
.selectFrom(personalDashboard)
.where(personalDashboard._super.member.eq(member)
.and(personalDashboard._super.status.eq(Status.ACTIVE)))
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();

return new PageImpl<>(dashboards, pageable, total);
}


@Override
public List<String> findForPersonalDashboardByCategory(Member member) {
return queryFactory
Expand Down Expand Up @@ -77,6 +68,15 @@ public Page<TeamDashboard> findForTeamDashboard(Member member, Pageable pageable
return new PageImpl<>(dashboards, pageable, total);
}

@Override
public List<TeamDashboard> findForTeamDashboard(Member member) {
return queryFactory
.selectFrom(teamDashboard)
.where(teamDashboard._super.member.eq(member)
.and(teamDashboard._super.status.eq(Status.ACTIVE)))
.fetch();
}

@Override
public List<Member> findForMembersByQuery(String query) {
if (query.contains("#")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -11,7 +10,6 @@
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.api.dto.request.PersonalDashboardSaveReqDto;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.api.dto.request.PersonalDashboardUpdateReqDto;
Expand Down Expand Up @@ -47,12 +45,10 @@ public RspTemplate<PersonalDashboardInfoResDto> update(@CurrentUserEmail String
}

@GetMapping("/")
public RspTemplate<PersonalDashboardListResDto> findForPersonalDashboard(@CurrentUserEmail String email,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = "10") int size) {
public RspTemplate<PersonalDashboardListResDto> findForPersonalDashboard(@CurrentUserEmail String email) {
return new RspTemplate<>(HttpStatus.OK,
"개인 대시보드 전체 조회",
personalDashboardService.findForPersonalDashboard(email, PageRequest.of(page, size)));
personalDashboardService.findForPersonalDashboard(email));
}

@GetMapping("/{dashboardId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@

import java.util.List;
import lombok.Builder;
import shop.kkeujeok.kkeujeokbackend.global.dto.PageInfoResDto;

@Builder
public record PersonalDashboardListResDto(
List<PersonalDashboardInfoResDto> personalDashboardListResDto,
PageInfoResDto pageInfoResDto
List<PersonalDashboardInfoResDto> personalDashboardListResDto
) {
public static PersonalDashboardListResDto of(List<PersonalDashboardInfoResDto> personalDashboards,
PageInfoResDto pageInfoResDto) {
public static PersonalDashboardListResDto of(List<PersonalDashboardInfoResDto> personalDashboards) {
return PersonalDashboardListResDto.builder()
.personalDashboardListResDto(personalDashboards)
.pageInfoResDto(pageInfoResDto)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import shop.kkeujeok.kkeujeokbackend.dashboard.exception.DashboardNotFoundException;
Expand All @@ -15,7 +13,6 @@
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.domain.PersonalDashboard;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.domain.repository.PersonalDashboardRepository;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.exception.DashboardAccessDeniedException;
import shop.kkeujeok.kkeujeokbackend.global.dto.PageInfoResDto;
import shop.kkeujeok.kkeujeokbackend.member.domain.Member;
import shop.kkeujeok.kkeujeokbackend.member.domain.repository.MemberRepository;
import shop.kkeujeok.kkeujeokbackend.member.exception.MemberNotFoundException;
Expand Down Expand Up @@ -59,17 +56,15 @@ public PersonalDashboardInfoResDto update(String email,
}

// 개인 대시보드 전체 조회
public PersonalDashboardListResDto findForPersonalDashboard(String email, Pageable pageable) {
public PersonalDashboardListResDto findForPersonalDashboard(String email) {
Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new);
Page<PersonalDashboard> personalDashboards = personalDashboardRepository.
findForPersonalDashboard(member, pageable);
List<PersonalDashboard> personalDashboards = personalDashboardRepository.findForPersonalDashboard(member);

List<PersonalDashboardInfoResDto> personalDashboardInfoResDtoList = personalDashboards.stream()
.map(p -> PersonalDashboardInfoResDto.of(member, p))
.toList();

return PersonalDashboardListResDto
.of(personalDashboardInfoResDtoList, PageInfoResDto.from(personalDashboards));
return PersonalDashboardListResDto.of(personalDashboardInfoResDtoList);
}

// 개인 대시보드 상세조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
Expand Down Expand Up @@ -47,12 +46,10 @@ public RspTemplate<TeamDashboardInfoResDto> update(@CurrentUserEmail String emai
}

@GetMapping("/")
public RspTemplate<TeamDashboardListResDto> findForTeamDashboard(@CurrentUserEmail String email,
@RequestParam(name = "page", defaultValue = "0") int page,
@RequestParam(name = "size", defaultValue = "10") int size) {
public RspTemplate<TeamDashboardListResDto> findForTeamDashboard(@CurrentUserEmail String email) {
return new RspTemplate<>(HttpStatus.OK,
"팀 대시보드 전체 조회",
teamDashboardService.findForTeamDashboard(email, PageRequest.of(page, size)));
teamDashboardService.findForTeamDashboard(email));
}

@GetMapping("/{dashboardId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,10 @@ public static TeamDashboardListResDto of(List<TeamDashboardInfoResDto> teamDashb
.pageInfoResDto(pageInfoResDto)
.build();
}

public static TeamDashboardListResDto from(List<TeamDashboardInfoResDto> teamDashboards) {
return TeamDashboardListResDto.builder()
.teamDashboardInfoResDto(teamDashboards)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public TeamDashboardInfoResDto update(String email,
return TeamDashboardInfoResDto.of(member, dashboard);
}

// 팀 대시보드 전체 조회
// 팀 대시보드 전체 조회(페이지네이션)
public TeamDashboardListResDto findForTeamDashboard(String email, Pageable pageable) {
Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new);
Page<TeamDashboard> teamDashboards = teamDashboardRepository.findForTeamDashboard(member, pageable);
Expand All @@ -69,6 +69,18 @@ public TeamDashboardListResDto findForTeamDashboard(String email, Pageable pagea
.of(teamDashboardInfoResDtoList, PageInfoResDto.from(teamDashboards));
}

// 팀 대시보드 전체 조회(페이지네이션 X)
public TeamDashboardListResDto findForTeamDashboard(String email) {
Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new);
List<TeamDashboard> teamDashboards = teamDashboardRepository.findForTeamDashboard(member);

List<TeamDashboardInfoResDto> teamDashboardInfoResDtoList = teamDashboards.stream()
.map(t -> TeamDashboardInfoResDto.of(member, t))
.toList();

return TeamDashboardListResDto.from(teamDashboardInfoResDtoList);
}

// 팀 대시보드 상세 조회
public TeamDashboardInfoResDto findById(String email, Long dashboardId) {
Member member = memberRepository.findByEmail(email).orElseThrow(MemberNotFoundException::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.test.util.ReflectionTestUtils;
Expand All @@ -47,7 +44,6 @@
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.api.dto.response.PersonalDashboardListResDto;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.domain.PersonalDashboard;
import shop.kkeujeok.kkeujeokbackend.global.annotationresolver.CurrentUserEmailArgumentResolver;
import shop.kkeujeok.kkeujeokbackend.global.dto.PageInfoResDto;
import shop.kkeujeok.kkeujeokbackend.global.error.ControllerAdvice;
import shop.kkeujeok.kkeujeokbackend.member.domain.Member;
import shop.kkeujeok.kkeujeokbackend.member.domain.SocialType;
Expand Down Expand Up @@ -189,16 +185,11 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
@Test
void 개인_대시보드_전체_조회() throws Exception {
// given
Page<PersonalDashboard> personalDashboardPage = new PageImpl<>(
List.of(personalDashboard),
PageRequest.of(0, 10),
1);
PersonalDashboardListResDto response = PersonalDashboardListResDto.of(
Collections.singletonList(PersonalDashboardInfoResDto.of(member, personalDashboard)),
PageInfoResDto.from(personalDashboardPage)
Collections.singletonList(PersonalDashboardInfoResDto.of(member, personalDashboard))
);

given(personalDashboardService.findForPersonalDashboard(anyString(), any())).willReturn(response);
given(personalDashboardService.findForPersonalDashboard(anyString())).willReturn(response);

// when & then
mockMvc.perform(get("/api/dashboards/personal/")
Expand Down Expand Up @@ -229,10 +220,7 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
fieldWithPath("data.personalDashboardListResDto[].category")
.description("개인 대시보드 카테고리"),
fieldWithPath("data.personalDashboardListResDto[].blockProgress")
.description("개인 대시보드의 완료된 블록 진행률"),
fieldWithPath("data.pageInfoResDto.currentPage").description("현재 페이지"),
fieldWithPath("data.pageInfoResDto.totalPages").description("전체 페이지"),
fieldWithPath("data.pageInfoResDto.totalItems").description("전체 아이템")
.description("개인 대시보드의 완료된 블록 진행률")
)
))
.andExpect(status().isOk());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.api.dto.request.PersonalDashboardSaveReqDto;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.api.dto.request.PersonalDashboardUpdateReqDto;
import shop.kkeujeok.kkeujeokbackend.dashboard.personal.api.dto.response.PersonalDashboardCategoriesResDto;
Expand Down Expand Up @@ -176,18 +172,11 @@ void setUp() {
@Test
void 개인_대시보드_전체_조회() {
// given
Pageable pageable = PageRequest.of(0, 10);
Page<PersonalDashboard> personalDashboardPage = new PageImpl<>(
List.of(personalDashboard),
pageable,
1);

when(personalDashboardRepository.findForPersonalDashboard(any(Member.class), any(Pageable.class)))
.thenReturn(personalDashboardPage);
when(personalDashboardRepository.findForPersonalDashboard(any(Member.class)))
.thenReturn(List.of(personalDashboard));

// when
PersonalDashboardListResDto result = personalDashboardService.
findForPersonalDashboard(member.getEmail(), pageable);
PersonalDashboardListResDto result = personalDashboardService.findForPersonalDashboard(member.getEmail());

// then
assertThat(result).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.offset;

import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.test.context.ActiveProfiles;
import shop.kkeujeok.kkeujeokbackend.block.domain.Block;
import shop.kkeujeok.kkeujeokbackend.block.domain.Progress;
Expand Down Expand Up @@ -99,15 +97,14 @@ void setUp() {
@Test
void 개인_대시보드_전체_조회() {
// given
Pageable pageable = PageRequest.of(0, 10);

// when
Page<PersonalDashboard> result = personalDashboardRepository.findForPersonalDashboard(member, pageable);
List<PersonalDashboard> result = personalDashboardRepository.findForPersonalDashboard(member);

// then
assertThat(result.getTotalElements()).isEqualTo(1);
assertThat(result.getContent().get(0).getTitle()).isEqualTo("title");
assertThat(result.getContent().get(0).getMember()).isEqualTo(member);
assertThat(result.size()).isEqualTo(1);
assertThat(result.get(0).getTitle()).isEqualTo("title");
assertThat(result.get(0).getMember()).isEqualTo(member);
}

@DisplayName("대시보드의 완료된 블록 비율을 계산합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.MediaType;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.test.util.ReflectionTestUtils;
Expand All @@ -48,7 +45,6 @@
import shop.kkeujeok.kkeujeokbackend.dashboard.team.api.dto.response.TeamDashboardListResDto;
import shop.kkeujeok.kkeujeokbackend.dashboard.team.domain.TeamDashboard;
import shop.kkeujeok.kkeujeokbackend.global.annotationresolver.CurrentUserEmailArgumentResolver;
import shop.kkeujeok.kkeujeokbackend.global.dto.PageInfoResDto;
import shop.kkeujeok.kkeujeokbackend.global.error.ControllerAdvice;
import shop.kkeujeok.kkeujeokbackend.member.domain.Member;
import shop.kkeujeok.kkeujeokbackend.member.domain.SocialType;
Expand Down Expand Up @@ -190,17 +186,11 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
@Test
void 팀_대시보드_전체_조회() throws Exception {
// given
Page<TeamDashboard> teamDashboardPage = new PageImpl<>(
List.of(teamDashboard),
PageRequest.of(0, 10),
1
);
TeamDashboardListResDto response = TeamDashboardListResDto.of(
Collections.singletonList(TeamDashboardInfoResDto.of(member, teamDashboard)),
PageInfoResDto.from(teamDashboardPage)
TeamDashboardListResDto response = TeamDashboardListResDto.from(
Collections.singletonList(TeamDashboardInfoResDto.of(member, teamDashboard))
);

given(teamDashboardService.findForTeamDashboard(anyString(), any())).willReturn(response);
given(teamDashboardService.findForTeamDashboard(anyString())).willReturn(response);

// when & then
mockMvc.perform(get("/api/dashboards/team/")
Expand Down Expand Up @@ -230,9 +220,8 @@ void setUp(RestDocumentationContextProvider restDocumentation) {
.description("팀 대시보드의 완료된 블록 진행률"),
fieldWithPath("data.teamDashboardInfoResDto[].joinMembers")
.description("팀 대시보드에 참여한 사용자"),
fieldWithPath("data.pageInfoResDto.currentPage").description("현재 페이지"),
fieldWithPath("data.pageInfoResDto.totalPages").description("전체 페이지"),
fieldWithPath("data.pageInfoResDto.totalItems").description("전체 아이템")
fieldWithPath("data.pageInfoResDto")
.description("페이지 정보가 없습니다.")
)
))
.andExpect(status().isOk());
Expand Down

0 comments on commit 61ed67f

Please sign in to comment.