Skip to content
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

[REFACTOR] Curriculum, Challenge, Bookmark Adaptor Pattern 적용 (#155) #158

Merged
merged 12 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions LionHeart-iOS/LionHeart-iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
B53F4EE52ADBC23F001C5752 /* MyPageFactoryImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EE42ADBC23F001C5752 /* MyPageFactoryImpl.swift */; };
B53F4EE72ADBC29F001C5752 /* CurriculumFactoryImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EE62ADBC29F001C5752 /* CurriculumFactoryImpl.swift */; };
B53F4EE92ADBC44B001C5752 /* CurriculumArticleByWeekControllerable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EE82ADBC44B001C5752 /* CurriculumArticleByWeekControllerable.swift */; };
B53F4EEE2ADE245B001C5752 /* CurriculumAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EED2ADE245B001C5752 /* CurriculumAdaptor.swift */; };
B53F4EF22ADE2687001C5752 /* CurriculumCoordinatorImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EF12ADE2687001C5752 /* CurriculumCoordinatorImpl.swift */; };
B53F4EF62ADE2DEB001C5752 /* ChallengeAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EF52ADE2DEB001C5752 /* ChallengeAdaptor.swift */; };
B53F4EF82ADE2FB0001C5752 /* ChallengeCoordinatorImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EF72ADE2FB0001C5752 /* ChallengeCoordinatorImpl.swift */; };
B53F4EFA2ADE3151001C5752 /* BookmarkAdaptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EF92ADE3151001C5752 /* BookmarkAdaptor.swift */; };
B53F4EFC2ADE3341001C5752 /* BookmarkCoordinatorImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = B53F4EFB2ADE3341001C5752 /* BookmarkCoordinatorImpl.swift */; };
B57BEB612A60E97100D1727C /* NetworkErrorCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEB602A60E97100D1727C /* NetworkErrorCode.swift */; };
B57BEB632A612DA100D1727C /* UserDefaultsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEB622A612DA100D1727C /* UserDefaultsManager.swift */; };
B57BEB652A6134B800D1727C /* setRootViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B57BEB642A6134B800D1727C /* setRootViewController.swift */; };
Expand Down Expand Up @@ -375,6 +381,12 @@
B53F4EE42ADBC23F001C5752 /* MyPageFactoryImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPageFactoryImpl.swift; sourceTree = "<group>"; };
B53F4EE62ADBC29F001C5752 /* CurriculumFactoryImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurriculumFactoryImpl.swift; sourceTree = "<group>"; };
B53F4EE82ADBC44B001C5752 /* CurriculumArticleByWeekControllerable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurriculumArticleByWeekControllerable.swift; sourceTree = "<group>"; };
B53F4EED2ADE245B001C5752 /* CurriculumAdaptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurriculumAdaptor.swift; sourceTree = "<group>"; };
B53F4EF12ADE2687001C5752 /* CurriculumCoordinatorImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurriculumCoordinatorImpl.swift; sourceTree = "<group>"; };
B53F4EF52ADE2DEB001C5752 /* ChallengeAdaptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengeAdaptor.swift; sourceTree = "<group>"; };
B53F4EF72ADE2FB0001C5752 /* ChallengeCoordinatorImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengeCoordinatorImpl.swift; sourceTree = "<group>"; };
B53F4EF92ADE3151001C5752 /* BookmarkAdaptor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkAdaptor.swift; sourceTree = "<group>"; };
B53F4EFB2ADE3341001C5752 /* BookmarkCoordinatorImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarkCoordinatorImpl.swift; sourceTree = "<group>"; };
B57BEB602A60E97100D1727C /* NetworkErrorCode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkErrorCode.swift; sourceTree = "<group>"; };
B57BEB622A612DA100D1727C /* UserDefaultsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsManager.swift; sourceTree = "<group>"; };
B57BEB642A6134B800D1727C /* setRootViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = setRootViewController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1444,6 +1456,9 @@
isa = PBXGroup;
children = (
C04BE3AE2ADD4F7F001967B5 /* TodayAdaptor.swift */,
B53F4EED2ADE245B001C5752 /* CurriculumAdaptor.swift */,
B53F4EF52ADE2DEB001C5752 /* ChallengeAdaptor.swift */,
B53F4EF92ADE3151001C5752 /* BookmarkAdaptor.swift */,
C034EDD72ADE21D200AD6FF3 /* SplashAdaptor.swift */,
C034EDDB2ADE2A2C00AD6FF3 /* AuthAdaptor.swift */,
C034EE1D2ADE44E200AD6FF3 /* ArticleCategoryAdaptor.swift */,
Expand Down Expand Up @@ -1474,6 +1489,9 @@
children = (
C003CC222AD9183600AFFAAC /* AuthCoordinatorImpl.swift */,
C04BE3AC2ADD4F5D001967B5 /* TodayCoordinatorImpl.swift */,
B53F4EF12ADE2687001C5752 /* CurriculumCoordinatorImpl.swift */,
B53F4EF72ADE2FB0001C5752 /* ChallengeCoordinatorImpl.swift */,
B53F4EFB2ADE3341001C5752 /* BookmarkCoordinatorImpl.swift */,
C003CC1E2AD917F900AFFAAC /* SplashCoordinatorImpl.swift */,
C003CC262AD9185A00AFFAAC /* ArticleCategoryCoordinatorImpl.swift */,
);
Expand Down Expand Up @@ -1886,6 +1904,7 @@
F47329E12A66F5D0001605D4 /* CurriculumResponse.swift in Sources */,
C0F029E42A5FB08700E0D185 /* LHUnderLine.swift in Sources */,
C06E38282A662D8700B00600 /* TodayArticleResponse.swift in Sources */,
B53F4EF22ADE2687001C5752 /* CurriculumCoordinatorImpl.swift in Sources */,
C003CC552ADA4FD500AFFAAC /* SplashNavigation.swift in Sources */,
C0DF03732A5A9CB50037F740 /* TodayViewController.swift in Sources */,
C00780B72A5FFE0E0043EB36 /* UILabel+.swift in Sources */,
Expand Down Expand Up @@ -1949,9 +1968,11 @@
C0DF039A2A5B908E0037F740 /* CGColor+.swift in Sources */,
C034EE1E2ADE44E200AD6FF3 /* ArticleCategoryAdaptor.swift in Sources */,
C003CC662ADA518E00AFFAAC /* ArticleDetailManager.swift in Sources */,
B53F4EF62ADE2DEB001C5752 /* ChallengeAdaptor.swift in Sources */,
4AD216402A69AC1E00C9F2F2 /* MyPageResponse.swift in Sources */,
C003CC1F2AD917F900AFFAAC /* SplashCoordinatorImpl.swift in Sources */,
C003CC6E2ADA51E200AFFAAC /* CurriculumListManager.swift in Sources */,
B53F4EFA2ADE3151001C5752 /* BookmarkAdaptor.swift in Sources */,
D35272D12A681E13002D7FCB /* ChallengeData.swift in Sources */,
C065F00D2ADBD29A0094912C /* OnboardingViewControllerable.swift in Sources */,
B59893132A5D3A4D00CE1FEB /* NetworkError.swift in Sources */,
Expand All @@ -1965,6 +1986,7 @@
C003CC432ADA4EFF00AFFAAC /* MyPageNavigation.swift in Sources */,
C003CC512ADA4FA600AFFAAC /* CompleteOnbardingNavigation.swift in Sources */,
C09A33232A62D46300B40770 /* LHToastView.swift in Sources */,
B53F4EF82ADE2FB0001C5752 /* ChallengeCoordinatorImpl.swift in Sources */,
B532E8632A5529B000F0DB19 /* HTTPHeaderField.swift in Sources */,
D34280772A66B90C00DA1499 /* UILabelPadding.swift in Sources */,
B598930F2A5BED0F00CE1FEB /* Font.swift in Sources */,
Expand All @@ -1978,6 +2000,7 @@
C034EDDC2ADE2A2C00AD6FF3 /* AuthAdaptor.swift in Sources */,
B57BEB702A6275F500D1727C /* ViewControllerServiceable.swift in Sources */,
C0DF032F2A5A92170037F740 /* NameSpace.swift in Sources */,
B53F4EFC2ADE3341001C5752 /* BookmarkCoordinatorImpl.swift in Sources */,
C0856B6D2ABFBD840026D9F8 /* BookmarkServiceImpl.swift in Sources */,
B59892EE2A5B9AF300CE1FEB /* NavigationBarLayoutManager.swift in Sources */,
C0DF032D2A5A91D90037F740 /* DataTypeProtocol.swift in Sources */,
Expand Down Expand Up @@ -2084,6 +2107,7 @@
C003CC3D2ADA4EB300AFFAAC /* ChallengeNavigation.swift in Sources */,
C0B15E232AC100690058D56B /* LHStackView.swift in Sources */,
B59BFD432ADBBFF5005D2D81 /* ArticleFactory.swift in Sources */,
B53F4EEE2ADE245B001C5752 /* CurriculumAdaptor.swift in Sources */,
C0856B732ABFC3070026D9F8 /* BookmarkMangerImpl.swift in Sources */,
B57BEB632A612DA100D1727C /* UserDefaultsManager.swift in Sources */,
C0DF037B2A5A9CF30037F740 /* OnboardingViewController.swift in Sources */,
Expand Down
31 changes: 31 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Scenes/Adaptor/BookmarkAdaptor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// BookmarkAdaptor.swift
// LionHeart-iOS
//
// Created by 김민재 on 10/17/23.
//

import Foundation

typealias EntireBookmarkNavigation = BookmarkNavigation

final class BookmarkAdaptor: EntireBookmarkNavigation {

let coordinator: BookmarkCoordinator

init(coordinator: BookmarkCoordinator) {
self.coordinator = coordinator
}

func bookmarkCellTapped(articleID: Int) {
coordinator.showArticleDetailViewController(articleId: articleID)
}

func checkTokenIsExpired() {
coordinator.exitApplication()
}

func backButtonTapped() {
coordinator.pop()
}
}
31 changes: 31 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Scenes/Adaptor/ChallengeAdaptor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// ChallengeAdaptor.swift
// LionHeart-iOS
//
// Created by 김민재 on 10/17/23.
//

import Foundation

typealias EntireChallengeNavigation = ChallengeNavigation

final class ChallengeAdaptor: EntireChallengeNavigation {

let coordinator: ChallengeCoordinator

init(coordinator: ChallengeCoordinator) {
self.coordinator = coordinator
}

func navigationRightButtonTapped() {
self.coordinator.showMypageViewController()
}

func navigationLeftButtonTapped() {
self.coordinator.showBookmarkViewController()
}

func checkTokenIsExpired() {
self.coordinator.exitApplication()
}
}
45 changes: 45 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Scenes/Adaptor/CurriculumAdaptor.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// CurriculumAdaptor.swift
// LionHeart-iOS
//
// Created by 김민재 on 10/17/23.
//

import Foundation

typealias EntireCurriculumNavigation = CurriculumNavigation & CurriculumListByWeekNavigation


final class CurriculumAdaptor: EntireCurriculumNavigation {

let coordinator: CurriculumCoordinator

init(coordinator: CurriculumCoordinator) {
self.coordinator = coordinator
}

func articleListCellTapped(itemIndex: Int) {
self.coordinator.showCurriculumListViewController(itemIndex: itemIndex)
}

func navigationRightButtonTapped() {
self.coordinator.showMypageViewController()
}

func navigationLeftButtonTapped() {
self.coordinator.showBookmarkViewController()
}

func checkTokenIsExpired() {
self.coordinator.exitApplication()
}

func curriculumArticleListCellTapped(articleId: Int) {
self.coordinator.showArticleDetailViewController(articleId: articleId)
}

func backButtonTapped() {
self.coordinator.pop()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SnapKit

final class BookmarkViewController: UIViewController, BookmarkViewControllerable {

weak var coordinator: BookmarkNavigation?
var navigator: BookmarkNavigation
private let manager: BookmarkManager

private lazy var navigationBar = LHNavigationBarView(type: .bookmark, viewController: self)
Expand All @@ -21,8 +21,9 @@ final class BookmarkViewController: UIViewController, BookmarkViewControllerable
private var bookmarkAppData = BookmarkAppData(nickName: "", articleSummaries: [ArticleSummaries]())
private var bookmarkList = [ArticleSummaries]()

init(manager: BookmarkManager) {
init(manager: BookmarkManager, navigator: BookmarkNavigation) {
self.manager = manager
self.navigator = navigator
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -102,7 +103,7 @@ private extension BookmarkViewController {

func setAddTarget() {
self.navigationBar.backButtonAction {
self.coordinator?.backButtonTapped()
self.navigator.backButtonTapped()
}
}
}
Expand All @@ -119,7 +120,7 @@ extension BookmarkViewController: ViewControllerServiceable {
case .fetchImageError:
LHToast.show(message: "Image Error")
case .unAuthorizedError:
self.coordinator?.checkTokenIsExpired()
self.navigator.checkTokenIsExpired()
case .clientError(_, let message):
LHToast.show(message: message)
case .serverError:
Expand Down Expand Up @@ -196,6 +197,7 @@ extension BookmarkViewController: UICollectionViewDelegateFlowLayout {

extension BookmarkViewController: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
self.coordinator?.bookmarkCellTapped(articleID: bookmarkList[indexPath.item].articleID)
let articleID = bookmarkList[indexPath.item].articleID
self.navigator.bookmarkCellTapped(articleID: articleID)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import Lottie

final class ChallengeViewController: UIViewController, ChallengeViewControllerable {

weak var coordinator: ChallengeNavigation?

var navigator: ChallengeNavigation
private var manager: ChallengeManager

private let leftSeperateLine = LHUnderLine(lineColor: .background)
Expand All @@ -33,8 +34,9 @@ final class ChallengeViewController: UIViewController, ChallengeViewControllerab
}
}

init(manager: ChallengeManager) {
init(manager: ChallengeManager, navigator: ChallengeNavigation) {
self.manager = manager
self.navigator = navigator
super.init(nibName: nil, bundle: nil)
}

Expand Down Expand Up @@ -173,11 +175,11 @@ private extension ChallengeViewController {

func setAddTarget() {
navigationBar.rightFirstBarItemAction {
self.coordinator?.navigationLeftButtonTapped()
self.navigator.navigationLeftButtonTapped()
}

navigationBar.rightSecondBarItemAction {
self.coordinator?.navigationRightButtonTapped()
self.navigator.navigationRightButtonTapped()
}
}
}
Expand Down Expand Up @@ -232,7 +234,7 @@ extension ChallengeViewController: ViewControllerServiceable {
case .fetchImageError:
LHToast.show(message: "챌린지 이미지 패치 에러")
case .unAuthorizedError:
LHToast.show(message: "챌린지 Auth 에러")
self.navigator.checkTokenIsExpired()
case .clientError(_, let message):
LHToast.show(message: message)
case .serverError:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import UIKit

protocol BookmarkViewControllerable where Self: UIViewController {
var coordinator: BookmarkNavigation? { get set }
var navigator: BookmarkNavigation { get set }
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
import UIKit

protocol ChallengeViewControllerable where Self: UIViewController {
var coordinator: ChallengeNavigation? { get set }
var navigator: ChallengeNavigation { get set }
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ import UIKit

protocol CurriculumArticleByWeekControllerable where Self: UIViewController {
func setWeekIndexPath(week: Int)
var coordinator: CurriculumListByWeekNavigation? { get set }
var navigator: CurriculumListByWeekNavigation { get set }
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import UIKit


protocol CurriculumControllerable where Self: UIViewController {
var coordinator: CurriculumNavigation? { get set }
var navigator: CurriculumNavigation { get set }
}


Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class ArticleCategoryCoordinatorImpl: ArticleCategoryCoordinator {

func showBookmarkViewController() {
let bookmarkFactory = BookmarkFactoryImpl()
let bookmarkCoordinator = BookmarkCoordinator(navigationController: navigationController, factory: bookmarkFactory)
let bookmarkCoordinator = BookmarkCoordinatorImpl(navigationController: navigationController, factory: bookmarkFactory)
bookmarkCoordinator.start()
children.append(bookmarkCoordinator)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//
// BookmarkCoordinatorImpl.swift
// LionHeart-iOS
//
// Created by 김민재 on 10/17/23.
//

import UIKit

final class BookmarkCoordinatorImpl: BookmarkCoordinator {

weak var parentCoordinator: Coordinator?
private let factory: BookmarkFactory

var children: [Coordinator] = []

var navigationController: UINavigationController

init(navigationController: UINavigationController, factory: BookmarkFactory) {
self.navigationController = navigationController
self.factory = factory
}

func start() {
showBookmarkViewController()
}

func showBookmarkViewController() {
let bookmarkViewController = factory.makeBookmarkViewController(coordinator: self)
self.navigationController.pushViewController(bookmarkViewController, animated: true)
}

func showArticleDetailViewController(articleId: Int) {
let articleCoordinator = ArticleCoordinator(
navigationController: navigationController,
factory: ArticleFactoryImpl(),
articleId: articleId)
articleCoordinator.start()
children.append(articleCoordinator)
}

func pop() {
self.navigationController.popViewController(animated: true)
self.parentCoordinator?.childDidFinish(self)
}

func exitApplication() {
UIApplication.shared.perform(#selector(NSXPCConnection.suspend))
DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
exit(0)
}
}
}

Loading