diff --git a/HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj b/HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj index f47c7eb..2773df9 100644 --- a/HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj +++ b/HomeCafeRecipes/HomeCafeRecipes.xcodeproj/project.pbxproj @@ -7,6 +7,23 @@ objects = { /* Begin PBXBuildFile section */ + 1D1283A22C15E94300C5A870 /* Recipe.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A12C15E94300C5A870 /* Recipe.swift */; }; + 1D1283A42C15EA8100C5A870 /* RecipeType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A32C15EA8100C5A870 /* RecipeType.swift */; }; + 1D1283A62C15EAA600C5A870 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A52C15EAA600C5A870 /* User.swift */; }; + 1D1283A82C15EABB00C5A870 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A72C15EABB00C5A870 /* Comment.swift */; }; + 1D1283AA2C15EBCF00C5A870 /* SearchFeedUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283A92C15EBCF00C5A870 /* SearchFeedUseCase.swift */; }; + 1D1283AC2C15EBE600C5A870 /* FetchFeedListUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283AB2C15EBE600C5A870 /* FetchFeedListUseCase.swift */; }; + 1D1283AF2C1697DB00C5A870 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283AE2C1697DB00C5A870 /* RxCocoa */; }; + 1D1283B12C1697DB00C5A870 /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283B02C1697DB00C5A870 /* RxSwift */; }; + 1D1283B42C16983900C5A870 /* RxSwift in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283B32C16983900C5A870 /* RxSwift */; }; + 1D1283B62C16984E00C5A870 /* RxCocoa in Frameworks */ = {isa = PBXBuildFile; productRef = 1D1283B52C16984E00C5A870 /* RxCocoa */; }; + 1D1283B82C169C0200C5A870 /* FeedListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283B72C169C0200C5A870 /* FeedListRepository.swift */; }; + 1D1283BA2C16A62800C5A870 /* SearchFeedListRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283B92C16A62800C5A870 /* SearchFeedListRepository.swift */; }; + 1D1283C12C16B05800C5A870 /* RecipeDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C02C16B05800C5A870 /* RecipeDTO.swift */; }; + 1D1283C32C16B06F00C5A870 /* UserDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C22C16B06F00C5A870 /* UserDTO.swift */; }; + 1D1283C52C16B07D00C5A870 /* CommentDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C42C16B07D00C5A870 /* CommentDTO.swift */; }; + 1D1283C82C16CE7C00C5A870 /* DateFormatter+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C72C16CE7C00C5A870 /* DateFormatter+Extensions.swift */; }; + 1D1283CA2C16D9C600C5A870 /* RecipeFetchService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D1283C92C16D9C600C5A870 /* RecipeFetchService.swift */; }; 1D2C16E62BE532B700C04508 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2C16E52BE532B700C04508 /* AppDelegate.swift */; }; 1D2C16E82BE532B700C04508 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2C16E72BE532B700C04508 /* SceneDelegate.swift */; }; 1D2C16EA2BE532B700C04508 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D2C16E92BE532B700C04508 /* ViewController.swift */; }; @@ -35,6 +52,19 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 1D1283A12C15E94300C5A870 /* Recipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Recipe.swift; sourceTree = ""; }; + 1D1283A32C15EA8100C5A870 /* RecipeType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeType.swift; sourceTree = ""; }; + 1D1283A52C15EAA600C5A870 /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; + 1D1283A72C15EABB00C5A870 /* Comment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = ""; }; + 1D1283A92C15EBCF00C5A870 /* SearchFeedUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchFeedUseCase.swift; sourceTree = ""; }; + 1D1283AB2C15EBE600C5A870 /* FetchFeedListUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchFeedListUseCase.swift; sourceTree = ""; }; + 1D1283B72C169C0200C5A870 /* FeedListRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeedListRepository.swift; sourceTree = ""; }; + 1D1283B92C16A62800C5A870 /* SearchFeedListRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchFeedListRepository.swift; sourceTree = ""; }; + 1D1283C02C16B05800C5A870 /* RecipeDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeDTO.swift; sourceTree = ""; }; + 1D1283C22C16B06F00C5A870 /* UserDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDTO.swift; sourceTree = ""; }; + 1D1283C42C16B07D00C5A870 /* CommentDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CommentDTO.swift; sourceTree = ""; }; + 1D1283C72C16CE7C00C5A870 /* DateFormatter+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateFormatter+Extensions.swift"; sourceTree = ""; }; + 1D1283C92C16D9C600C5A870 /* RecipeFetchService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecipeFetchService.swift; sourceTree = ""; }; 1D2C16E22BE532B700C04508 /* HomeCafeRecipes.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HomeCafeRecipes.app; sourceTree = BUILT_PRODUCTS_DIR; }; 1D2C16E52BE532B700C04508 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 1D2C16E72BE532B700C04508 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; @@ -54,6 +84,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1D1283B12C1697DB00C5A870 /* RxSwift in Frameworks */, + 1D1283AF2C1697DB00C5A870 /* RxCocoa in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -68,12 +100,87 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 1D1283B62C16984E00C5A870 /* RxCocoa in Frameworks */, + 1D1283B42C16983900C5A870 /* RxSwift in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 1D12839F2C15E7A700C5A870 /* Entities */ = { + isa = PBXGroup; + children = ( + 1D1283A12C15E94300C5A870 /* Recipe.swift */, + 1D1283A32C15EA8100C5A870 /* RecipeType.swift */, + 1D1283A52C15EAA600C5A870 /* User.swift */, + 1D1283A72C15EABB00C5A870 /* Comment.swift */, + ); + path = Entities; + sourceTree = ""; + }; + 1D1283A02C15E92C00C5A870 /* UseCases */ = { + isa = PBXGroup; + children = ( + 1D1283A92C15EBCF00C5A870 /* SearchFeedUseCase.swift */, + 1D1283AB2C15EBE600C5A870 /* FetchFeedListUseCase.swift */, + ); + path = UseCases; + sourceTree = ""; + }; + 1D1283AD2C16974B00C5A870 /* Data */ = { + isa = PBXGroup; + children = ( + 1D1283BC2C16AA8100C5A870 /* Network */, + 1D1283BB2C16AA6400C5A870 /* Repositories */, + ); + path = Data; + sourceTree = ""; + }; + 1D1283B22C16983900C5A870 /* Frameworks */ = { + isa = PBXGroup; + children = ( + ); + name = Frameworks; + sourceTree = ""; + }; + 1D1283BB2C16AA6400C5A870 /* Repositories */ = { + isa = PBXGroup; + children = ( + 1D1283B72C169C0200C5A870 /* FeedListRepository.swift */, + 1D1283B92C16A62800C5A870 /* SearchFeedListRepository.swift */, + ); + name = Repositories; + path = "ㄲ데ㅐ냐새갿ㄴ"; + sourceTree = ""; + }; + 1D1283BC2C16AA8100C5A870 /* Network */ = { + isa = PBXGroup; + children = ( + 1D1283BF2C16B02600C5A870 /* DTO */, + 1D1283C92C16D9C600C5A870 /* RecipeFetchService.swift */, + ); + path = Network; + sourceTree = ""; + }; + 1D1283BF2C16B02600C5A870 /* DTO */ = { + isa = PBXGroup; + children = ( + 1D1283C02C16B05800C5A870 /* RecipeDTO.swift */, + 1D1283C22C16B06F00C5A870 /* UserDTO.swift */, + 1D1283C42C16B07D00C5A870 /* CommentDTO.swift */, + ); + path = DTO; + sourceTree = ""; + }; + 1D1283C62C16CD9200C5A870 /* Utilities */ = { + isa = PBXGroup; + children = ( + 1D1283C72C16CE7C00C5A870 /* DateFormatter+Extensions.swift */, + ); + path = Utilities; + sourceTree = ""; + }; 1D2C16D92BE532B700C04508 = { isa = PBXGroup; children = ( @@ -81,6 +188,7 @@ 1D2C16FB2BE532B800C04508 /* HomeCafeRecipesTests */, 1D2C17052BE532B800C04508 /* HomeCafeRecipesUITests */, 1D2C16E32BE532B700C04508 /* Products */, + 1D1283B22C16983900C5A870 /* Frameworks */, ); sourceTree = ""; }; @@ -97,6 +205,9 @@ 1D2C16E42BE532B700C04508 /* HomeCafeRecipes */ = { isa = PBXGroup; children = ( + 1D1283C62C16CD9200C5A870 /* Utilities */, + 1D1283AD2C16974B00C5A870 /* Data */, + 1D740B402C15E6680001B704 /* Domain */, 1D2C16E52BE532B700C04508 /* AppDelegate.swift */, 1D2C16E72BE532B700C04508 /* SceneDelegate.swift */, 1D2C16E92BE532B700C04508 /* ViewController.swift */, @@ -124,6 +235,15 @@ path = HomeCafeRecipesUITests; sourceTree = ""; }; + 1D740B402C15E6680001B704 /* Domain */ = { + isa = PBXGroup; + children = ( + 1D1283A02C15E92C00C5A870 /* UseCases */, + 1D12839F2C15E7A700C5A870 /* Entities */, + ); + path = Domain; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -141,6 +261,8 @@ ); name = HomeCafeRecipes; packageProductDependencies = ( + 1D1283AE2C1697DB00C5A870 /* RxCocoa */, + 1D1283B02C1697DB00C5A870 /* RxSwift */, ); productName = HomeCafeRecipes; productReference = 1D2C16E22BE532B700C04508 /* HomeCafeRecipes.app */; @@ -178,6 +300,10 @@ 1D2C17042BE532B800C04508 /* PBXTargetDependency */, ); name = HomeCafeRecipesUITests; + packageProductDependencies = ( + 1D1283B32C16983900C5A870 /* RxSwift */, + 1D1283B52C16984E00C5A870 /* RxCocoa */, + ); productName = HomeCafeRecipesUITests; productReference = 1D2C17022BE532B800C04508 /* HomeCafeRecipesUITests.xctest */; productType = "com.apple.product-type.bundle.ui-testing"; @@ -261,7 +387,20 @@ files = ( 1D2C16EA2BE532B700C04508 /* ViewController.swift in Sources */, 1D2C16E62BE532B700C04508 /* AppDelegate.swift in Sources */, + 1D1283A62C15EAA600C5A870 /* User.swift in Sources */, + 1D1283C52C16B07D00C5A870 /* CommentDTO.swift in Sources */, + 1D1283AC2C15EBE600C5A870 /* FetchFeedListUseCase.swift in Sources */, + 1D1283A82C15EABB00C5A870 /* Comment.swift in Sources */, + 1D1283C82C16CE7C00C5A870 /* DateFormatter+Extensions.swift in Sources */, + 1D1283B82C169C0200C5A870 /* FeedListRepository.swift in Sources */, + 1D1283A42C15EA8100C5A870 /* RecipeType.swift in Sources */, + 1D1283AA2C15EBCF00C5A870 /* SearchFeedUseCase.swift in Sources */, 1D2C16E82BE532B700C04508 /* SceneDelegate.swift in Sources */, + 1D1283BA2C16A62800C5A870 /* SearchFeedListRepository.swift in Sources */, + 1D1283A22C15E94300C5A870 /* Recipe.swift in Sources */, + 1D1283CA2C16D9C600C5A870 /* RecipeFetchService.swift in Sources */, + 1D1283C32C16B06F00C5A870 /* UserDTO.swift in Sources */, + 1D1283C12C16B05800C5A870 /* RecipeDTO.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -609,6 +748,29 @@ }; }; /* End XCRemoteSwiftPackageReference section */ + +/* Begin XCSwiftPackageProductDependency section */ + 1D1283AE2C1697DB00C5A870 /* RxCocoa */ = { + isa = XCSwiftPackageProductDependency; + package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */; + productName = RxCocoa; + }; + 1D1283B02C1697DB00C5A870 /* RxSwift */ = { + isa = XCSwiftPackageProductDependency; + package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */; + productName = RxSwift; + }; + 1D1283B32C16983900C5A870 /* RxSwift */ = { + isa = XCSwiftPackageProductDependency; + package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */; + productName = RxSwift; + }; + 1D1283B52C16984E00C5A870 /* RxCocoa */ = { + isa = XCSwiftPackageProductDependency; + package = 1D740B3F2C15E1EC0001B704 /* XCRemoteSwiftPackageReference "RxSwift" */; + productName = RxCocoa; + }; +/* End XCSwiftPackageProductDependency section */ }; rootObject = 1D2C16DA2BE532B700C04508 /* Project object */; } diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/NetworkResponseDTO.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/NetworkResponseDTO.swift new file mode 100644 index 0000000..2399978 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/NetworkResponseDTO.swift @@ -0,0 +1,14 @@ +// +// RecipesResponseDTO.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/11/24. +// + +import Foundation + +struct NetworkResponseDTO: Decodable { + let statusCode: Int + let message: String + let data: T +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift new file mode 100644 index 0000000..6f1d198 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeDTO.swift @@ -0,0 +1,49 @@ +// +// RecipeDTO.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/10/24. +// + +import Foundation + +struct RecipeDTO: Decodable { + + let id: Int + let type: String + let name: String + let description: String + let likesCount: Int + let createdAt: String + let writer: UserDTO + let imageUrls: [RecipeImageDTO] + let isLikedByCurrentUser: Bool + + enum CodingKeys: String, CodingKey { + case id = "recipeId" + case type = "recipeType" + case name = "recipeName" + case description = "recipeDescription" + case likesCount = "recipeLikesCnt" + case createdAt = "createdAt" + case writer = "writer" + case imageUrls = "recipeImgUrls" + case isLikedByCurrentUser = "isLiked" + } +} + +extension RecipeDTO { + func toDomain() -> Recipe { + return Recipe( + id: id, + type: RecipeType(rawValue: type) ?? .coffee, + name: name, + description: description, + writer: writer.toDomain(), + imageUrls: imageUrls.map { $0.recipeImageUrl }, + isLikedByCurrentUser: isLikedByCurrentUser, + likeCount: likesCount, + createdAt: DateFormatter.iso8601.date(from: createdAt) ?? Date() + ) + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeImageDTO.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeImageDTO.swift new file mode 100644 index 0000000..bb5cdea --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipeImageDTO.swift @@ -0,0 +1,18 @@ +// +// RecipeImageDTO.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/11/24. +// + +import Foundation + +struct RecipeImageDTO: Decodable { + let recipeImageID: Int + let recipeImageUrl: String + + private enum CodingKeys: String, CodingKey { + case recipeImageID = "recipeImgId" + case recipeImageUrl = "recipeImgUrl" + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipePageDTO.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipePageDTO.swift new file mode 100644 index 0000000..7a72985 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Network/DTO/RecipePageDTO.swift @@ -0,0 +1,20 @@ +// +// RecipePageDTO.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/12/24. +// + +import Foundation + +struct RecipePageDTO: Decodable { + let totalPageNumber: Int + let pageNumber: Int + let recipes: [RecipeDTO] + + private enum CodingKeys: String, CodingKey { + case totalPageNumber = "totalPageNumber" + case pageNumber = "pageNumber" + case recipes = "recipes" + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/FeedListRepository.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/FeedListRepository.swift new file mode 100644 index 0000000..2fda774 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/FeedListRepository.swift @@ -0,0 +1,24 @@ +// +// FeedListRepository.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/10/24. +// + +import RxSwift + +protocol FeedListRepository { + func fetchRecipes(pageNumber: Int) -> Single<[Recipe]> +} + +class DefaultFeedListRepository: FeedListRepository { + private let networkService: RecipeFetchService + + init(networkService: RecipeFetchService) { + self.networkService = networkService + } + + func fetchRecipes(pageNumber: Int) -> Single<[Recipe]> { + return networkService.fetchRecipes(pageNumber: pageNumber) + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/SearchFeedListRepository.swift b/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/SearchFeedListRepository.swift new file mode 100644 index 0000000..6b4b21d --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Data/Repositories/SearchFeedListRepository.swift @@ -0,0 +1,25 @@ +// +// SearchFeedListRepository.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/10/24. +// + +import RxSwift + +protocol SearchFeedListRepository { + func searchRecipes(title: String, pageNumber: Int) -> Single<[Recipe]> +} + +class DefaultSearchFeedRepository: SearchFeedListRepository { + + private let networkService: RecipeFetchService + + init(networkService: RecipeFetchService) { + self.networkService = networkService + } + + func searchRecipes(title: String,pageNumber: Int) -> Single<[Recipe]> { + return networkService.searchRecipes(title: title, pageNumber: pageNumber) + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/Recipe.swift b/HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/Recipe.swift new file mode 100644 index 0000000..06e9520 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/Recipe.swift @@ -0,0 +1,20 @@ +// +// Recipe.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/9/24. +// + +import Foundation + +struct Recipe { + let id: Int + let type: RecipeType + let name: String + let description: String + let writer: User + let imageUrls: [String] + let isLikedByCurrentUser: Bool + let likeCount: Int + let createdAt: Date +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/RecipeType.swift b/HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/RecipeType.swift new file mode 100644 index 0000000..57c7b1b --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Domain/Entities/RecipeType.swift @@ -0,0 +1,13 @@ +// +// RecipeType.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/9/24. +// + + + +enum RecipeType: String { + case coffee + case dessert +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/FetchFeedListUseCase.swift b/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/FetchFeedListUseCase.swift new file mode 100644 index 0000000..f5b4152 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/FetchFeedListUseCase.swift @@ -0,0 +1,30 @@ +// +// FetchFeedListUseCase.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/9/24. +// + +import RxSwift + +protocol FetchFeedListUseCase { + func execute(pageNumber: Int) -> Single> +} + +class DefaultFetchFeedListUseCase: FetchFeedListUseCase { + private let repository: FeedListRepository + + init(repository: FeedListRepository) { + self.repository = repository + } + + func execute(pageNumber: Int) -> Single> { + return repository.fetchRecipes(pageNumber: pageNumber) + .map { recipes in + return .success(recipes) + } + .catch { error in + return .just(.failure(error)) + } + } +} diff --git a/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/SearchFeedUseCase.swift b/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/SearchFeedUseCase.swift new file mode 100644 index 0000000..68fd1c3 --- /dev/null +++ b/HomeCafeRecipes/HomeCafeRecipes/Domain/UseCases/SearchFeedUseCase.swift @@ -0,0 +1,30 @@ +// +// SearchFeedUseCase.swift +// HomeCafeRecipes +// +// Created by 김건호 on 6/9/24. +// + +import RxSwift + +protocol SearchFeedListUseCase { + func execute(title: String,pageNumber: Int) -> Single> +} + +class DefaultSearchFeedListUseCase: SearchFeedListUseCase { + private let repository: SearchFeedListRepository + + init(repository: SearchFeedListRepository) { + self.repository = repository + } + + func execute(title: String,pageNumber: Int) -> Single> { + return repository.searchRecipes(title: title,pageNumber: pageNumber) + .map { recipes in + return .success(recipes) + } + .catch { error in + return .just(.failure(error)) + } + } +}