From ec3c2fc4e50ac2f48f63e8f614951f120aa62986 Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 16:37:41 +0900 Subject: [PATCH 01/10] =?UTF-8?q?fix:=20controller=20=EB=8B=A8=EC=9C=84=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/FindClassroomDetailService.java | 33 --------------- .../mapper/ClassroomDetailServiceMapper.java | 36 ---------------- .../usecase/FindClassroomDetailUsecase.java | 8 ---- .../controller/ClassroomControllerTest.java | 41 ++++++++++++++----- 4 files changed, 30 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/com/ohdab/classroom/service/FindClassroomDetailService.java delete mode 100644 src/main/java/com/ohdab/classroom/service/mapper/ClassroomDetailServiceMapper.java delete mode 100644 src/main/java/com/ohdab/classroom/service/usecase/FindClassroomDetailUsecase.java 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/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/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java b/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java index ed622725..914e9ff9 100644 --- a/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java +++ b/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java @@ -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,11 +134,23 @@ class ClassroomControllerTest { // given final String url = "/classrooms/"; - List studentIds = new ArrayList<>(); - studentIds.add(3L); - - List workbookIds = new ArrayList<>(); - workbookIds.add(4L); + List studentInfoList = new ArrayList<>(); + studentInfoList.add( + ClassroomDetailDto.StudentInfo.builder().studentId(1L).studentName("갑").build()); + studentInfoList.add( + ClassroomDetailDto.StudentInfo.builder().studentId(2L).studentName("을").build()); + + List workbookInfoList = new ArrayList<>(); + workbookInfoList.add( + ClassroomDetailDto.WorkbookInfo.builder() + .workbookId(10L) + .workbookName("책10") + .build()); + workbookInfoList.add( + ClassroomDetailDto.WorkbookInfo.builder() + .workbookId(11L) + .workbookName("책11") + .build()); ClassroomDetailDtoResponse classroomDetailDtoResponse = ClassroomDetailDtoResponse.builder() @@ -149,12 +162,12 @@ class ClassroomControllerTest { .description("1반 설명") .grade("high1") .build()) - .studentIds(studentIds) - .workbookIds(workbookIds) + .studentInfoList(studentInfoList) + .workbookInfoList(workbookInfoList) .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}")); } From 218f402617f6e31500ce3aa6a41a868171877088 Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 16:38:44 +0900 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20mepper=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mistakenote/service/GetMistakeNoteInfoServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 = From 8624a1bf6027a1b045278d3148eba759456a2062 Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 16:39:42 +0900 Subject: [PATCH 03/10] =?UTF-8?q?fix:=20=EC=9A=94=EA=B5=AC=EC=82=AC?= =?UTF-8?q?=ED=95=AD=20=EB=B3=80=EA=B2=BD=EC=9C=BC=EB=A1=9C=20=EC=9D=B8?= =?UTF-8?q?=ED=95=9C=20controller=20=EC=9D=91=EB=8B=B5=EA=B0=92=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ClassroomController.java | 4 ++-- .../controller/mapper/ClassroomMapper.java | 21 +++++++++++++++++-- .../response/ClassroomDetailRes.java | 20 ++++++++++++++++-- 3 files changed, 39 insertions(+), 6 deletions(-) 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..1afe8d33 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.getStudentInfoList().stream() + .map( + studentInfo -> + ClassroomDetailRes.StudentInfo.builder() + .studentId(studentInfo.getStudentId()) + .studentName(studentInfo.getStudentName()) + .build()) + .collect(Collectors.toList())) + .workbookInfoList( + detailDto.getWorkbookInfoList().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; + } } From 23e492f460f42dc5fcc5708fb7bf2dd344e8666b Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 16:40:17 +0900 Subject: [PATCH 04/10] =?UTF-8?q?fix:=20memberMapper=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ohdab/member/repository/mapper/MemberMapper.java | 5 ++++- .../com/ohdab/member/repository/mapper/MemberMapperTest.java | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) 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..dde32e4f 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,14 @@ 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/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java b/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java index b30834b3..1ec051ed 100644 --- a/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java +++ b/src/test/java/com/ohdab/member/repository/mapper/MemberMapperTest.java @@ -53,7 +53,7 @@ class MemberMapperTest { // when List result = - memberMapper.findAllStudent( + memberMapper.findAllStudentForMistakeNoteInfo( List.of( savedStudent1.getId(), savedStudent2.getId(), From d23714a0bfc2a355c468c43804eb8859bd22142c Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 16:41:07 +0900 Subject: [PATCH 05/10] =?UTF-8?q?fix:=20memberMapper=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ohdab/mistakenote/service/GetMistakeNoteInfoService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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() From 1c00a396eafba451c9f53f9809f52fdfd74e0f8b Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 16:56:41 +0900 Subject: [PATCH 06/10] =?UTF-8?q?fix:=20dto=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20mapper=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GetClassroomDetailInfoService.java | 58 +++++++++++++++---- .../service/dto/ClassroomDetailDto.java | 24 ++++++-- .../repository/mapper/WorkbookMapper.java | 12 ++++ src/main/resources/mapper/MemberMapper.xml | 13 ++++- src/main/resources/mapper/WorkbookMapper.xml | 15 +++++ .../controller/ClassroomControllerTest.java | 4 +- 6 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java create mode 100644 src/main/resources/mapper/WorkbookMapper.xml diff --git a/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java b/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java index fd9d39a7..fd59b356 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)) + .studentInfoList(students) + .workbookInfoList(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..217fdce6 100644 --- a/src/main/java/com/ohdab/classroom/service/dto/ClassroomDetailDto.java +++ b/src/main/java/com/ohdab/classroom/service/dto/ClassroomDetailDto.java @@ -10,7 +10,7 @@ public class ClassroomDetailDto { @Getter @Builder - public static class ClassroomDetailDtoInfo { + public static class ClassroomDetailInfo { private String name; private String description; private String grade; @@ -29,10 +29,26 @@ public static class ClassroomDetailDtoResponse { private long teacherId; - private ClassroomDetailDtoInfo info; + private ClassroomDetailInfo info; - private List studentIds; + private List studentInfoList; - private List workbookIds; + 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/workbook/repository/mapper/WorkbookMapper.java b/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java new file mode 100644 index 00000000..d0ddb152 --- /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..a69cbe42 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..19698345 --- /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 914e9ff9..1c6fd428 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; @@ -157,7 +157,7 @@ class ClassroomControllerTest { .classroomId(1) .teacherId(2) .info( - ClassroomDetailDtoInfo.builder() + ClassroomDetailInfo.builder() .name("1반") .description("1반 설명") .grade("high1") From b70946f73ba570ec0565caf74531a1bca15adf3a Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 17:06:22 +0900 Subject: [PATCH 07/10] =?UTF-8?q?test:=20mapper=20=EB=8B=A8=EC=9C=84=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ... => UpdateWorkbookInfoDtoServiceTest.java} | 0 .../repository/mapper/MemberMapperTest.java | 57 +++++++++++++++++-- 2 files changed, 53 insertions(+), 4 deletions(-) rename src/test/java/com/ohdab/classroom/service/{UpdateWorkbookInfoServiceTest.java => UpdateWorkbookInfoDtoServiceTest.java} (100%) diff --git a/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoServiceTest.java b/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java similarity index 100% rename from src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoServiceTest.java rename to src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java 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 1ec051ed..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,7 +53,7 @@ class MemberMapperTest { em.clear(); // when - List result = + List result = memberMapper.findAllStudentForMistakeNoteInfo( List.of( savedStudent1.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(), "병")); From db9848f7fe0656fa3e45ec81c4c1318af203073d Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 17:06:44 +0900 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20dto=20=EC=9D=B4=EB=84=88=20?= =?UTF-8?q?=ED=81=B4=EB=9E=98=EC=8A=A4=EB=AA=85=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/mapper/ClassroomMapper.java | 4 +-- .../GetClassroomDetailInfoService.java | 12 ++++----- .../service/dto/ClassroomDetailDto.java | 13 +++++----- .../repository/mapper/MemberMapper.java | 3 ++- .../repository/mapper/WorkbookMapper.java | 2 +- src/main/resources/mapper/MemberMapper.xml | 2 +- src/main/resources/mapper/WorkbookMapper.xml | 2 +- .../controller/ClassroomControllerTest.java | 26 +++++++++---------- .../UpdateWorkbookInfoDtoServiceTest.java | 2 +- 9 files changed, 34 insertions(+), 32 deletions(-) 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 1afe8d33..e801f7a8 100644 --- a/src/main/java/com/ohdab/classroom/controller/mapper/ClassroomMapper.java +++ b/src/main/java/com/ohdab/classroom/controller/mapper/ClassroomMapper.java @@ -68,7 +68,7 @@ public static ClassroomDetailRes classroomDetailToClassroomDetailRes( .description(detailDto.getInfo().getDescription()) .grade(detailDto.getInfo().getGrade()) .studentInfoList( - detailDto.getStudentInfoList().stream() + detailDto.getStudentInfoDtoList().stream() .map( studentInfo -> ClassroomDetailRes.StudentInfo.builder() @@ -77,7 +77,7 @@ public static ClassroomDetailRes classroomDetailToClassroomDetailRes( .build()) .collect(Collectors.toList())) .workbookInfoList( - detailDto.getWorkbookInfoList().stream() + detailDto.getWorkbookInfoDtoList().stream() .map( workbookInfo -> ClassroomDetailRes.WorkbookInfo.builder() diff --git a/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java b/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java index fd59b356..c7143ef6 100644 --- a/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java +++ b/src/main/java/com/ohdab/classroom/service/GetClassroomDetailInfoService.java @@ -29,10 +29,10 @@ public class GetClassroomDetailInfoService implements GetClassroomDetailInfoUsec @Override public ClassroomDetailDtoResponse getClassroomDetailById(long classroomId) { Classroom classroom = findExistingClassroom(classroomId, classroomRepository); - List students = + List students = memberMapper.findAllStudentForClassroomInfo( getStudentIdList(classroom.getStudents())); - List workbooks = + List workbooks = workbookMapper.findAllWorkbookForClassroomInfo( getWorkbookIdList(classroom.getWorkbooks())); return mapToClassroomDetailDtoResponse(classroom, students, workbooks); @@ -48,14 +48,14 @@ private List getWorkbookIdList(List workbookIds) { private ClassroomDetailDtoResponse mapToClassroomDetailDtoResponse( Classroom classroom, - List students, - List workbooks) { + List students, + List workbooks) { return ClassroomDetailDtoResponse.builder() .classroomId(classroom.getId()) .teacherId(classroom.getTeacher().getId()) .info(mapToClassRoomDetailInfo(classroom)) - .studentInfoList(students) - .workbookInfoList(workbooks) + .studentInfoDtoList(students) + .workbookInfoDtoList(workbooks) .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 217fdce6..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,11 +1,12 @@ 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 @@ -31,14 +32,14 @@ public static class ClassroomDetailDtoResponse { private ClassroomDetailInfo info; - private List studentInfoList; + private List studentInfoDtoList; - private List workbookInfoList; + private List workbookInfoDtoList; } @Getter @Builder - public static class StudentInfo { + public static class StudentInfoDto { private long studentId; private String studentName; @@ -46,7 +47,7 @@ public static class StudentInfo { @Getter @Builder - public static class WorkbookInfo { + public static class WorkbookInfoDto { private long workbookId; private String workbookName; 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 dde32e4f..f2afe6e8 100644 --- a/src/main/java/com/ohdab/member/repository/mapper/MemberMapper.java +++ b/src/main/java/com/ohdab/member/repository/mapper/MemberMapper.java @@ -11,5 +11,6 @@ public interface MemberMapper { List findAllStudentForMistakeNoteInfo(List studentIdList); - List findAllStudentForClassroomInfo(List studentIdList); + List findAllStudentForClassroomInfo( + List studentIdList); } diff --git a/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java b/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java index d0ddb152..fa664aa0 100644 --- a/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java +++ b/src/main/java/com/ohdab/workbook/repository/mapper/WorkbookMapper.java @@ -7,6 +7,6 @@ @Mapper public interface WorkbookMapper { - List findAllWorkbookForClassroomInfo( + List findAllWorkbookForClassroomInfo( List workbookIdList); } diff --git a/src/main/resources/mapper/MemberMapper.xml b/src/main/resources/mapper/MemberMapper.xml index a69cbe42..bc93789e 100644 --- a/src/main/resources/mapper/MemberMapper.xml +++ b/src/main/resources/mapper/MemberMapper.xml @@ -13,7 +13,7 @@ order by member_id asc - select member_id as "studentId", member_name as "name" from MEMBER diff --git a/src/main/resources/mapper/WorkbookMapper.xml b/src/main/resources/mapper/WorkbookMapper.xml index 19698345..0f51dbdd 100644 --- a/src/main/resources/mapper/WorkbookMapper.xml +++ b/src/main/resources/mapper/WorkbookMapper.xml @@ -2,7 +2,7 @@ - select workbook_name as "wrongName", workbook_id as "workbookId" from WORKBOOK diff --git a/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java b/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java index 1c6fd428..8fc8d093 100644 --- a/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java +++ b/src/test/java/com/ohdab/classroom/controller/ClassroomControllerTest.java @@ -134,20 +134,20 @@ class ClassroomControllerTest { // given final String url = "/classrooms/"; - List studentInfoList = new ArrayList<>(); - studentInfoList.add( - ClassroomDetailDto.StudentInfo.builder().studentId(1L).studentName("갑").build()); - studentInfoList.add( - ClassroomDetailDto.StudentInfo.builder().studentId(2L).studentName("을").build()); - - List workbookInfoList = new ArrayList<>(); - workbookInfoList.add( - ClassroomDetailDto.WorkbookInfo.builder() + 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()); - workbookInfoList.add( - ClassroomDetailDto.WorkbookInfo.builder() + workbookInfoDtoList.add( + ClassroomDetailDto.WorkbookInfoDto.builder() .workbookId(11L) .workbookName("책11") .build()); @@ -162,8 +162,8 @@ class ClassroomControllerTest { .description("1반 설명") .grade("high1") .build()) - .studentInfoList(studentInfoList) - .workbookInfoList(workbookInfoList) + .studentInfoDtoList(studentInfoDtoList) + .workbookInfoDtoList(workbookInfoDtoList) .build(); // when diff --git a/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java b/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.java index ac15c3ad..0f040c55 100644 --- a/src/test/java/com/ohdab/classroom/service/UpdateWorkbookInfoDtoServiceTest.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; From 05a2bb6905607e48953fd995ea9418c4b7f4cb05 Mon Sep 17 00:00:00 2001 From: simhani1 Date: Wed, 16 Aug 2023 17:20:06 +0900 Subject: [PATCH 09/10] =?UTF-8?q?fix:=20=EC=B9=BC=EB=9F=BC=20=EB=B3=84?= =?UTF-8?q?=EB=AA=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/mapper/WorkbookMapper.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/mapper/WorkbookMapper.xml b/src/main/resources/mapper/WorkbookMapper.xml index 0f51dbdd..7b181b4e 100644 --- a/src/main/resources/mapper/WorkbookMapper.xml +++ b/src/main/resources/mapper/WorkbookMapper.xml @@ -3,8 +3,8 @@ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">