Skip to content

Commit

Permalink
refactor: studyMemberMapper 생성 및 매핑 코드 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
donghyun0304 committed Mar 24, 2024
1 parent 3557b00 commit 48f8337
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 6 additions & 0 deletions src/main/java/com/example/demo/config/MapperConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.example.demo.mapper.CafeMapper;
import com.example.demo.mapper.ReviewMapper;
import com.example.demo.mapper.SnsDetailMapper;
import com.example.demo.mapper.StudyMemberMapper;
import com.example.demo.mapper.StudyOnceMapper;

@Configuration
Expand Down Expand Up @@ -36,4 +37,9 @@ public SnsDetailMapper snsDetailMapper() {
public StudyOnceMapper studyOnceMapper() {
return new StudyOnceMapper();
}

@Bean
public StudyMemberMapper studyMemberMapper() {
return new StudyMemberMapper();
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/example/demo/mapper/StudyMemberMapper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package com.example.demo.mapper;

import java.util.List;
import java.util.stream.Collectors;

import com.example.demo.domain.StudyMember;
import com.example.demo.dto.MemberResponse;

public class StudyMemberMapper {

public List<MemberResponse> toMemberResponses(List<StudyMember> studyMembers) {
return studyMembers.stream()
.map(studyMember -> new MemberResponse(
studyMember.getMember().getId(),
studyMember.getMember().getName(),
studyMember.getMember().getThumbnailImage().getThumbnailImage()))
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.example.demo.dto.UpdateAttendanceRequest;
import com.example.demo.dto.UpdateAttendanceResponse;
import com.example.demo.exception.CafegoryException;
import com.example.demo.mapper.StudyMemberMapper;
import com.example.demo.mapper.StudyOnceMapper;
import com.example.demo.repository.MemberRepository;
import com.example.demo.repository.StudyMemberRepository;
Expand All @@ -45,6 +46,7 @@ public class StudyOnceServiceImpl implements StudyOnceService {
private final MemberRepository memberRepository;
private final StudyMemberRepository studyMemberRepository;
private final StudyOnceMapper studyOnceMapper;
private final StudyMemberMapper studyMemberMapper;

@Override
public void tryJoin(long memberIdThatExpectedToJoin, long studyId) {
Expand Down Expand Up @@ -207,12 +209,7 @@ public Long changeCafe(Long requestMemberId, Long studyOnceId, final Long changi
@Override
public StudyMembersResponse findStudyMembersById(Long studyOnceId) {
StudyOnceImpl studyOnce = findStudyOnceById(studyOnceId);
List<MemberResponse> memberResponses = studyOnce.getStudyMembers().stream()
.map(studyMember -> new MemberResponse(
studyMember.getMember().getId(),
studyMember.getMember().getName(),
studyMember.getMember().getThumbnailImage().getThumbnailImage()))
.collect(Collectors.toList());
List<MemberResponse> memberResponses = studyMemberMapper.toMemberResponses(studyOnce.getStudyMembers());
return new StudyMembersResponse(memberResponses);
}

Expand Down

0 comments on commit 48f8337

Please sign in to comment.