From aea77d5d239b3baa247bf245a79be98a7e3bec84 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 01:46:34 +0900 Subject: [PATCH 01/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookInfoEntity?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookDomain/Entity/BookInfoEntity.swift | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift diff --git a/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift b/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift new file mode 100644 index 0000000..f126156 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift @@ -0,0 +1,21 @@ +import Foundation + +public struct BookInfoEntity: Equatable { + public let id: Int + public let title: String + public let plot: String + public let created_at: String + + public init( + id: Int, + title: String, + plot: String, + created_at: String + + ) { + self.id = id + self.title = title + self.plot = plot + self.created_at = created_at + } +} From 604e90f0100a41bdbec633a43c2013d7a52861d0 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 01:49:30 +0900 Subject: [PATCH 02/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20[#86]=20BookInf?= =?UTF-8?q?oEntity=20/=20created=5Fat=20=ED=83=80=EC=9E=85=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift b/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift index f126156..2a7500b 100644 --- a/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift +++ b/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift @@ -4,13 +4,13 @@ public struct BookInfoEntity: Equatable { public let id: Int public let title: String public let plot: String - public let created_at: String + public let created_at: Date public init( id: Int, title: String, plot: String, - created_at: String + created_at: Date ) { self.id = id From 4061f69a2ea5f7654521e6aefb506af84c4343d2 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 01:54:54 +0900 Subject: [PATCH 03/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20FetchBookInfoRes?= =?UTF-8?q?ponseDTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Response/FetchBookInfoResponseDTO.swift | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Service/Sources/Domain/BookDomain/DTO/Response/FetchBookInfoResponseDTO.swift diff --git a/Service/Sources/Domain/BookDomain/DTO/Response/FetchBookInfoResponseDTO.swift b/Service/Sources/Domain/BookDomain/DTO/Response/FetchBookInfoResponseDTO.swift new file mode 100644 index 0000000..c1bd2a5 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/DTO/Response/FetchBookInfoResponseDTO.swift @@ -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 + ) + } +} From d517eab79ad757b1cb18f59dcbf78d6828a141ae Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 01:57:39 +0900 Subject: [PATCH 04/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20WriteBookRequest?= =?UTF-8?q?DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DTO/Book/Request/WriteBookRequestDTO.swift | 14 ++++++++++++++ .../{ => Goal}/Request/SettingGoalRequestDTO.swift | 0 2 files changed, 14 insertions(+) create mode 100644 Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift rename Service/Sources/Interface/DTO/{ => Goal}/Request/SettingGoalRequestDTO.swift (100%) diff --git a/Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift b/Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift new file mode 100644 index 0000000..515fc36 --- /dev/null +++ b/Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift @@ -0,0 +1,14 @@ +import Foundation + +public struct WriteBookRequestDTO: Encodable { + public let title: String + public let plot: String + + public init( + title: String, + plot: String + ) { + self.title = title + self.plot = plot + } +} diff --git a/Service/Sources/Interface/DTO/Request/SettingGoalRequestDTO.swift b/Service/Sources/Interface/DTO/Goal/Request/SettingGoalRequestDTO.swift similarity index 100% rename from Service/Sources/Interface/DTO/Request/SettingGoalRequestDTO.swift rename to Service/Sources/Interface/DTO/Goal/Request/SettingGoalRequestDTO.swift From 868c458aee81a8a8c6480d58721fe7372774dc2d Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 02:03:32 +0900 Subject: [PATCH 05/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookDetail=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../FetchBookDetailInfoResponseDTO.swift | 23 +++++++++++++++++++ .../Entity/BookDetailInfoEntity.swift | 15 ++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Service/Sources/Domain/BookDomain/DTO/Response/FetchBookDetailInfoResponseDTO.swift create mode 100644 Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift diff --git a/Service/Sources/Domain/BookDomain/DTO/Response/FetchBookDetailInfoResponseDTO.swift b/Service/Sources/Domain/BookDomain/DTO/Response/FetchBookDetailInfoResponseDTO.swift new file mode 100644 index 0000000..77084c9 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/DTO/Response/FetchBookDetailInfoResponseDTO.swift @@ -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 + ) + } +} diff --git a/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift b/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift new file mode 100644 index 0000000..c05a694 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift @@ -0,0 +1,15 @@ +import Foundation + +public struct BookDetialInfoEntity: Equatable { + public let title: String + public let plot: String + + public init( + title: String, + plot: String + + ) { + self.title = title + self.plot = plot + } +} From 9be713b2c773d84af93c73876aeebbbd56bbf3dd Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 02:07:09 +0900 Subject: [PATCH 06/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookDomain=20Use?= =?UTF-8?q?Case=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Sources/Interface/UseCase/Book/DeleteBookUseCase.swift | 5 +++++ .../Interface/UseCase/Book/FetchBookDetailUseCase.swift | 5 +++++ .../Interface/UseCase/Book/FetchBookListUseCase.swift | 5 +++++ .../Sources/Interface/UseCase/Book/ModifyBookUseCase.swift | 5 +++++ .../Sources/Interface/UseCase/Book/WriteBookUseCase.swift | 5 +++++ 5 files changed, 25 insertions(+) create mode 100644 Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift create mode 100644 Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift create mode 100644 Service/Sources/Interface/UseCase/Book/FetchBookListUseCase.swift create mode 100644 Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift create mode 100644 Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift diff --git a/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift new file mode 100644 index 0000000..c78abdd --- /dev/null +++ b/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol DeleteBookUseCase { + func execute() async throws +} diff --git a/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift b/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift new file mode 100644 index 0000000..ec3b3ba --- /dev/null +++ b/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol FetchBookDetailUseCase { + func execute() async throws -> [BookDetialInfoEntity] +} diff --git a/Service/Sources/Interface/UseCase/Book/FetchBookListUseCase.swift b/Service/Sources/Interface/UseCase/Book/FetchBookListUseCase.swift new file mode 100644 index 0000000..dac462b --- /dev/null +++ b/Service/Sources/Interface/UseCase/Book/FetchBookListUseCase.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol FetchBookListUseCase { + func execute() async throws -> [BookInfoEntity] +} diff --git a/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift new file mode 100644 index 0000000..eca62d7 --- /dev/null +++ b/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol ModifyBookUseCase { + func execute() async throws +} diff --git a/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift new file mode 100644 index 0000000..14ff22f --- /dev/null +++ b/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift @@ -0,0 +1,5 @@ +import Foundation + +public protocol WriteBookUseCase { + func execute() async throws +} From fb935f71745649033f2b4d2cb0ad27532fe5c32d Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 10:13:52 +0900 Subject: [PATCH 07/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookRepository?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/BookDomain/Entity/BookDetailInfoEntity.swift | 1 - .../GoalDomain/UseCase/SettingGoalUseCaseImpl.swift | 4 ++-- .../Interface/Repository/Book/BookRepository.swift | 9 +++++++++ .../Interface/UseCase/Goal/SettingGoalUseCase.swift | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 Service/Sources/Interface/Repository/Book/BookRepository.swift diff --git a/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift b/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift index c05a694..559086a 100644 --- a/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift +++ b/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift @@ -7,7 +7,6 @@ public struct BookDetialInfoEntity: Equatable { public init( title: String, plot: String - ) { self.title = title self.plot = plot diff --git a/Service/Sources/Domain/GoalDomain/UseCase/SettingGoalUseCaseImpl.swift b/Service/Sources/Domain/GoalDomain/UseCase/SettingGoalUseCaseImpl.swift index 1737f94..6c8d625 100644 --- a/Service/Sources/Domain/GoalDomain/UseCase/SettingGoalUseCaseImpl.swift +++ b/Service/Sources/Domain/GoalDomain/UseCase/SettingGoalUseCaseImpl.swift @@ -7,7 +7,7 @@ public struct SettingGoalUseCaseImpl: SettingGoalUseCase { self.goalRepository = goalRepository } - public func execute() async throws { - try await goalRepository.settingGoal() + public func execute(req: SettingGoalRequestDTO) async throws { + try await goalRepository.settingGoal(req: req) } } diff --git a/Service/Sources/Interface/Repository/Book/BookRepository.swift b/Service/Sources/Interface/Repository/Book/BookRepository.swift new file mode 100644 index 0000000..753a46f --- /dev/null +++ b/Service/Sources/Interface/Repository/Book/BookRepository.swift @@ -0,0 +1,9 @@ +import Foundation + +public protocol BookRepository { + func writeBook(req: WriteBookRequestDTO) async throws + func fetchBookList() async throws -> [BookInfoEntity] + func modifyBook(req: BookDetialInfoEntity) async throws + func deleteBook() async throws + func fetchBookDetail() async throws -> BookDetialInfoEntity +} diff --git a/Service/Sources/Interface/UseCase/Goal/SettingGoalUseCase.swift b/Service/Sources/Interface/UseCase/Goal/SettingGoalUseCase.swift index deb3622..dac9b5a 100644 --- a/Service/Sources/Interface/UseCase/Goal/SettingGoalUseCase.swift +++ b/Service/Sources/Interface/UseCase/Goal/SettingGoalUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol SettingGoalUseCase { - func execute() async throws + func execute(req: SettingGoalRequestDTO) async throws } From 1c322273e8f21b0c4e7c7322f4d61bfe6a4d14cf Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 10:14:46 +0900 Subject: [PATCH 08/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20RemoteBookDataSo?= =?UTF-8?q?urce=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/DataSource/Book/RemoteBookDataSource.swift | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift diff --git a/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift b/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift new file mode 100644 index 0000000..2eb25ca --- /dev/null +++ b/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift @@ -0,0 +1,9 @@ +import Foundation + +public protocol RemoteBookDataSource { + func writeBook(req: WriteBookRequestDTO) async throws + func fetchBookList() async throws -> [BookInfoEntity] + func modifyBook(req: BookDetialInfoEntity) async throws + func deleteBook() async throws + func fetchBookDetail() async throws -> BookDetialInfoEntity +} From d6fb719f548e858785671565f49afc65af3af482 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 10:30:50 +0900 Subject: [PATCH 09/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookDomain=20Use?= =?UTF-8?q?CaseImpl=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BookDomain/Entity/BookDetailInfoEntity.swift | 2 +- .../BookDomain/UseCase/DeleteBookUseCaseImpl.swift | 13 +++++++++++++ .../UseCase/FetchBookDetailUseCaseImpl.swift | 13 +++++++++++++ .../UseCase/FetchBookListUseCaseImpl.swift | 13 +++++++++++++ .../BookDomain/UseCase/ModifyBookUseCaseImpl.swift | 13 +++++++++++++ .../BookDomain/UseCase/WriteBookUseCaseImpl.swift | 13 +++++++++++++ ...ookRequestDTO.swift => BookInfoRequestDTO.swift} | 2 +- .../DataSource/Book/RemoteBookDataSource.swift | 6 +++--- .../Interface/Repository/Book/BookRepository.swift | 6 +++--- .../UseCase/Book/FetchBookDetailUseCase.swift | 2 +- .../Interface/UseCase/Book/ModifyBookUseCase.swift | 2 +- .../Interface/UseCase/Book/WriteBookUseCase.swift | 2 +- 12 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 Service/Sources/Domain/BookDomain/UseCase/DeleteBookUseCaseImpl.swift create mode 100644 Service/Sources/Domain/BookDomain/UseCase/FetchBookDetailUseCaseImpl.swift create mode 100644 Service/Sources/Domain/BookDomain/UseCase/FetchBookListUseCaseImpl.swift create mode 100644 Service/Sources/Domain/BookDomain/UseCase/ModifyBookUseCaseImpl.swift create mode 100644 Service/Sources/Domain/BookDomain/UseCase/WriteBookUseCaseImpl.swift rename Service/Sources/Interface/DTO/Book/Request/{WriteBookRequestDTO.swift => BookInfoRequestDTO.swift} (81%) diff --git a/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift b/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift index 559086a..07a99c4 100644 --- a/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift +++ b/Service/Sources/Domain/BookDomain/Entity/BookDetailInfoEntity.swift @@ -1,6 +1,6 @@ import Foundation -public struct BookDetialInfoEntity: Equatable { +public struct BookDetailInfoEntity: Equatable { public let title: String public let plot: String diff --git a/Service/Sources/Domain/BookDomain/UseCase/DeleteBookUseCaseImpl.swift b/Service/Sources/Domain/BookDomain/UseCase/DeleteBookUseCaseImpl.swift new file mode 100644 index 0000000..16613cd --- /dev/null +++ b/Service/Sources/Domain/BookDomain/UseCase/DeleteBookUseCaseImpl.swift @@ -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() + } +} diff --git a/Service/Sources/Domain/BookDomain/UseCase/FetchBookDetailUseCaseImpl.swift b/Service/Sources/Domain/BookDomain/UseCase/FetchBookDetailUseCaseImpl.swift new file mode 100644 index 0000000..a590b6e --- /dev/null +++ b/Service/Sources/Domain/BookDomain/UseCase/FetchBookDetailUseCaseImpl.swift @@ -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() + } +} diff --git a/Service/Sources/Domain/BookDomain/UseCase/FetchBookListUseCaseImpl.swift b/Service/Sources/Domain/BookDomain/UseCase/FetchBookListUseCaseImpl.swift new file mode 100644 index 0000000..516e44b --- /dev/null +++ b/Service/Sources/Domain/BookDomain/UseCase/FetchBookListUseCaseImpl.swift @@ -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() + } +} diff --git a/Service/Sources/Domain/BookDomain/UseCase/ModifyBookUseCaseImpl.swift b/Service/Sources/Domain/BookDomain/UseCase/ModifyBookUseCaseImpl.swift new file mode 100644 index 0000000..7eefe12 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/UseCase/ModifyBookUseCaseImpl.swift @@ -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) + } +} diff --git a/Service/Sources/Domain/BookDomain/UseCase/WriteBookUseCaseImpl.swift b/Service/Sources/Domain/BookDomain/UseCase/WriteBookUseCaseImpl.swift new file mode 100644 index 0000000..d2dd3c6 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/UseCase/WriteBookUseCaseImpl.swift @@ -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) + } +} diff --git a/Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift b/Service/Sources/Interface/DTO/Book/Request/BookInfoRequestDTO.swift similarity index 81% rename from Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift rename to Service/Sources/Interface/DTO/Book/Request/BookInfoRequestDTO.swift index 515fc36..1e81cf7 100644 --- a/Service/Sources/Interface/DTO/Book/Request/WriteBookRequestDTO.swift +++ b/Service/Sources/Interface/DTO/Book/Request/BookInfoRequestDTO.swift @@ -1,6 +1,6 @@ import Foundation -public struct WriteBookRequestDTO: Encodable { +public struct BookInfoRequestDTO: Encodable { public let title: String public let plot: String diff --git a/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift b/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift index 2eb25ca..881a778 100644 --- a/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift +++ b/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift @@ -1,9 +1,9 @@ import Foundation public protocol RemoteBookDataSource { - func writeBook(req: WriteBookRequestDTO) async throws + func writeBook(req: BookInfoRequestDTO) async throws func fetchBookList() async throws -> [BookInfoEntity] - func modifyBook(req: BookDetialInfoEntity) async throws + func modifyBook(req: BookInfoRequestDTO) async throws func deleteBook() async throws - func fetchBookDetail() async throws -> BookDetialInfoEntity + func fetchBookDetail() async throws -> BookDetailInfoEntity } diff --git a/Service/Sources/Interface/Repository/Book/BookRepository.swift b/Service/Sources/Interface/Repository/Book/BookRepository.swift index 753a46f..89479cc 100644 --- a/Service/Sources/Interface/Repository/Book/BookRepository.swift +++ b/Service/Sources/Interface/Repository/Book/BookRepository.swift @@ -1,9 +1,9 @@ import Foundation public protocol BookRepository { - func writeBook(req: WriteBookRequestDTO) async throws + func writeBook(req: BookInfoRequestDTO) async throws func fetchBookList() async throws -> [BookInfoEntity] - func modifyBook(req: BookDetialInfoEntity) async throws + func modifyBook(req: BookInfoRequestDTO) async throws func deleteBook() async throws - func fetchBookDetail() async throws -> BookDetialInfoEntity + func fetchBookDetail() async throws -> BookDetailInfoEntity } diff --git a/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift b/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift index ec3b3ba..b8557aa 100644 --- a/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift +++ b/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol FetchBookDetailUseCase { - func execute() async throws -> [BookDetialInfoEntity] + func execute() async throws -> BookDetailInfoEntity } diff --git a/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift index eca62d7..e939a46 100644 --- a/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift +++ b/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol ModifyBookUseCase { - func execute() async throws + func execute(req: BookInfoRequestDTO) async throws } diff --git a/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift index 14ff22f..30280c9 100644 --- a/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift +++ b/Service/Sources/Interface/UseCase/Book/WriteBookUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol WriteBookUseCase { - func execute() async throws + func execute(req: BookInfoRequestDTO) async throws } From 333cfc42923cf16468b77586de0cca05ae5fd8f3 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 10:33:05 +0900 Subject: [PATCH 10/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookRepositoryIm?= =?UTF-8?q?pl=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Repository/BookRepositoryImpl.swift | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Service/Sources/Domain/BookDomain/Repository/BookRepositoryImpl.swift diff --git a/Service/Sources/Domain/BookDomain/Repository/BookRepositoryImpl.swift b/Service/Sources/Domain/BookDomain/Repository/BookRepositoryImpl.swift new file mode 100644 index 0000000..26b6b7e --- /dev/null +++ b/Service/Sources/Domain/BookDomain/Repository/BookRepositoryImpl.swift @@ -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() + } +} From 78a29bd1d245ac8ecbbac321ce85866b3475c81b Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 10:36:09 +0900 Subject: [PATCH 11/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookDomainError?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/BookDomain/Error/BookDomainError.swift | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Service/Sources/Domain/BookDomain/Error/BookDomainError.swift diff --git a/Service/Sources/Domain/BookDomain/Error/BookDomainError.swift b/Service/Sources/Domain/BookDomain/Error/BookDomainError.swift new file mode 100644 index 0000000..5b43699 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/Error/BookDomainError.swift @@ -0,0 +1,14 @@ +import Foundation + +public enum BookDomainError: Error { + case unauthorized +} + +extension BookDomainError: LocalizedError { + public var errorDescription: String? { + switch self { + case .unauthorized: + return "권한이 없습니다." + } + } +} From 3129d9773a051a0abb0731598b2786e620fc3f19 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 12:04:07 +0900 Subject: [PATCH 12/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20BookAPI=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/BookDomain/API/BookAPI.swift | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 Service/Sources/Domain/BookDomain/API/BookAPI.swift diff --git a/Service/Sources/Domain/BookDomain/API/BookAPI.swift b/Service/Sources/Domain/BookDomain/API/BookAPI.swift new file mode 100644 index 0000000..6c8de19 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/API/BookAPI.swift @@ -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 + ] + } + } +} From 3dc5d6a8ba9bcf87e283e38a5ce33fbd2ef4e332 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Mon, 17 Jun 2024 12:12:07 +0900 Subject: [PATCH 13/14] =?UTF-8?q?=E2=9C=A8=20::=20[#86]=20RemoteBookDataSo?= =?UTF-8?q?urceImpl=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DataSource/RemoteBookDataSourceImpl.swift | 25 +++++++++++++++++++ .../Book/RemoteBookDataSource.swift | 6 ++--- .../Repository/Book/BookRepository.swift | 6 ++--- .../UseCase/Book/DeleteBookUseCase.swift | 2 +- .../UseCase/Book/FetchBookDetailUseCase.swift | 2 +- .../UseCase/Book/ModifyBookUseCase.swift | 2 +- 6 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 Service/Sources/Domain/BookDomain/DataSource/RemoteBookDataSourceImpl.swift diff --git a/Service/Sources/Domain/BookDomain/DataSource/RemoteBookDataSourceImpl.swift b/Service/Sources/Domain/BookDomain/DataSource/RemoteBookDataSourceImpl.swift new file mode 100644 index 0000000..59a8555 --- /dev/null +++ b/Service/Sources/Domain/BookDomain/DataSource/RemoteBookDataSourceImpl.swift @@ -0,0 +1,25 @@ +import Foundation + +public final class RemoteBookDataSourceImpl: BaseRemoteDataSource, 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() + } +} diff --git a/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift b/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift index 881a778..04617be 100644 --- a/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift +++ b/Service/Sources/Interface/DataSource/Book/RemoteBookDataSource.swift @@ -3,7 +3,7 @@ import Foundation public protocol RemoteBookDataSource { func writeBook(req: BookInfoRequestDTO) async throws func fetchBookList() async throws -> [BookInfoEntity] - func modifyBook(req: BookInfoRequestDTO) async throws - func deleteBook() async throws - func fetchBookDetail() async throws -> BookDetailInfoEntity + func modifyBook(book_id: Int, req: BookInfoRequestDTO) async throws + func deleteBook(book_id: Int) async throws + func fetchBookDetail(book_id: Int) async throws -> BookDetailInfoEntity } diff --git a/Service/Sources/Interface/Repository/Book/BookRepository.swift b/Service/Sources/Interface/Repository/Book/BookRepository.swift index 89479cc..447b375 100644 --- a/Service/Sources/Interface/Repository/Book/BookRepository.swift +++ b/Service/Sources/Interface/Repository/Book/BookRepository.swift @@ -3,7 +3,7 @@ import Foundation public protocol BookRepository { func writeBook(req: BookInfoRequestDTO) async throws func fetchBookList() async throws -> [BookInfoEntity] - func modifyBook(req: BookInfoRequestDTO) async throws - func deleteBook() async throws - func fetchBookDetail() async throws -> BookDetailInfoEntity + func modifyBook(book_id: Int, req: BookInfoRequestDTO) async throws + func deleteBook(book_id: Int) async throws + func fetchBookDetail(book_id: Int) async throws -> BookDetailInfoEntity } diff --git a/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift index c78abdd..2513d0e 100644 --- a/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift +++ b/Service/Sources/Interface/UseCase/Book/DeleteBookUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol DeleteBookUseCase { - func execute() async throws + func execute(book_id: Int) async throws } diff --git a/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift b/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift index b8557aa..7762d48 100644 --- a/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift +++ b/Service/Sources/Interface/UseCase/Book/FetchBookDetailUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol FetchBookDetailUseCase { - func execute() async throws -> BookDetailInfoEntity + func execute(book_id: Int) async throws -> BookDetailInfoEntity } diff --git a/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift b/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift index e939a46..f8d7a6b 100644 --- a/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift +++ b/Service/Sources/Interface/UseCase/Book/ModifyBookUseCase.swift @@ -1,5 +1,5 @@ import Foundation public protocol ModifyBookUseCase { - func execute(req: BookInfoRequestDTO) async throws + func execute(book_id: Int, req: BookInfoRequestDTO) async throws } From 49df99015d232183fef984165e7aa3e3fc5940a4 Mon Sep 17 00:00:00 2001 From: shwaaaa Date: Tue, 18 Jun 2024 09:55:41 +0900 Subject: [PATCH 14/14] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20::=20[#86]=20BookInf?= =?UTF-8?q?oEntity=20=EA=B3=B5=EB=B0=B1=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift b/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift index 2a7500b..b730b80 100644 --- a/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift +++ b/Service/Sources/Domain/BookDomain/Entity/BookInfoEntity.swift @@ -11,7 +11,6 @@ public struct BookInfoEntity: Equatable { title: String, plot: String, created_at: Date - ) { self.id = id self.title = title