-
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.
Merge pull request #65 from DSM-Repo/refactor-project-#1
pr :: 도서관 목록 조회 api 리팩토링
- Loading branch information
Showing
8 changed files
with
104 additions
and
20 deletions.
There are no files selected for viewing
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/example/whopper/domain/library/application/dao/LibraryAdapter.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,39 @@ | ||
package com.example.whopper.domain.library.application.dao; | ||
|
||
import com.example.whopper.domain.file.application.usecase.PdfUseCase; | ||
import com.example.whopper.domain.library.application.model.Library; | ||
import com.example.whopper.domain.library.dao.LibraryMongoRepository; | ||
import com.example.whopper.domain.library.domain.type.AccessRight; | ||
import jakarta.annotation.Nullable; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Optional; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class LibraryAdapter { | ||
|
||
private final LibraryMongoRepository libraryMongoRepository; | ||
private final PdfUseCase pdfUseCase; | ||
|
||
public Optional<Library> getLibrary(AccessRight accessRight, @Nullable Integer year) { | ||
if (year == null) { | ||
return libraryMongoRepository.findFirstByAccessRightNot(accessRight) | ||
.map(it -> { | ||
var pdfFileUrl = pdfUseCase.getPdfFileUrl(it.getFilePath()); | ||
return it.toModel(pdfFileUrl); | ||
} | ||
); | ||
} | ||
|
||
return libraryMongoRepository.findFirstByAccessRightNotAndYear( | ||
accessRight, year | ||
).map(it -> { | ||
var pdfFileUrl = pdfUseCase.getPdfFileUrl(it.getFilePath()); | ||
return it.toModel(pdfFileUrl); | ||
} | ||
); | ||
} | ||
|
||
} |
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
24 changes: 7 additions & 17 deletions
24
...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,25 @@ | ||
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.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()) | ||
)) | ||
return DataResponseInfo.of(arthurLibrary.stream() | ||
.map(LibraryResponse::from) | ||
.toList()); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
src/main/java/com/example/whopper/domain/library/application/model/Library.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,25 @@ | ||
package com.example.whopper.domain.library.application.model; | ||
|
||
import com.example.whopper.domain.library.domain.DocumentIndex; | ||
import com.example.whopper.domain.library.domain.type.AccessRight; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Getter | ||
public record Library( | ||
String id, | ||
Integer year, | ||
Integer grade, | ||
LocalDateTime createAt, | ||
AccessRight accessRight, | ||
List<DocumentIndex> books, | ||
String pdfFileUrl | ||
) { | ||
|
||
public Integer getGeneration() { | ||
return this.year - this.grade - 2013; | ||
} | ||
|
||
} |
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
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