-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
44 additions
and
36 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
...va/com/example/whopper/domain/library/application/component/FindLibraryByIdComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
|
||
|
20 changes: 20 additions & 0 deletions
20
...ample/whopper/domain/library/application/component/impl/FindLibraryByIdComponentImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
25 changes: 7 additions & 18 deletions
25
...n/java/com/example/whopper/domain/library/application/impl/StudentFindLibraryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,24 @@ | ||
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; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StudentFindLibraryService implements StudentFindLibraryUseCase { | ||
|
||
private final LibraryMongoRepository libraryMongoRepository; | ||
private final PdfUseCase pdfUseCase; | ||
private final LibraryAdapter libraryAdapter; | ||
|
||
public DataResponseInfo<LibraryResponse> studentFindLibrary(Integer year) { | ||
var libraries = year == null | ||
? libraryMongoRepository.findFirstByAccessRightNot(AccessRight.PRIVATE) | ||
: libraryMongoRepository.findFirstByAccessRightNotAndYear(AccessRight.PRIVATE, year); | ||
public DataResponseInfo<LibraryResponse> 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()); | ||
} | ||
} |
25 changes: 7 additions & 18 deletions
25
...n/java/com/example/whopper/domain/library/application/impl/TeacherFindLibraryService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,24 @@ | ||
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; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class TeacherFindLibraryService implements TeacherFindLibraryUseCase { | ||
|
||
private final LibraryMongoRepository libraryMongoRepository; | ||
private final PdfUseCase pdfUseCase; | ||
private final LibraryAdapter libraryAdapter; | ||
|
||
public DataResponseInfo<LibraryResponse> teacherFindLibrary(Integer year) { | ||
var libraries = year == null | ||
? libraryMongoRepository.findFirstByAccessRightNot(AccessRight.PRIVATE) | ||
: libraryMongoRepository.findFirstByAccessRightNotAndYear(AccessRight.PRIVATE, year); | ||
public DataResponseInfo<LibraryResponse> 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()); | ||
} | ||
} |