-
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
Router를 정의했습니다. #17
Merged
Merged
Router를 정의했습니다. #17
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
baa8ac8
Feat: Router 정의
GeonH0 6f1738b
Fix: RecipeListRouter 정의
GeonH0 396e9bc
Fix: RecipeListViewController,RecipeListView coordinator삭제 router 적용
GeonH0 4213bfc
Fix: RecipeDetailViewController에 Drawable 적용
GeonH0 d49fa45
Fix: MainTabbarController에 router 적용
GeonH0 dfdf9a6
Fix: SceneDelegate에 Router 설정
GeonH0 e4b3115
Fix: 상수삭제후 바로 주입시키는 코드로 수정
GeonH0 9c07a9b
Fix: create___Dependencies 에서 make___ViewController로 네이밍 수정
GeonH0 87f16f7
Merge branch 'main' into feature/Router
GeonH0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,93 @@ | ||
// | ||
// Router.swift | ||
// HomeCafeRecipes | ||
// | ||
// Created by 김건호 on 7/9/24. | ||
// | ||
|
||
import UIKit | ||
|
||
public typealias NavigationBackClosure = () -> Void | ||
|
||
public protocol Drawable { | ||
var viewController: UIViewController? { get } | ||
} | ||
|
||
public protocol RouterProtocol { | ||
func push ( | ||
_ drawable: Drawable, | ||
from viewController: UIViewController, | ||
isAnimated: Bool, | ||
onNavigateBack closure: NavigationBackClosure? | ||
) | ||
} | ||
|
||
class Router: NSObject, RouterProtocol { | ||
private var closures: [String: NavigationBackClosure] = [:] | ||
|
||
func push( | ||
_ drawable: Drawable, | ||
from viewController: UIViewController, | ||
isAnimated: Bool, | ||
onNavigateBack closure: NavigationBackClosure? | ||
) { | ||
guard let targetViewController = drawable.viewController else { | ||
return | ||
} | ||
|
||
if let closure = closure { | ||
closures.updateValue(closure, forKey: targetViewController.description) | ||
} | ||
viewController.navigationController?.pushViewController(targetViewController, animated: isAnimated) | ||
} | ||
|
||
private func executeClosure(_ viewController: UIViewController) { | ||
guard let closure = closures.removeValue(forKey: viewController.description) else { return } | ||
closure() | ||
} | ||
} | ||
|
||
extension Router { | ||
func createRecipeListDependencies() -> RecipeListViewController { | ||
let baseNetworkService = BaseNetworkService() | ||
let recipeFetchService = RecipeFetchServiceImpl(networkService: baseNetworkService) | ||
let feedListRepository = FeedListRepositoryImpl(networkService: recipeFetchService) | ||
let searchFeedRepository = SearchFeedRepositoryImpl(networkService: recipeFetchService) | ||
let fetchFeedListUseCase = FetchFeedListUseCaseImpl(repository: feedListRepository) | ||
let searchFeedListUseCase = SearchFeedListUseCaseImpl(repository: searchFeedRepository) | ||
let recipeListInteractor = RecipeListInteractorImpl( | ||
fetchFeedListUseCase: fetchFeedListUseCase, | ||
searchFeedListUseCase: searchFeedListUseCase | ||
) | ||
let recipeListRouter = RecipeListRouterImpl(router: self) | ||
let recipeListVC = RecipeListViewController( | ||
interactor: recipeListInteractor, | ||
router: recipeListRouter | ||
) | ||
recipeListInteractor.delegate = recipeListVC | ||
return recipeListVC | ||
} | ||
|
||
func createAddRecipeDependencies(recipeType: RecipeType) -> AddRecipeViewController { | ||
let baseNetworkService = BaseNetworkService() | ||
let recipePostService = RecipePostServiceImpl(networkService: baseNetworkService) | ||
let saveRepository = AddRecipeRepositoryImpl(recipePostService: recipePostService) | ||
let saveRecipeUseCase = SaveRecipeUseCaseImpl(repository: saveRepository) | ||
let addRecipeInteractor = AddRecipeInteractorImpl(saveRecipeUseCase: saveRecipeUseCase) | ||
let addRecipeVC = AddRecipeViewController(recipeType: recipeType, addRecipeInteractor: addRecipeInteractor) | ||
return addRecipeVC | ||
} | ||
|
||
func createRecipeDetailDependencies(recipeID: Int) -> RecipeDetailViewController { | ||
let baseNetworkService = BaseNetworkService() | ||
let recipeDetailRepository = RecipeDetailRepositoryImpl(networkService: baseNetworkService) | ||
let fetchRecipeDetailUseCase = FetchRecipeDetailUseCaseImpl(repository: recipeDetailRepository) | ||
let detailInteractor = RecipeDetailInteractorImpl( | ||
fetchRecipeDetailUseCase: fetchRecipeDetailUseCase, | ||
recipeID: recipeID | ||
) | ||
let detailVC = RecipeDetailViewController(interactor: detailInteractor) | ||
detailInteractor.delegate = detailVC | ||
return detailVC | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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.
굳이 상수로 갖지 않고 바로 주입해도 될 것 같아요.
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.
이 코드 참고해서 다른 디펜던시들도 수정부탁드려요~
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.
[e4b3115] 수정했습니다