-
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 영역을 정의해 보았습니다. #13
Changes from 1 commit
6eb97ea
bab43de
4b09f04
3f7f570
429a962
6178184
e117629
8f79c55
c91393f
9ba8620
ed07510
cda676a
dbf2111
02a63aa
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,73 @@ | ||
// | ||
// RecipeDetailInteractor.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 6/27/24. | ||
// | ||
|
||
import Foundation | ||
import RxSwift | ||
|
||
protocol RecipeDetailInteractorDelegate: AnyObject { | ||
func fetchedRecipe(result: Result<Recipe, Error>) | ||
} | ||
|
||
protocol InputRecipeDetailInteractor { | ||
func viewDidLoad() | ||
} | ||
|
||
protocol OutputRecipeDetailInteractor { | ||
var recipe: Observable<Result<Recipe, Error>> { get } | ||
} | ||
Comment on lines
+19
to
+21
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. 이건 어떻게 활용되는거에요? 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. recipeDetailSubject를 Observable로 반환함으로써 외부에서 데이터를 읽기 전용으로 사용할 수 있습니다 |
||
|
||
class RecipeDetailInteractor: InputRecipeDetailInteractor, OutputRecipeDetailInteractor { | ||
|
||
private let fetchRecipeDetailUseCase: FetchRecipeDetailUseCase | ||
private let recipeID: Int | ||
private let disposeBag = DisposeBag() | ||
private let recipeDetailSubject = PublishSubject<Result<Recipe, Error>>() | ||
weak var delegate: RecipeDetailInteractorDelegate? | ||
|
||
var recipe: Observable<Result<Recipe, Error>> { | ||
return recipeDetailSubject.asObservable() | ||
} | ||
|
||
init(fetchRecipeDetailUseCase: FetchRecipeDetailUseCase, recipeID: Int) { | ||
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. 개행 부탁드려요 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. [9ba8620] 수정했습니다 |
||
self.fetchRecipeDetailUseCase = fetchRecipeDetailUseCase | ||
self.recipeID = recipeID | ||
} | ||
|
||
func setDelegate(_ delegate: RecipeDetailInteractorDelegate) { | ||
self.delegate = delegate | ||
bindOutputs() | ||
} | ||
|
||
private func bindOutputs() { | ||
recipe | ||
.subscribe(onNext: { [weak self] result in | ||
self?.delegate?.fetchedRecipe(result: result) | ||
}) | ||
.disposed(by: disposeBag) | ||
Comment on lines
+49
to
+53
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. 바로 델리게이트를 호출해도 될 것 같은데 recipe를 통하는 이유가 궁금해요. 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. recipe를 통해서 비동기 데이터를 전달하고, Delegate는 이벤트만을 처리하기 위해 만들어 둔것 입니다. |
||
} | ||
|
||
func viewDidLoad() { | ||
fetchRecipeDetail() | ||
} | ||
|
||
private func fetchRecipeDetail() { | ||
fetchRecipeDetailUseCase.execute(recipeID: recipeID) | ||
.subscribe { [weak self] result in | ||
self?.handleResult(result) | ||
} | ||
.disposed(by: disposeBag) | ||
} | ||
|
||
private func handleResult(_ result: Result<Recipe, Error>) { | ||
switch result { | ||
case .success(let recipe): | ||
self.recipeDetailSubject.onNext(.success(recipe)) | ||
case .failure(let error): | ||
self.recipeDetailSubject.onNext(.failure(error)) | ||
} | ||
} | ||
} |
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.
InputRecipeDetailInteractor -> RecipeDetailInteractor
RecipeDetailInteractorImpl: RecipeDetailInteractor
// vc에서 행동에 따른 비즈니스 로직 호출 ex) viewDidLoad
// 비즈니스 로직 -> return 도메인 모델 -> delegate로 vc에 전달 -> mapper -> return 뷰 모델 -> 뷰 업데이트
output 빼고