diff --git a/src/main/java/com/example/whopper/domain/library/application/component/FindLibraryByIdComponent.java b/src/main/java/com/example/whopper/domain/library/application/component/FindLibraryByIdComponent.java new file mode 100644 index 00000000..c411c5a8 --- /dev/null +++ b/src/main/java/com/example/whopper/domain/library/application/component/FindLibraryByIdComponent.java @@ -0,0 +1,10 @@ +package com.example.whopper.domain.library.application.component; + +import com.example.whopper.domain.library.domain.LibraryEntity; + +public interface FindLibraryByIdComponent { + LibraryEntity findLibraryById(String libraryId); +} + + + diff --git a/src/main/java/com/example/whopper/domain/library/application/component/impl/FindLibraryByIdComponentImpl.java b/src/main/java/com/example/whopper/domain/library/application/component/impl/FindLibraryByIdComponentImpl.java new file mode 100644 index 00000000..d0b8bb48 --- /dev/null +++ b/src/main/java/com/example/whopper/domain/library/application/component/impl/FindLibraryByIdComponentImpl.java @@ -0,0 +1,20 @@ +package com.example.whopper.domain.library.application.component.impl; + +import com.example.whopper.domain.library.application.component.FindLibraryByIdComponent; +import com.example.whopper.domain.library.dao.LibraryMongoRepository; +import com.example.whopper.domain.library.domain.LibraryEntity; +import com.example.whopper.domain.library.exception.LibraryNotFoundException; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +public class FindLibraryByIdComponentImpl implements FindLibraryByIdComponent { + + private final LibraryMongoRepository libraryMongoRepository; + + public LibraryEntity findLibraryById(String libraryId) { + return libraryMongoRepository.findById(libraryId) + .orElseThrow(()-> LibraryNotFoundException.EXCEPTION); + } +} diff --git a/src/main/java/com/example/whopper/domain/library/application/impl/StudentFindLibraryService.java b/src/main/java/com/example/whopper/domain/library/application/impl/StudentFindLibraryService.java index 98aa5bec..373c96a6 100644 --- a/src/main/java/com/example/whopper/domain/library/application/impl/StudentFindLibraryService.java +++ b/src/main/java/com/example/whopper/domain/library/application/impl/StudentFindLibraryService.java @@ -1,11 +1,11 @@ package com.example.whopper.domain.library.application.impl; -import com.example.whopper.domain.file.application.usecase.PdfUseCase; +import com.example.whopper.domain.library.application.dao.LibraryAdapter; import com.example.whopper.domain.library.application.usecase.StudentFindLibraryUseCase; -import com.example.whopper.domain.library.dao.LibraryMongoRepository; import com.example.whopper.domain.library.domain.type.AccessRight; import com.example.whopper.domain.library.dto.response.LibraryResponse; import com.example.whopper.global.utils.DataResponseInfo; +import jakarta.annotation.Nullable; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -13,23 +13,12 @@ @RequiredArgsConstructor public class StudentFindLibraryService implements StudentFindLibraryUseCase { - private final LibraryMongoRepository libraryMongoRepository; - private final PdfUseCase pdfUseCase; + private final LibraryAdapter libraryAdapter; - public DataResponseInfo studentFindLibrary(Integer year) { - var libraries = year == null - ? libraryMongoRepository.findFirstByAccessRightNot(AccessRight.PRIVATE) - : libraryMongoRepository.findFirstByAccessRightNotAndYear(AccessRight.PRIVATE, year); + public DataResponseInfo studentFindLibrary(@Nullable Integer year) { + var arthurLibrary = libraryAdapter.getLibrary(AccessRight.PRIVATE, year); - return DataResponseInfo.of(libraries.stream() - .map(library -> new LibraryResponse( - null, - null, - library.getYear(), - library.getGrade(), - library.getGeneration(), - pdfUseCase.getPdfFileUrl(library.getFilePath()) - )) - .toList()); + return DataResponseInfo.of(arthurLibrary.stream() + .map(LibraryResponse::from).toList()); } } diff --git a/src/main/java/com/example/whopper/domain/library/application/impl/TeacherFindLibraryService.java b/src/main/java/com/example/whopper/domain/library/application/impl/TeacherFindLibraryService.java index 7c73017a..5e2feca0 100644 --- a/src/main/java/com/example/whopper/domain/library/application/impl/TeacherFindLibraryService.java +++ b/src/main/java/com/example/whopper/domain/library/application/impl/TeacherFindLibraryService.java @@ -1,11 +1,11 @@ package com.example.whopper.domain.library.application.impl; -import com.example.whopper.domain.file.application.usecase.PdfUseCase; +import com.example.whopper.domain.library.application.dao.LibraryAdapter; import com.example.whopper.domain.library.application.usecase.TeacherFindLibraryUseCase; -import com.example.whopper.domain.library.dao.LibraryMongoRepository; import com.example.whopper.domain.library.domain.type.AccessRight; import com.example.whopper.domain.library.dto.response.LibraryResponse; import com.example.whopper.global.utils.DataResponseInfo; +import jakarta.annotation.Nullable; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -13,23 +13,12 @@ @RequiredArgsConstructor public class TeacherFindLibraryService implements TeacherFindLibraryUseCase { - private final LibraryMongoRepository libraryMongoRepository; - private final PdfUseCase pdfUseCase; + private final LibraryAdapter libraryAdapter; - public DataResponseInfo teacherFindLibrary(Integer year) { - var libraries = year == null - ? libraryMongoRepository.findFirstByAccessRightNot(AccessRight.PRIVATE) - : libraryMongoRepository.findFirstByAccessRightNotAndYear(AccessRight.PRIVATE, year); + public DataResponseInfo teacherFindLibrary(@Nullable Integer year) { + var arthurLibrary = libraryAdapter.getLibrary(AccessRight.PRIVATE, year); - return DataResponseInfo.of(libraries.stream() - .map(library -> new LibraryResponse( - library.getId(), - library.getAccessRight(), - library.getYear(), - library.getGrade(), - library.getGeneration(), - pdfUseCase.getPdfFileUrl(library.getFilePath()) - )) - .toList()); + return DataResponseInfo.of(arthurLibrary.stream() + .map(LibraryResponse::from).toList()); } }