-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
π :: book λλ©μΈ μΈν #90
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
aea77d5
β¨ :: [#86] BookInfoEntity μΆκ°
shwaaaa 604e90f
β»οΈ :: [#86] BookInfoEntity / created_at νμ
μμ
shwaaaa 4061f69
β¨ :: [#86] FetchBookInfoResponseDTO μΆκ°
shwaaaa d517eab
β¨ :: [#86] WriteBookRequestDTO μΆκ°
shwaaaa 868c458
β¨ :: [#86] BookDetail μΆκ°
shwaaaa 9be713b
β¨ :: [#86] BookDomain UseCase μΆκ°
shwaaaa fb935f7
β¨ :: [#86] BookRepository μΆκ°
shwaaaa 1c32227
β¨ :: [#86] RemoteBookDataSource μΆκ°
shwaaaa d6fb719
β¨ :: [#86] BookDomain UseCaseImpl μΆκ°
shwaaaa 333cfc4
β¨ :: [#86] BookRepositoryImpl μΆκ°
shwaaaa 78a29bd
β¨ :: [#86] BookDomainError μΆκ°
shwaaaa 3129d97
β¨ :: [#86] BookAPI μΆκ°
shwaaaa 3dc5d6a
β¨ :: [#86] RemoteBookDataSourceImpl μΆκ°
shwaaaa 49df990
β»οΈ :: [#86] BookInfoEntity 곡백 μμ
shwaaaa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import Foundation | ||
import Moya | ||
|
||
public enum BookAPI { | ||
case writeBook(req: BookInfoRequestDTO) | ||
case bookList | ||
case bookDetail(book_id: Int) | ||
case modifyBook(book_id: Int, req: BookInfoRequestDTO) | ||
case deleteBook(book_id: Int) | ||
} | ||
|
||
extension BookAPI: MindWayAPI { | ||
public typealias ErrorType = BookDomainError | ||
|
||
public var domain: MindWayDomain { | ||
.book | ||
} | ||
|
||
public var urlPath: String { | ||
switch self { | ||
case .writeBook, .bookList: | ||
return "" | ||
case let .bookDetail(book_id), | ||
let .modifyBook(book_id, _), | ||
let .deleteBook(book_id): | ||
return "/\(book_id)" | ||
} | ||
} | ||
|
||
public var method: Moya.Method { | ||
switch self { | ||
case .bookList, .bookDetail: | ||
return .get | ||
case .writeBook: | ||
return .post | ||
case .modifyBook: | ||
return .patch | ||
case .deleteBook: | ||
return .delete | ||
} | ||
} | ||
|
||
public var task: Moya.Task { | ||
switch self { | ||
case let .writeBook(req): | ||
return .requestJSONEncodable(req) | ||
case let .modifyBook(_, req): | ||
return .requestJSONEncodable(req) | ||
case .bookList, .bookDetail, .deleteBook: | ||
return .requestPlain | ||
} | ||
} | ||
|
||
public var jwtTokenType: JwtTokenType { | ||
switch self { | ||
default: | ||
return .accessToken | ||
} | ||
} | ||
|
||
public var errorMap: [Int: ErrorType] { | ||
switch self { | ||
default: | ||
return [ | ||
401: .unauthorized | ||
] | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Service/Sources/Domain/BookDomain/DTO/Response/FetchBookDetailInfoResponseDTO.swift
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,23 @@ | ||
import Foundation | ||
|
||
public struct FetchBookDetailInfoResponseDTO: Decodable { | ||
public let title: String | ||
public let plot: String | ||
|
||
public init( | ||
title: String, | ||
plot: String | ||
) { | ||
self.title = title | ||
self.plot = plot | ||
} | ||
} | ||
|
||
extension FetchBookDetailInfoResponseDTO { | ||
func toDomain() -> BookDetialInfoEntity { | ||
BookDetialInfoEntity( | ||
title: title, | ||
plot: plot | ||
) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Service/Sources/Domain/BookDomain/DTO/Response/FetchBookInfoResponseDTO.swift
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,45 @@ | ||
import Foundation | ||
|
||
public struct FetchBookInfoResponseDTO: Decodable { | ||
public let book: [BookInfoResponseDTO] | ||
|
||
public init(book: [BookInfoResponseDTO]) { | ||
self.book = book | ||
} | ||
} | ||
|
||
public struct BookInfoResponseDTO: Decodable { | ||
public let id: Int | ||
public let title: String | ||
public let plot: String | ||
public let created_at: Date | ||
|
||
public init( | ||
id: Int, | ||
title: String, | ||
plot: String, | ||
created_at: Date | ||
) { | ||
self.id = id | ||
self.title = title | ||
self.plot = plot | ||
self.created_at = created_at | ||
} | ||
} | ||
|
||
extension FetchBookInfoResponseDTO { | ||
func toDomain() -> [BookInfoEntity] { | ||
book.map { $0.toDomain() } | ||
} | ||
} | ||
|
||
extension BookInfoResponseDTO { | ||
func toDomain() -> BookInfoEntity { | ||
BookInfoEntity( | ||
id: id, | ||
title: title, | ||
plot: plot, | ||
created_at: created_at | ||
) | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
Service/Sources/Domain/BookDomain/DataSource/RemoteBookDataSourceImpl.swift
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 @@ | ||
import Foundation | ||
|
||
public final class RemoteBookDataSourceImpl: BaseRemoteDataSource<BookAPI>, RemoteBookDataSource { | ||
public func writeBook(req: BookInfoRequestDTO) async throws { | ||
try await request(.writeBook(req: req)) | ||
} | ||
|
||
public func fetchBookList() async throws -> [BookInfoEntity] { | ||
try await request(.bookList, dto: FetchBookInfoResponseDTO.self) | ||
.toDomain() | ||
} | ||
|
||
public func modifyBook(book_id: Int, req: BookInfoRequestDTO) async throws { | ||
try await request(.modifyBook(book_id: book_id, req: req)) | ||
} | ||
|
||
public func deleteBook(book_id: Int) async throws { | ||
try await request(.deleteBook(book_id: book_id)) | ||
} | ||
|
||
public func fetchBookDetail(book_id: Int) async throws -> BookDetailInfoEntity { | ||
try await request(.bookDetail(book_id: book_id), dto: FetchBookDetailInfoResponseDTO.self) | ||
.toDomain() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift
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,14 @@ | ||
import Foundation | ||
|
||
public struct BookDetailInfoEntity: Equatable { | ||
public let title: String | ||
public let plot: String | ||
|
||
public init( | ||
title: String, | ||
plot: String | ||
) { | ||
self.title = title | ||
self.plot = plot | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift
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 @@ | ||
import Foundation | ||
|
||
public struct BookInfoEntity: Equatable { | ||
public let id: Int | ||
public let title: String | ||
public let plot: String | ||
public let created_at: Date | ||
|
||
public init( | ||
id: Int, | ||
title: String, | ||
plot: String, | ||
created_at: Date | ||
) { | ||
self.id = id | ||
self.title = title | ||
self.plot = plot | ||
self.created_at = created_at | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Service/Sources/Domain/BookDomain/Error/BookDomainError.swift
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,14 @@ | ||
import Foundation | ||
|
||
public enum BookDomainError: Error { | ||
case unauthorized | ||
} | ||
|
||
extension BookDomainError: LocalizedError { | ||
public var errorDescription: String? { | ||
switch self { | ||
case .unauthorized: | ||
return "κΆνμ΄ μμ΅λλ€." | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Service/Sources/Domain/BookDomain/Repository/BookRepositoryImpl.swift
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,31 @@ | ||
import Foundation | ||
|
||
public struct BookRepositoryImpl: BookRepository { | ||
private let remoteBookDataSource: any RemoteBookDataSource | ||
|
||
public init( | ||
remoteBookDataSource: any RemoteBookDataSource | ||
) { | ||
self.remoteBookDataSource = remoteBookDataSource | ||
} | ||
|
||
public func writeBook(req: BookInfoRequestDTO) async throws { | ||
try await remoteBookDataSource.writeBook(req: req) | ||
} | ||
|
||
public func fetchBookList() async throws -> [BookInfoEntity] { | ||
try await remoteBookDataSource.fetchBookList() | ||
} | ||
|
||
public func modifyBook(req: BookInfoRequestDTO) async throws { | ||
try await remoteBookDataSource.modifyBook(req: req) | ||
} | ||
|
||
public func deleteBook() async throws { | ||
try await remoteBookDataSource.deleteBook() | ||
} | ||
|
||
public func fetchBookDetail() async throws -> BookDetailInfoEntity { | ||
try await remoteBookDataSource.fetchBookDetail() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Service/Sources/Domain/BookDomain/UseCase/DeleteBookUseCaseImpl.swift
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,13 @@ | ||
import Foundation | ||
|
||
public struct DeleteBookUseCaseImpl: DeleteBookUseCase { | ||
private let bookRepository: any BookRepository | ||
|
||
public init(bookRepository: any BookRepository) { | ||
self.bookRepository = bookRepository | ||
} | ||
|
||
public func execute() async throws { | ||
try await bookRepository.deleteBook() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Service/Sources/Domain/BookDomain/UseCase/FetchBookDetailUseCaseImpl.swift
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,13 @@ | ||
import Foundation | ||
|
||
public struct FetchBookDetailUseCaseImpl: FetchBookDetailUseCase { | ||
private let bookRepository: any BookRepository | ||
|
||
public init(bookRepository: any BookRepository) { | ||
self.bookRepository = bookRepository | ||
} | ||
|
||
public func execute() async throws -> BookDetailInfoEntity { | ||
try await bookRepository.fetchBookDetail() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Service/Sources/Domain/BookDomain/UseCase/FetchBookListUseCaseImpl.swift
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,13 @@ | ||
import Foundation | ||
|
||
public struct FetchBookListUseCaseImpl: FetchBookListUseCase { | ||
private let bookRepository: any BookRepository | ||
|
||
public init(bookRepository: any BookRepository) { | ||
self.bookRepository = bookRepository | ||
} | ||
|
||
public func execute() async throws -> [BookInfoEntity]{ | ||
try await bookRepository.fetchBookList() | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Service/Sources/Domain/BookDomain/UseCase/ModifyBookUseCaseImpl.swift
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,13 @@ | ||
import Foundation | ||
|
||
public struct ModifyBookUseCaseImpl: ModifyBookUseCase { | ||
private let bookRepository: any BookRepository | ||
|
||
public init(bookRepository: any BookRepository) { | ||
self.bookRepository = bookRepository | ||
} | ||
|
||
public func execute(req: BookInfoRequestDTO) async throws { | ||
try await bookRepository.modifyBook(req: req) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
Service/Sources/Domain/BookDomain/UseCase/WriteBookUseCaseImpl.swift
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,13 @@ | ||
import Foundation | ||
|
||
public struct WriteBookUseCaseImpl: WriteBookUseCase { | ||
private let bookRepository: any BookRepository | ||
|
||
public init(bookRepository: any BookRepository) { | ||
self.bookRepository = bookRepository | ||
} | ||
|
||
public func execute(req: BookInfoRequestDTO) async throws { | ||
try await bookRepository.writeBook(req: req) | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
Service/Sources/Interface/DTO/Book/Request/BookInfoRequestDTO.swift
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,14 @@ | ||
import Foundation | ||
|
||
public struct BookInfoRequestDTO: Encodable { | ||
public let title: String | ||
public let plot: String | ||
|
||
public init( | ||
title: String, | ||
plot: String | ||
) { | ||
self.title = title | ||
self.plot = plot | ||
} | ||
} |
File renamed without changes.
9 changes: 9 additions & 0 deletions
9
Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift
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,9 @@ | ||
import Foundation | ||
|
||
public protocol RemoteBookDataSource { | ||
func writeBook(req: BookInfoRequestDTO) async throws | ||
func fetchBookList() async throws -> [BookInfoEntity] | ||
func modifyBook(book_id: Int, req: BookInfoRequestDTO) async throws | ||
func deleteBook(book_id: Int) async throws | ||
func fetchBookDetail(book_id: Int) async throws -> BookDetailInfoEntity | ||
} |
9 changes: 9 additions & 0 deletions
9
Service/Sources/Interface/Repository/Book/BookRepository.swift
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,9 @@ | ||
import Foundation | ||
|
||
public protocol BookRepository { | ||
func writeBook(req: BookInfoRequestDTO) async throws | ||
func fetchBookList() async throws -> [BookInfoEntity] | ||
func modifyBook(book_id: Int, req: BookInfoRequestDTO) async throws | ||
func deleteBook(book_id: Int) async throws | ||
func fetchBookDetail(book_id: Int) async throws -> BookDetailInfoEntity | ||
} |
5 changes: 5 additions & 0 deletions
5
Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift
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,5 @@ | ||
import Foundation | ||
|
||
public protocol DeleteBookUseCase { | ||
func execute(book_id: Int) async throws | ||
} |
5 changes: 5 additions & 0 deletions
5
Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift
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,5 @@ | ||
import Foundation | ||
|
||
public protocol FetchBookDetailUseCase { | ||
func execute(book_id: Int) async throws -> BookDetailInfoEntity | ||
} |
5 changes: 5 additions & 0 deletions
5
Service/Sources/Interface/UseCase/Book/FetchBookListUseCase.swift
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,5 @@ | ||
import Foundation | ||
|
||
public protocol FetchBookListUseCase { | ||
func execute() async throws -> [BookInfoEntity] | ||
} |
5 changes: 5 additions & 0 deletions
5
Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift
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,5 @@ | ||
import Foundation | ||
|
||
public protocol ModifyBookUseCase { | ||
func execute(book_id: Int, req: BookInfoRequestDTO) async throws | ||
} |
5 changes: 5 additions & 0 deletions
5
Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift
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,5 @@ | ||
import Foundation | ||
|
||
public protocol WriteBookUseCase { | ||
func execute(req: BookInfoRequestDTO) async throws | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API λͺ μΈμμ Longμ΄λ©΄ StringμΌλ‘ μ°μ§ μλμ??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
longμ΄λ©΄ μ€μνμ΄μ΄μ Intλ‘ μ¨μΌνλκ±Έλ‘ μκ³ μμ΄μ!