-
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 #90 from Team-MindWay/86-book-domain-setting
🔀 :: book 도메인 세팅
- Loading branch information
Showing
24 changed files
with
366 additions
and
3 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
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.