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]전체 DI적용(#131) #132

Merged
merged 20 commits into from
Sep 30, 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
174 changes: 83 additions & 91 deletions LionHeart-iOS/LionHeart-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion LionHeart-iOS/LionHeart-iOS/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
self.window = UIWindow(windowScene: windowScene)
/// 폰트등록
Font.registerFonts()
let navigationController = UINavigationController(rootViewController: SplashViewController(authService: AuthMyPageServiceWrapper(authAPIService: AuthAPI(apiService: APIService()), mypageAPIService: MyPageAPI(apiService: APIService()))))
let splashViewController = SplashViewController(manager: SplashManagerImpl(authService: AuthServiceImpl(apiService: APIService())))
let navigationController = UINavigationController(rootViewController: splashViewController)
self.window?.rootViewController = navigationController
self.window?.makeKeyAndVisible()
}
Expand Down
46 changes: 46 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Global/Enums/Badge.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Badge.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import UIKit

enum BadgeLevel: String {
case level01 = "LEVEL_ONE"
case level02 = "LEVEL_TWO"
case level03 = "LEVEL_THREE"
case level04 = "LEVEL_FOUR"
case level05 = "LEVEL_FIVE"

var badgeLevel: Int {
switch self {
case .level01: return 1
case .level02: return 2
case .level03: return 3
case .level04: return 4
case .level05: return 5
}
}

var badgeImage: UIImage {
switch self {
case .level01: return ImageLiterals.ChallengeBadge.level01
case .level02: return ImageLiterals.ChallengeBadge.level02
case .level03: return ImageLiterals.ChallengeBadge.level03
case .level04: return ImageLiterals.ChallengeBadge.level04
case .level05: return ImageLiterals.ChallengeBadge.level05
}
}

var progreddbarLottie: String {
switch self {
case .level01: return "Level1"
case .level02: return "Level2"
case .level03: return "Level3"
case .level04: return "Level4"
case .level05: return "Level5"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ extension UIViewController {

extension UIViewController {
func presentArticleDetailFullScreen(articleID: Int) {
let articleDetailViewController = ArticleDetailViewController(serviceProtocol: BookmarkService(bookmarkAPIProtocol: BookmarkAPI(apiService: APIService())))
let articleDetailViewController = ArticleDetailViewController(manager: ArticleDetailManagerImpl(articleService: ArticleServiceImpl(apiService: APIService()), bookmarkService: BookmarkServiceImpl(apiService: APIService())))
articleDetailViewController.setArticleId(id: articleID)
articleDetailViewController.isModalInPresentation = true
articleDetailViewController.modalPresentationStyle = .fullScreen
Expand Down
2 changes: 1 addition & 1 deletion LionHeart-iOS/LionHeart-iOS/Network/Base/APIService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class APIService: Requestable {
throw NetworkError.serverError
}

print("✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅APIService성공✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅")
print("✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅API호출성공✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅✅")
return decodedData.data
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ struct ChallengeDataResponse: DTO, Response {
let level: String
let attendances: [String]
}

extension ChallengeDataResponse {
func toAppData() -> ChallengeData {
return .init(babyDaddyName: self.babyNickname, howLongDay: self.day, daddyLevel: self.level, daddyAttendances: self.attendances)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ struct TodayArticleResponse: DTO, Response {
let day: Int
let articleId: Int
}

extension TodayArticleResponse {
func toAppData() -> TodayArticle {
return .init(fetalNickname: self.babyNickname, articleTitle: self.title, articleDescription: self.editorNoteContent, currentWeek: self.week, currentDay: self.day, mainImageURL: self.mainImageUrl, aticleID: self.articleId)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ArticleDetailManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class ArticleDetailManagerImpl: ArticleDetailManager {

private let articleService: ArticleService
private let bookmarkService: BookmarkOutService

init(articleService: ArticleService, bookmarkService: BookmarkOutService) {
self.articleService = articleService
self.bookmarkService = bookmarkService
}

func getArticleDetail(articleId: Int) async throws -> [BlockTypeAppData] {
guard let model = try await articleService.getArticleDetail(articleId: articleId) else { return []}
return model.toAppData()
}

func postBookmark(model: BookmarkRequest) async throws {
guard let data = try await bookmarkService.postBookmark(model: model) else { throw NetworkError.badCasting }
print(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// ArticleListByCategoryMangerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class ArticleListByCategoryMangerImpl: ArticleListByCategoryManager {

private let articleService: ArticleService
private let bookmarkService: BookmarkOutService

init(articleService: ArticleService, bookmarkService: BookmarkOutService) {
self.articleService = articleService
self.bookmarkService = bookmarkService
}

func getArticleListByCategory(categoryString: String) async throws -> CurriculumWeekData {
guard let model = try await articleService.getArticleListByCategory(categoryString: categoryString) else { throw NetworkError.badCasting }
return model.toAppData()
}

func postBookmark(model: BookmarkRequest) async throws {
guard let data = try await bookmarkService.postBookmark(model: model) else { throw NetworkError.badCasting }
print(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// BookmarkMangerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class BookmarkMangerImpl: BookmarkManger {

private let bookmarkService: BookmarkService

init(bookmarkService: BookmarkService) {
self.bookmarkService = bookmarkService
}

func getBookmark() async throws -> BookmarkAppData {
guard let model = try await bookmarkService.getBookmark() else { return .empty }
return model.toAppData()
}

func postBookmark(model: BookmarkRequest) async throws {
guard let data = try await bookmarkService.postBookmark(model: model) else { throw NetworkError.badCasting }
print(data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// ChallengeManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class ChallengeManagerImpl: ChallengeManager {

private let challengeService: ChallengeService

init(challengeService: ChallengeService) {
self.challengeService = challengeService
}

func inquireChallengeInfo() async throws -> ChallengeData {
guard let model = try await challengeService.inquireChallengeInfo() else { return .empty }
return model.toAppData()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// CurriculumListManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class CurriculumListManagerImpl: CurriculumListManager {

private let bookmarkService: BookmarkOutService
private let curriculumService: CurriculumService

init(bookmarkService: BookmarkOutService, curriculumService: CurriculumService) {
self.bookmarkService = bookmarkService
self.curriculumService = curriculumService
}

func postBookmark(model: BookmarkRequest) async throws {
guard let data = try await bookmarkService.postBookmark(model: model) else { throw NetworkError.badCasting }
print(data)
}

func getArticleListByWeekInfo(week: Int) async throws -> CurriculumWeekData {
guard let model = try await curriculumService.getArticleListByWeekInfo(week: week) else { throw NetworkError.badCasting }
return model.toAppData()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// CurriculumManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class CurriculumManagerImpl: CurriculumManager {

private let curriculumService: CurriculumService

init(curriculumService: CurriculumService) {
self.curriculumService = curriculumService
}

func getCurriculumServiceInfo() async throws -> UserInfoData {
guard let model = try await curriculumService.getCurriculumServiceInfo() else { throw NetworkError.badCasting }
return UserInfoData(userWeekInfo: model.week, userDayInfo: model.day, progress: model.progress + 1, remainingDay: model.remainingDay)
}
}
21 changes: 21 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Network/Manager/LoginMangerImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// LoginMangerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class LoginMangerImpl: LoginManager {

private let authService: AuthUserInService

init(authService: AuthUserInService) {
self.authService = authService
}

func login(type: LoginType, kakaoToken: String) async throws {
try await authService.login(type: type, kakaoToken: kakaoToken)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// MyPageManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class MyPageManagerImpl: MyPageManager {

private let mypageService: MypageService
private let authService: AuthUserOutService

init(mypageService: MypageService, authService: AuthUserOutService) {
self.mypageService = mypageService
self.authService = authService
}

func getMyPage() async throws -> MyPageAppData {
guard let model = try await mypageService.getMyPage() else { throw NetworkError.badCasting }
return MyPageAppData(badgeImage: model.level, nickname: model.babyNickname, isAlarm: model.notificationStatus)
}

func resignUser() async throws {
try await authService.resignUser()
}

func logout(token: UserDefaultToken) async throws {
try await authService.logout(token: token)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// OnboardingManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class OnboardingManagerImpl: OnboardingManager {

private let authService: AuthUserInService

init(authService: AuthUserInService) {
self.authService = authService
}

func signUp(type: LoginType, onboardingModel: UserOnboardingModel) async throws {
try await authService.signUp(type: type, onboardingModel: onboardingModel)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// SplashManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class SplashManagerImpl: SplashManager {

private let authService: AuthService

init(authService: AuthService) {
self.authService = authService
}

func reissueToken(token: Token) async throws -> Token? {
return try await authService.reissueToken(token: token)
}

func logout(token: UserDefaultToken) async throws {
try await authService.logout(token: token)
}
}
22 changes: 22 additions & 0 deletions LionHeart-iOS/LionHeart-iOS/Network/Manager/TodayManagerImpl.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// TodayManagerImpl.swift
// LionHeart-iOS
//
// Created by uiskim on 2023/09/24.
//

import Foundation

final class TodayManagerImpl: TodayManager {

private let articleService: ArticleService

init(articleService: ArticleService) {
self.articleService = articleService
}

func inquiryTodayArticle() async throws -> TodayArticle {
guard let model = try await articleService.inquiryTodayArticle() else { return .emptyArticle }
return model.toAppData()
}
}
Loading