-
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
레시피 업로드 Domain, Data 영역을 정의해 보았습니다. #18
Changes from 2 commits
928c743
ac56a82
13864c0
74c0206
afd9f0b
d7677a1
838777b
b1276ad
e95db90
58b4cc8
54cdfca
ed32a83
f527923
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// | ||
// AddRecipeInteractor.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 7/1/24. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
import RxSwift | ||
|
||
protocol AddRecipeInteractorDelegate: AnyObject { | ||
func didLoadRecipeData(viewModel: AddRecipeViewModel) | ||
} | ||
|
||
protocol AddRecipeInteractor { | ||
func saveRecipe(userID: Int, recipeType: RecipeType) -> Single<Result<Recipe, AddRecipeError>> | ||
func updateRecipeTitle(_ title: String) | ||
func updateRecipeDescription(_ description: String) | ||
func addRecipeImage(_ image: UIImage) | ||
func removeRecipeImage(at index: Int) | ||
func loadRecipeData() | ||
} | ||
|
||
class AddRecipeInteractorImpl: AddRecipeInteractor { | ||
private var recipeImages: [UIImage] = [] | ||
private var recipeTitle: String = "" | ||
private var recipeDescription: String = "" | ||
|
||
weak var delegate: AddRecipeInteractorDelegate? | ||
|
||
private let saveRecipeUseCase: AddRecipeUseCase | ||
|
||
init(saveRecipeUseCase: AddRecipeUseCase) { | ||
self.saveRecipeUseCase = saveRecipeUseCase | ||
} | ||
|
||
func saveRecipe(userID: Int, recipeType: RecipeType) -> Single<Result<Recipe, AddRecipeError>> { | ||
return saveRecipeUseCase.execute( | ||
userID: userID, | ||
recipeType: recipeType.rawValue, | ||
title: recipeTitle, | ||
description: recipeDescription, | ||
images: recipeImages | ||
) | ||
} | ||
|
||
func updateRecipeTitle(_ title: String) { | ||
self.recipeTitle = title | ||
} | ||
|
||
func updateRecipeDescription(_ description: String) { | ||
self.recipeDescription = description | ||
} | ||
|
||
func addRecipeImage(_ image: UIImage) { | ||
self.recipeImages.append(image) | ||
} | ||
|
||
func removeRecipeImage(at index: Int) { | ||
self.recipeImages.remove(at: index) | ||
} | ||
|
||
func loadRecipeData() { | ||
let viewModel = AddRecipeViewModel(images: recipeImages, title: recipeTitle, description: recipeDescription) | ||
delegate?.didLoadRecipeData(viewModel: viewModel) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// | ||
// SaveRecipeUseCase.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 7/1/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import RxSwift | ||
|
||
protocol AddRecipeUseCase { | ||
func execute( | ||
userID: Int, | ||
recipeType: String, | ||
title: String, | ||
description: String, | ||
images: [UIImage] | ||
) -> Single<Result<Recipe, AddRecipeError>> | ||
} | ||
|
||
class AddRecipeUseCaseImpl: AddRecipeUseCase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. final class 검토부탁해요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [54cdfca] 수정했습니다 |
||
private let repository: AddRecipeRepository | ||
|
||
init(repository: AddRecipeRepository) { | ||
self.repository = repository | ||
} | ||
|
||
func execute( | ||
userID: Int, | ||
recipeType: String, | ||
title: String, | ||
description: String, | ||
images: [UIImage] | ||
) -> Single<Result<Recipe, AddRecipeError>> { | ||
|
||
guard !images.isEmpty else { | ||
return .just(.failure(.noImages)) | ||
} | ||
|
||
guard !title.isBlank else { | ||
return .just(.failure(.titleIsEmpty)) | ||
} | ||
|
||
guard description.count > 10 else { | ||
return .just(.failure(.descriptionTooShort)) | ||
} | ||
Comment on lines
+37
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 좋네요 👍 |
||
|
||
return repository.saveRecipe( | ||
userID: userID, | ||
recipeType: recipeType, | ||
title: title, | ||
description: description, | ||
images: images | ||
) | ||
.map { .success($0) } | ||
.catch { .just(.failure(.genericError($0))) } | ||
} | ||
} |
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.
didLoadRecipe 정도로 해도 괜찮을 것 같아요. viewModel을 넘겨서 구성하는데 너무 도메인적인 네이밍 같아요.
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.
[58b4cc8] 수정했습니다