diff --git a/src/main/java/com/ohdab/classroom/controller/ClassroomController.java b/src/main/java/com/ohdab/classroom/controller/ClassroomController.java index 319cbc19..bed9c115 100644 --- a/src/main/java/com/ohdab/classroom/controller/ClassroomController.java +++ b/src/main/java/com/ohdab/classroom/controller/ClassroomController.java @@ -25,7 +25,7 @@ public class ClassroomController { private final AddClassroomUsecase addClassroomUsecase; private final FindClassroomListUsecase findClassroomListUsecase; - private final FindClassroomDetailUsecase findClassroomDetailUsecase; + private final GetClassroomDetailInfoUsecase getClassroomDetailInfoUsecase; private final UpdateClassroomInfoUsecase updateClassroomInfoUsecase; private final DeleteClassroomUsecase deleteClassroomUsecase; private final DeleteStudentUsecase deleteStudentUsecase; @@ -55,7 +55,7 @@ public ResponseEntity getClassroomListByTeacherId( public ResponseEntity getClassroomDetailById( @PathVariable("classroom-id") long id) { ClassroomDetailDtoResponse classroomDetail = - findClassroomDetailUsecase.getClassroomDetailById(id); + getClassroomDetailInfoUsecase.getClassroomDetailById(id); ClassroomDetailRes classroomDetailRes = ClassroomMapper.classroomDetailToClassroomDetailRes(classroomDetail); return ResponseEntity.ok(classroomDetailRes); diff --git a/src/main/java/com/ohdab/classroom/controller/mapper/ClassroomMapper.java b/src/main/java/com/ohdab/classroom/controller/mapper/ClassroomMapper.java index 6a2fe5c1..e801f7a8 100644 --- a/src/main/java/com/ohdab/classroom/controller/mapper/ClassroomMapper.java +++ b/src/main/java/com/ohdab/classroom/controller/mapper/ClassroomMapper.java @@ -67,8 +67,25 @@ public static ClassroomDetailRes classroomDetailToClassroomDetailRes( .name(detailDto.getInfo().getName()) .description(detailDto.getInfo().getDescription()) .grade(detailDto.getInfo().getGrade()) - .studentIds(detailDto.getStudentIds()) - .workbookIds(detailDto.getWorkbookIds()) + .studentInfoList( + detailDto.getStudentInfoDtoList().stream() + .map( + studentInfo -> + ClassroomDetailRes.StudentInfo.builder() + .studentId(studentInfo.getStudentId()) + .studentName(studentInfo.getStudentName()) + .build()) + .collect(Collectors.toList())) + .workbookInfoList( + detailDto.getWorkbookInfoDtoList().stream() + .map( + workbookInfo -> + ClassroomDetailRes.WorkbookInfo.builder() + .workbookId(workbookInfo.getWorkbookId()) + .workbookName( + workbookInfo.getWorkbookName()) + .build()) + .collect(Collectors.toList())) .build(); } diff --git a/src/main/java/com/ohdab/classroom/controller/response/ClassroomDetailRes.java b/src/main/java/com/ohdab/classroom/controller/response/ClassroomDetailRes.java index 6859f217..cf18c34f 100644 --- a/src/main/java/com/ohdab/classroom/controller/response/ClassroomDetailRes.java +++ b/src/main/java/com/ohdab/classroom/controller/response/ClassroomDetailRes.java @@ -15,6 +15,22 @@ public class ClassroomDetailRes { private String grade; private long teacherId; - private List studentIds; - private List workbookIds; + private List studentInfoList; + private List workbookInfoList; + + @Getter + @Builder + public static class StudentInfo { + + private long studentId; + private String studentName; + } + + @Getter + @Builder + public static class WorkbookInfo { + + private long workbookId; + private String workbookName; + } } diff --git a/src/main/java/com/ohdab/classroom/service/FindClassroomDetailService.java b/src/main/java/com/ohdab/classroom/service/FindClassroomDetailService.java deleted file mode 100644 index 3665967b..00000000 --- a/src/main/java/com/ohdab/classroom/service/FindClassroomDetailService.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.ohdab.classroom.service; - -import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoResponse; - -import com.ohdab.classroom.domain.Classroom; -import com.ohdab.classroom.exception.NoClassroomException; -import com.ohdab.classroom.repository.ClassroomRepository; -import com.ohdab.classroom.service.mapper.ClassroomDetailServiceMapper; -import com.ohdab.classroom.service.usecase.FindClassroomDetailUsecase; -import com.ohdab.core.exception.ExceptionEnum; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -@Service -@RequiredArgsConstructor -@Transactional(readOnly = true) -public class FindClassroomDetailService implements FindClassroomDetailUsecase { - - private final ClassroomRepository classroomRepository; - - @Override - public ClassroomDetailDtoResponse getClassroomDetailById(long classroomId) { - Classroom classroom = - classroomRepository - .findById(classroomId) - .orElseThrow( - () -> - new NoClassroomException( - ExceptionEnum.NO_CLASSROOM.getMessage())); - return ClassroomDetailServiceMapper.classroomToClassroomDetail(classroom); - } -} diff --git a/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java b/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java index fd9d39a7..c7143ef6 100644 --- a/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java +++ b/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java @@ -1,13 +1,18 @@ package com.ohdab.classroom.service; import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoResponse; +import static com.ohdab.classroom.service.helper.ClassroomHelperService.findExistingClassroom; import com.ohdab.classroom.domain.Classroom; -import com.ohdab.classroom.exception.NoClassroomException; import com.ohdab.classroom.repository.ClassroomRepository; -import com.ohdab.classroom.service.mapper.ClassroomDetailServiceMapper; +import com.ohdab.classroom.service.dto.ClassroomDetailDto; import com.ohdab.classroom.service.usecase.GetClassroomDetailInfoUsecase; -import com.ohdab.core.exception.ExceptionEnum; +import com.ohdab.member.domain.student.studentid.StudentId; +import com.ohdab.member.repository.mapper.MemberMapper; +import com.ohdab.workbook.domain.workbookid.WorkbookId; +import com.ohdab.workbook.repository.mapper.WorkbookMapper; +import java.util.List; +import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,16 +23,47 @@ public class GetClassroomDetailInfoService implements GetClassroomDetailInfoUsecase { private final ClassroomRepository classroomRepository; + private final MemberMapper memberMapper; + private final WorkbookMapper workbookMapper; @Override public ClassroomDetailDtoResponse getClassroomDetailById(long classroomId) { - Classroom classroom = - classroomRepository - .findById(classroomId) - .orElseThrow( - () -> - new NoClassroomException( - ExceptionEnum.NO_CLASSROOM.getMessage())); - return ClassroomDetailServiceMapper.classroomToClassroomDetail(classroom); + Classroom classroom = findExistingClassroom(classroomId, classroomRepository); + List students = + memberMapper.findAllStudentForClassroomInfo( + getStudentIdList(classroom.getStudents())); + List workbooks = + workbookMapper.findAllWorkbookForClassroomInfo( + getWorkbookIdList(classroom.getWorkbooks())); + return mapToClassroomDetailDtoResponse(classroom, students, workbooks); + } + + private List getStudentIdList(List students) { + return students.stream().map(StudentId::getId).collect(Collectors.toList()); + } + + private List getWorkbookIdList(List workbookIds) { + return workbookIds.stream().map(WorkbookId::getId).collect(Collectors.toList()); + } + + private ClassroomDetailDtoResponse mapToClassroomDetailDtoResponse( + Classroom classroom, + List students, + List workbooks) { + return ClassroomDetailDtoResponse.builder() + .classroomId(classroom.getId()) + .teacherId(classroom.getTeacher().getId()) + .info(mapToClassRoomDetailInfo(classroom)) + .studentInfoDtoList(students) + .workbookInfoDtoList(workbooks) + .build(); + } + + private ClassroomDetailDto.ClassroomDetailInfo mapToClassRoomDetailInfo(Classroom classroom) { + return ClassroomDetailDto.ClassroomDetailInfo.builder() + .name(classroom.getClassroomInfo().getName()) + .description(classroom.getClassroomInfo().getDescription()) + .grade(classroom.getClassroomInfo().getGrade().toString()) + .build(); } } diff --git a/src/main/java/com/ohdab/classroom/service/dto/ClassroomDetailDto.java b/src/main/java/com/ohdab/classroom/service/dto/ClassroomDetailDto.java index 3dbdc648..6e768c54 100644 --- a/src/main/java/com/ohdab/classroom/service/dto/ClassroomDetailDto.java +++ b/src/main/java/com/ohdab/classroom/service/dto/ClassroomDetailDto.java @@ -1,16 +1,17 @@ package com.ohdab.classroom.service.dto; import java.util.List; +import lombok.AccessLevel; import lombok.Builder; import lombok.Getter; +import lombok.NoArgsConstructor; -@Getter -@Builder +@NoArgsConstructor(access = AccessLevel.PROTECTED) public class ClassroomDetailDto { @Getter @Builder - public static class ClassroomDetailDtoInfo { + public static class ClassroomDetailInfo { private String name; private String description; private String grade; @@ -29,10 +30,26 @@ public static class ClassroomDetailDtoResponse { private long teacherId; - private ClassroomDetailDtoInfo info; + private ClassroomDetailInfo info; - private List studentIds; + private List studentInfoDtoList; - private List workbookIds; + private List workbookInfoDtoList; + } + + @Getter + @Builder + public static class StudentInfoDto { + + private long studentId; + private String studentName; + } + + @Getter + @Builder + public static class WorkbookInfoDto { + + private long workbookId; + private String workbookName; } } diff --git a/src/main/java/com/ohdab/classroom/service/mapper/ClassroomDetailServiceMapper.java b/src/main/java/com/ohdab/classroom/service/mapper/ClassroomDetailServiceMapper.java deleted file mode 100644 index 1bb1c07e..00000000 --- a/src/main/java/com/ohdab/classroom/service/mapper/ClassroomDetailServiceMapper.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.ohdab.classroom.service.mapper; - -import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoInfo; -import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoResponse; - -import com.ohdab.classroom.domain.Classroom; -import com.ohdab.member.domain.student.studentid.StudentId; -import com.ohdab.workbook.domain.workbookid.WorkbookId; -import java.util.stream.Collectors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class ClassroomDetailServiceMapper { - - public static ClassroomDetailDtoResponse classroomToClassroomDetail(Classroom classroom) { - return ClassroomDetailDtoResponse.builder() - .classroomId(classroom.getId()) - .teacherId(classroom.getTeacher().getId()) - .info( - ClassroomDetailDtoInfo.builder() - .name(classroom.getClassroomInfo().getName()) - .description(classroom.getClassroomInfo().getDescription()) - .grade(classroom.getClassroomInfo().getGrade().getLabel()) - .build()) - .studentIds( - classroom.getStudents().stream() - .map(StudentId::getId) - .collect(Collectors.toList())) - .workbookIds( - classroom.getWorkbooks().stream() - .map(WorkbookId::getId) - .collect(Collectors.toList())) - .build(); - } -} diff --git a/src/main/java/com/ohdab/classroom/service/usecase/FindClassroomDetailUsecase.java b/src/main/java/com/ohdab/classroom/service/usecase/FindClassroomDetailUsecase.java deleted file mode 100644 index b314251e..00000000 --- a/src/main/java/com/ohdab/classroom/service/usecase/FindClassroomDetailUsecase.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.ohdab.classroom.service.usecase; - -import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoResponse; - -public interface FindClassroomDetailUsecase { - - ClassroomDetailDtoResponse getClassroomDetailById(long classroomId); -} diff --git a/src/main/java/com/ohdab/member/repository/mapper/MemberMapper.java b/src/main/java/com/ohdab/member/repository/mapper/MemberMapper.java index 2131b97e..f2afe6e8 100644 --- a/src/main/java/com/ohdab/member/repository/mapper/MemberMapper.java +++ b/src/main/java/com/ohdab/member/repository/mapper/MemberMapper.java @@ -2,11 +2,15 @@ import static com.ohdab.mistakenote.service.dto.GetAllMistakeNoteInfoDto.Response.StudentInfoDto; +import com.ohdab.classroom.service.dto.ClassroomDetailDto; import java.util.List; import org.apache.ibatis.annotations.Mapper; @Mapper public interface MemberMapper { - List findAllStudent(List studentIdList); + List findAllStudentForMistakeNoteInfo(List studentIdList); + + List findAllStudentForClassroomInfo( + List studentIdList); } diff --git a/src/main/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoService.java b/src/main/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoService.java index ec24fd7a..20089024 100644 --- a/src/main/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoService.java +++ b/src/main/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoService.java @@ -76,7 +76,8 @@ public GetAllMistakeNoteInfoDto.Response getAllMistakeNoteInfo(long workbookId) if (mistakeNotesIsEmpty(mistakeNotes)) { throw new MistakeNoteIsEmptyException(ExceptionEnum.MISTAKE_NOTE_IS_EMPTY.getMessage()); } - List students = memberMapper.findAllStudent(getStudentIdList(mistakeNotes)); + List students = + memberMapper.findAllStudentForMistakeNoteInfo(getStudentIdList(mistakeNotes)); List allMistakeNoteInfoDto = mistakeRecordMapper.findAllMistakeNoteInfo(getMistakeNoteIdList(mistakeNotes)); return GetAllMistakeNoteInfoDto.Response.builder() diff --git a/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java b/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java new file mode 100644 index 00000000..fa664aa0 --- /dev/null +++ b/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java @@ -0,0 +1,12 @@ +package com.ohdab.workbook.repository.mapper; + +import com.ohdab.classroom.service.dto.ClassroomDetailDto; +import java.util.List; +import org.apache.ibatis.annotations.Mapper; + +@Mapper +public interface WorkbookMapper { + + List findAllWorkbookForClassroomInfo( + List workbookIdList); +} diff --git a/src/main/resources/mapper/MemberMapper.xml b/src/main/resources/mapper/MemberMapper.xml index c5458140..bc93789e 100644 --- a/src/main/resources/mapper/MemberMapper.xml +++ b/src/main/resources/mapper/MemberMapper.xml @@ -2,7 +2,7 @@ - select member_id as "studentId", member_name as "name" from MEMBER @@ -12,4 +12,15 @@ order by member_id asc + + \ No newline at end of file diff --git a/src/main/resources/mapper/WorkbookMapper.xml b/src/main/resources/mapper/WorkbookMapper.xml new file mode 100644 index 00000000..7b181b4e --- /dev/null +++ b/src/main/resources/mapper/WorkbookMapper.xml @@ -0,0 +1,15 @@ + + + + + \ No newline at end of file diff --git a/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java b/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java index ed622725..8fc8d093 100644 --- a/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java +++ b/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java @@ -1,7 +1,7 @@ package com.ohdab.classroom.controller; -import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoInfo; import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailDtoResponse; +import static com.ohdab.classroom.service.dto.ClassroomDetailDto.ClassroomDetailInfo; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doNothing; @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.ohdab.classroom.controller.request.*; import com.ohdab.classroom.service.dto.AddStudentDto; +import com.ohdab.classroom.service.dto.ClassroomDetailDto; import com.ohdab.classroom.service.dto.ClassroomDto; import com.ohdab.classroom.service.dto.ClassroomWorkbookDto; import com.ohdab.classroom.service.usecase.*; @@ -41,7 +42,7 @@ class ClassroomControllerTest { @Autowired private ObjectMapper objectMapper; @MockBean private AddClassroomUsecase addClassroomUsecase; @MockBean private FindClassroomListUsecase findClassroomListUsecase; - @MockBean private FindClassroomDetailUsecase findClassroomDetailUsecase; + @MockBean private GetClassroomDetailInfoUsecase getClassroomDetailInfoUsecase; @MockBean private UpdateClassroomInfoUsecase updateClassroomInfoUsecase; @MockBean private DeleteClassroomUsecase deleteClassroomUsecase; @MockBean private DeleteStudentUsecase deleteStudentUsecase; @@ -133,28 +134,40 @@ class ClassroomControllerTest { // given final String url = "/classrooms/"; - List studentIds = new ArrayList<>(); - studentIds.add(3L); - - List workbookIds = new ArrayList<>(); - workbookIds.add(4L); + List studentInfoDtoList = new ArrayList<>(); + studentInfoDtoList.add( + ClassroomDetailDto.StudentInfoDto.builder().studentId(1L).studentName("갑").build()); + studentInfoDtoList.add( + ClassroomDetailDto.StudentInfoDto.builder().studentId(2L).studentName("을").build()); + + List workbookInfoDtoList = new ArrayList<>(); + workbookInfoDtoList.add( + ClassroomDetailDto.WorkbookInfoDto.builder() + .workbookId(10L) + .workbookName("책10") + .build()); + workbookInfoDtoList.add( + ClassroomDetailDto.WorkbookInfoDto.builder() + .workbookId(11L) + .workbookName("책11") + .build()); ClassroomDetailDtoResponse classroomDetailDtoResponse = ClassroomDetailDtoResponse.builder() .classroomId(1) .teacherId(2) .info( - ClassroomDetailDtoInfo.builder() + ClassroomDetailInfo.builder() .name("1반") .description("1반 설명") .grade("high1") .build()) - .studentIds(studentIds) - .workbookIds(workbookIds) + .studentInfoDtoList(studentInfoDtoList) + .workbookInfoDtoList(workbookInfoDtoList) .build(); // when - when(findClassroomDetailUsecase.getClassroomDetailById(1L)) + when(getClassroomDetailInfoUsecase.getClassroomDetailById(1L)) .thenReturn(classroomDetailDtoResponse); // then @@ -167,8 +180,14 @@ class ClassroomControllerTest { jsonPath("$.name").value("1반"), jsonPath("$.description").value("1반 설명"), jsonPath("$.grade").value("high1"), - jsonPath("$.studentIds[0]").value(3), - jsonPath("$.workbookIds[0]").value(4)) + jsonPath("$.studentInfoList[0].studentId").value("1"), + jsonPath("$.studentInfoList[0].studentName").value("갑"), + jsonPath("$.studentInfoList[1].studentId").value("2"), + jsonPath("$.studentInfoList[1].studentName").value("을"), + jsonPath("$.workbookInfoList[0].workbookId").value("10"), + jsonPath("$.workbookInfoList[0].workbookName").value("책10"), + jsonPath("$.workbookInfoList[1].workbookId").value("11"), + jsonPath("$.workbookInfoList[1].workbookName").value("책11")) .andDo(print()) .andDo(createDocument("classrooms/{classroom-id}")); } diff --git a/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoServiceTest.java b/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java similarity index 98% rename from src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoServiceTest.java rename to src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java index ac15c3ad..0f040c55 100644 --- a/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoServiceTest.java +++ b/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java @@ -21,7 +21,7 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {UpdateWorkbookInfoService.class}) -public class UpdateWorkbookInfoServiceTest { +public class UpdateWorkbookInfoDtoServiceTest { @Autowired private UpdateWorkbookInfoUsecase updateWorkbookInfoUsecase; @MockBean private WorkbookRepository workbookRepository; diff --git a/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java b/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java index b30834b3..bd5c76d7 100644 --- a/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java +++ b/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java @@ -3,11 +3,12 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; +import com.ohdab.classroom.service.dto.ClassroomDetailDto; import com.ohdab.member.domain.Authority; import com.ohdab.member.domain.Member; import com.ohdab.member.domain.memberinfo.MemberInfo; import com.ohdab.member.repository.MemberRepository; -import com.ohdab.mistakenote.service.dto.GetAllMistakeNoteInfoDto.Response.StudentInfoDto; +import com.ohdab.mistakenote.service.dto.GetAllMistakeNoteInfoDto; import java.util.List; import javax.persistence.EntityManager; import org.junit.jupiter.api.DisplayName; @@ -24,7 +25,7 @@ class MemberMapperTest { @Autowired private MemberRepository memberRepository; @Autowired private EntityManager em; - @DisplayName("특정 반의 학생 명단을 조회한다.") + @DisplayName("교재 상세조회시 특정 반의 학생 명단을 조회한다.") @Test void 교재_상세조회_학생명단() { // given @@ -52,8 +53,8 @@ class MemberMapperTest { em.clear(); // when - List result = - memberMapper.findAllStudent( + List result = + memberMapper.findAllStudentForMistakeNoteInfo( List.of( savedStudent1.getId(), savedStudent2.getId(), @@ -62,7 +63,55 @@ class MemberMapperTest { // then assertThat(result) .hasSize(3) - .extracting("studentId", "name") + .extracting( + GetAllMistakeNoteInfoDto.Response.StudentInfoDto::getStudentId, + GetAllMistakeNoteInfoDto.Response.StudentInfoDto::getName) + .contains(tuple(savedStudent1.getId(), "갑")) + .contains(tuple(savedStudent2.getId(), "을")) + .contains(tuple(savedStudent3.getId(), "병")); + } + + @DisplayName("반 상세조회시 학생 명단을 조회한다.") + @Test + void 반_상세조회_학생명단() { + // given + final Member student1 = + Member.builder() + .memberInfo(MemberInfo.builder().name("갑").password("1234").build()) + .authorities(List.of(new Authority("STUDENT"))) + .build(); + final Member student2 = + Member.builder() + .memberInfo(MemberInfo.builder().name("을").password("1234").build()) + .authorities(List.of(new Authority("STUDENT"))) + .build(); + final Member student3 = + Member.builder() + .memberInfo(MemberInfo.builder().name("병").password("1234").build()) + .authorities(List.of(new Authority("STUDENT"))) + .build(); + + Member savedStudent1 = memberRepository.save(student1); + Member savedStudent2 = memberRepository.save(student2); + Member savedStudent3 = memberRepository.save(student3); + + em.flush(); + em.clear(); + + // when + List result = + memberMapper.findAllStudentForClassroomInfo( + List.of( + savedStudent1.getId(), + savedStudent2.getId(), + savedStudent3.getId())); + + // then + assertThat(result) + .hasSize(3) + .extracting( + ClassroomDetailDto.StudentInfoDto::getStudentId, + ClassroomDetailDto.StudentInfoDto::getStudentName) .contains(tuple(savedStudent1.getId(), "갑")) .contains(tuple(savedStudent2.getId(), "을")) .contains(tuple(savedStudent3.getId(), "병")); diff --git a/src/test/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoServiceTest.java b/src/test/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoServiceTest.java index ca0bbb67..4521c144 100644 --- a/src/test/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoServiceTest.java +++ b/src/test/java/com/ohdab/mistakenote/service/GetMistakeNoteInfoServiceTest.java @@ -145,7 +145,7 @@ class GetMistakeNoteInfoServiceTest { // when when(mistakeNoteRepository.findByWorkbookId(any(WorkbookId.class))) .thenReturn(mistakeNotes); - when(memberMapper.findAllStudent(anyList())).thenReturn(students); + when(memberMapper.findAllStudentForMistakeNoteInfo(anyList())).thenReturn(students); when(mistakeRecordMapper.findAllMistakeNoteInfo(anyList())) .thenReturn(allMistakeNoteInfoDto); GetAllMistakeNoteInfoDto.Response result = diff --git a/src/test/java/com/ohdab/workbook/repository/mapper/WorkbookMapperTest.java b/src/test/java/com/ohdab/workbook/repository/mapper/WorkbookMapperTest.java new file mode 100644 index 00000000..9b2c2285 --- /dev/null +++ b/src/test/java/com/ohdab/workbook/repository/mapper/WorkbookMapperTest.java @@ -0,0 +1,90 @@ +package com.ohdab.workbook.repository.mapper; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.groups.Tuple.tuple; + +import com.ohdab.classroom.domain.classroomid.ClassroomId; +import com.ohdab.classroom.service.dto.ClassroomDetailDto; +import com.ohdab.workbook.domain.Workbook; +import com.ohdab.workbook.domain.workbookInfo.WorkbookInfo; +import com.ohdab.workbook.repository.WorkbookRepository; +import java.util.List; +import javax.persistence.EntityManager; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mybatis.spring.boot.test.autoconfigure.AutoConfigureMybatis; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest +@AutoConfigureMybatis +class WorkbookMapperTest { + + @Autowired private WorkbookMapper workbookMapper; + @Autowired private WorkbookRepository workbookRepository; + @Autowired private EntityManager em; + + @DisplayName("반 상세조회시 교재 목록 조회") + @Test + void 반_상세조회_교재목록() { + // given + final ClassroomId classroomId = new ClassroomId(1L); + final Workbook workbook1 = + Workbook.builder() + .classroomId(classroomId) + .workbookInfo( + WorkbookInfo.builder() + .name("책1") + .description("설명") + .startingNumber(1) + .endingNumber(2000) + .build()) + .build(); + final Workbook workbook2 = + Workbook.builder() + .classroomId(classroomId) + .workbookInfo( + WorkbookInfo.builder() + .name("책2") + .description("설명") + .startingNumber(1) + .endingNumber(2000) + .build()) + .build(); + final Workbook workbook3 = + Workbook.builder() + .classroomId(classroomId) + .workbookInfo( + WorkbookInfo.builder() + .name("책3") + .description("설명") + .startingNumber(1) + .endingNumber(2000) + .build()) + .build(); + + // when + Workbook savedWorkbook1 = workbookRepository.save(workbook1); + Workbook savedWorkbook2 = workbookRepository.save(workbook2); + Workbook savedWorkbook3 = workbookRepository.save(workbook3); + em.flush(); + em.clear(); + + List workbooks = + workbookMapper.findAllWorkbookForClassroomInfo( + List.of( + savedWorkbook1.getId(), + savedWorkbook2.getId(), + savedWorkbook3.getId())); + + // then + assertThat(workbooks) + .hasSize(3) + .extracting( + ClassroomDetailDto.WorkbookInfoDto::getWorkbookId, + ClassroomDetailDto.WorkbookInfoDto::getWorkbookName) + .contains(tuple(savedWorkbook3.getId(), "책3")) + .contains(tuple(savedWorkbook2.getId(), "책2")) + .contains(tuple(savedWorkbook1.getId(), "책1")); + } +}