diff --git a/Cherrish-iOS/Cherrish-iOS/Data/Persistence/UserDefaultKey.swift b/Cherrish-iOS/Cherrish-iOS/Data/Persistence/UserDefaultKey.swift index e6308ca9..95d27d12 100644 --- a/Cherrish-iOS/Cherrish-iOS/Data/Persistence/UserDefaultKey.swift +++ b/Cherrish-iOS/Cherrish-iOS/Data/Persistence/UserDefaultKey.swift @@ -10,4 +10,5 @@ import Foundation enum UserDefaultsKey: String, CaseIterable { case userID case isOnboardingCompleted + case hasProgressChallenge } diff --git a/Cherrish-iOS/Cherrish-iOS/Data/Repository/DemoRepository.swift b/Cherrish-iOS/Cherrish-iOS/Data/Repository/DemoRepository.swift index 16a57862..2baa5bc7 100644 --- a/Cherrish-iOS/Cherrish-iOS/Data/Repository/DemoRepository.swift +++ b/Cherrish-iOS/Cherrish-iOS/Data/Repository/DemoRepository.swift @@ -25,17 +25,27 @@ struct DefaultDemoRepository: DemoInterface { DemoAPI.fetchChallenges(userID: userID), decodingType: FetchChallengesResponseDTO.self ) - + let _ = userDefaultService.save(true, key: .hasProgressChallenge) + CherrishLogger.debug(userDefaultService.load(key: .hasProgressChallenge) ?? false) return response.toEntity() } func advance() async throws -> ProgressChallengeEntity { let userID: Int = userDefaultService.load(key: .userID) ?? 1 - let response = try await networkService.request( - DemoAPI.advance(userID: userID), - decodingType: FetchChallengesResponseDTO.self - ) - return response.toEntity() + do { + let response = try await networkService.request( + DemoAPI.advance(userID: userID), + decodingType: FetchChallengesResponseDTO.self + ) + return response.toEntity() + + } catch { + if error as! CherrishError == CherrishError.conflict { + let _ = userDefaultService.save(false, key: .hasProgressChallenge) + } + throw error + } + } func toggleRoutine(routineID: Int) async throws -> ProgressRoutineEntity { @@ -49,7 +59,7 @@ struct DefaultDemoRepository: DemoInterface { func createChallenge(missionIds: Int, routineNames: [String]) async throws { let userID: Int = userDefaultService.load(key: .userID) ?? 1 - let response: () = try await networkService.request( + let response = try await networkService.request( DemoAPI.createChallenge(userID: userID, requestDTO: .init( homecareRoutineId: missionIds, diff --git a/Cherrish-iOS/Cherrish-iOS/Data/Repository/HomeRepository.swift b/Cherrish-iOS/Cherrish-iOS/Data/Repository/HomeRepository.swift index c7865b3e..f1e5c48e 100644 --- a/Cherrish-iOS/Cherrish-iOS/Data/Repository/HomeRepository.swift +++ b/Cherrish-iOS/Cherrish-iOS/Data/Repository/HomeRepository.swift @@ -22,6 +22,11 @@ struct DefaultHomeRepository: HomeInterface { HomeAPI.fetchDashboard(userID: userID), decodingType: DashboardDTO.self ) + + if dto.challengeName == nil { + _ = userDefaultService.save(false, key: .hasProgressChallenge) + } + CherrishLogger.debug(userDefaultService.load(key: .hasProgressChallenge) ?? false) return dto.toEntity() } diff --git a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinator.swift b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinator.swift index 4cc489ad..81e74a01 100644 --- a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinator.swift +++ b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinator.swift @@ -8,7 +8,6 @@ import SwiftUI enum ChallengeRoute: PresentationTypeProtocol { - case root case startChallenge case createChallenge case challengeProgress diff --git a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinatorView.swift b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinatorView.swift index c2bb85fa..767cccc7 100644 --- a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinatorView.swift +++ b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/Coordinator/ChallengeCoordinatorView.swift @@ -10,30 +10,36 @@ import SwiftUI struct ChallengeCoordinatorView: View { @EnvironmentObject private var challengeCoordinator: ChallengeCoordinator @EnvironmentObject private var tabBarCoordinator: TabBarCoordinator + private let userDefaultService: UserDefaultService = DefaultUserDefaultService() + var body: some View { NavigationStack(path: $challengeCoordinator.path) { - ViewFactory.shared.makeStartChallengeView() - .navigationDestination(for: ChallengeRoute.self) { route in - Group { - switch route { - case .root: - ViewFactory.shared.makeHomeView() - case .startChallenge: - ViewFactory.shared.makeStartChallengeView() - case .createChallenge: - ViewFactory.shared.makeCreateChallengeView() - .onAppear { - tabBarCoordinator.isTabbarHidden = true - } - case .challengeProgress: - ViewFactory.shared.makeChallengeProgressView() - .onAppear() { - tabBarCoordinator.isTabbarHidden = false - } - } + Group { + if let hasProgress: Bool = userDefaultService.load(key: .hasProgressChallenge), hasProgress { + ViewFactory.shared.makeChallengeProgressView() + } else { + ViewFactory.shared.makeStartChallengeView() + } + } + .navigationDestination(for: ChallengeRoute.self) { route in + Group { + switch route { + case .startChallenge: + ViewFactory.shared.makeStartChallengeView() + case .createChallenge: + ViewFactory.shared.makeCreateChallengeView() + .onAppear { + tabBarCoordinator.isTabbarHidden = true + } + case .challengeProgress: + ViewFactory.shared.makeChallengeProgressView() + .onAppear() { + tabBarCoordinator.isTabbarHidden = false + } } - .navigationBarBackButtonHidden() } + .navigationBarBackButtonHidden() + } } } } diff --git a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/View/ChallengeLoadingView.swift b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/View/ChallengeLoadingView.swift index 8d587720..4a5568e0 100644 --- a/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/View/ChallengeLoadingView.swift +++ b/Cherrish-iOS/Cherrish-iOS/Presentation/Feature/ChallengeView/View/ChallengeLoadingView.swift @@ -13,7 +13,7 @@ struct ChallengeLoadingView: View { var body: some View { VStack { VStack(spacing: 4.adjustedH) { - highlight(highlightText: viewModel.selectedRoutine?.description ?? "", normalText: "관리 방향을 바탕으로") + highlight(highlightText: viewModel.selectedRoutine?.description ?? "", normalText: "방향을 바탕으로") .padding(.top, 113.adjustedH) TypographyText("TO-DO 미션을 만들고 있어요.", style: .title1_sb_18, color: .gray800) Image(.loading)