Skip to content

Commit

Permalink
refactor: pageToDTO 로직을 MembersResponseDTO 메소드로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoon9901 committed Nov 22, 2023
1 parent 1829efb commit 1fccf1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.example.codebase.domain.member.dto;

import com.example.codebase.controller.dto.PageInfo;
import com.example.codebase.domain.member.entity.Member;
import lombok.Getter;
import org.springframework.data.domain.Page;

import java.util.List;

Expand All @@ -18,4 +20,12 @@ public static MembersResponseDTO of (List<MemberResponseDTO> members, PageInfo p
dto.pageInfo = pageInfo;
return dto;
}

public static MembersResponseDTO from(Page<Member> members) {
PageInfo pageInfo = PageInfo.from(members);
List<MemberResponseDTO> dtos = members.stream()
.map(MemberResponseDTO::from)
.toList();
return MembersResponseDTO.of(dtos, pageInfo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ public Member createOAuthMember(OAuthAttributes oAuthAttributes) {

public MembersResponseDTO getAllMember(PageRequest pageRequest) {
Page<Member> members = memberRepository.findAll(pageRequest);

PageInfo pageInfo = PageInfo.from(members);
List<MemberResponseDTO> memberDtos = members.stream()
.map(MemberResponseDTO::from)
.toList();
return MembersResponseDTO.of(memberDtos, pageInfo);
return MembersResponseDTO.from(members);
}

@Transactional
Expand Down Expand Up @@ -309,7 +304,7 @@ public MembersResponseDTO getAllRoleStatusMember(String roleStatus, PageRequest
}

Page<Member> members = memberRepository.findAllByRoleStatus(RoleStatus.create(roleStatus), pageRequest);
return pageToDTO(members);
return MembersResponseDTO.from(members);
}

private MembersResponseDTO getRoleStatusMember(String roleStatus, PageRequest pageRequest) {
Expand All @@ -325,14 +320,7 @@ private MembersResponseDTO getRoleStatusMember(String roleStatus, PageRequest pa
}

Page<Member> members = memberRepository.findAllByRoleStatus(roleStatusEnums[0], roleStatusEnums[1], pageRequest);
return pageToDTO(members);
return MembersResponseDTO.from(members);
}

private MembersResponseDTO pageToDTO(Page<Member> members) {
PageInfo pageInfo = PageInfo.from(members);
List<MemberResponseDTO> dtos = members.stream()
.map(MemberResponseDTO::from)
.toList();
return MembersResponseDTO.of(dtos, pageInfo);
}
}

0 comments on commit 1fccf1c

Please sign in to comment.