From 8e5bb73a180c2dac1fcbebe7faf38f2801d870d6 Mon Sep 17 00:00:00 2001 From: "hsj._.06" Date: Tue, 10 Oct 2023 23:36:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20::=20=EA=B0=95=EC=A0=9C=20update=20?= =?UTF-8?q?=EC=97=86=EC=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SplashFeature/Sources/SplashView.swift | 39 ----------- .../Sources/SplashViewModel.swift | 68 +------------------ 2 files changed, 3 insertions(+), 104 deletions(-) diff --git a/Projects/Feature/SplashFeature/Sources/SplashView.swift b/Projects/Feature/SplashFeature/Sources/SplashView.swift index f0c12f99..21579205 100644 --- a/Projects/Feature/SplashFeature/Sources/SplashView.swift +++ b/Projects/Feature/SplashFeature/Sources/SplashView.swift @@ -18,45 +18,6 @@ struct SplashView: View { .resizable() .frame(width: 200, height: 200) } - .alert(isPresented: $viewModel.showUpdateAlert) { - if viewModel.forceAlert { - return Alert( - title: Text(viewModel.alertTitle), - message: Text(viewModel.alertMessage), - dismissButton: Alert.Button.destructive( - Text("확인"), - action: { - viewModel.openAppStore() - } - ) - ) - } else { - let reissue: () -> Void = { - viewModel.compareRefreshToke { authority in - appState.authority = authority - appState.sceneFlow = .main - } onError: { _ in - appState.sceneFlow = .auth - } - } - - return Alert( - title: Text(viewModel.alertTitle), - message: Text(viewModel.alertMessage), - primaryButton: Alert.Button.destructive( - Text("확인"), - action: { - viewModel.openAppStore() - reissue() - } - ), - secondaryButton: Alert.Button.cancel( - Text("취소"), - action: reissue - ) - ) - } - } .onAppear { viewModel.onAppear { authority in appState.authority = authority diff --git a/Projects/Feature/SplashFeature/Sources/SplashViewModel.swift b/Projects/Feature/SplashFeature/Sources/SplashViewModel.swift index 0ef23287..5c795b77 100644 --- a/Projects/Feature/SplashFeature/Sources/SplashViewModel.swift +++ b/Projects/Feature/SplashFeature/Sources/SplashViewModel.swift @@ -1,16 +1,10 @@ import BaseFeature -import UIKit import Combine import AuthDomainInterface import UsersDomainInterface final class SplashViewModel: BaseViewModel { private let reissueTokenUseCase: any ReissueTokenUseCase - @Published var showUpdateAlert: Bool = false - @Published var forceAlert: Bool = false - public var alertTitle = "" - public var alertMessage = "" - private let appleID = "6450888392" public init( reissueTokenUseCase: any ReissueTokenUseCase @@ -21,71 +15,15 @@ final class SplashViewModel: BaseViewModel { func onAppear( onSuccess: @escaping (AuthorityType) -> Void, onError: @escaping (Error) -> Void - ) { - update { - self.compareRefreshToke(onSuccess: onSuccess, onError: onError) - } - } - - func compareRefreshToke( - onSuccess: @escaping (AuthorityType) -> Void, - onError: @escaping (Error) -> Void ) { addCancellable(reissueTokenUseCase.execute()) { authority in - if authority { - onSuccess(.developer) + if authority.authority == .developer || authority.authority == .student { + onSuccess(AuthorityType(rawValue: authority.authority.rawValue) ?? .student) } else { - onSuccess(.student) + onError(AuthDomainError.internalServerError) } } onReceiveError: { error in onError(error) } } - - private func update(action: @escaping () -> Void) { - let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String - let urlString = "http://itunes.apple.com/lookup?id=\(self.appleID)&country=kr" - - guard appVersion != "0.0.0" else { return action() } - guard let url = URL(string: urlString) else { return } - let urlRequest = URLRequest(url: url) - URLSession.shared.dataTask(with: urlRequest) { data, _, _ in - guard let json = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments) as? [String: Any], - let results = json["results"] as? [[String: Any]], - let marketingVersion = results[0]["version"] as? String else { return } - let currentProjectVersion = appVersion! - let splitMarketingVersion = marketingVersion.split(separator: ".").map {$0} - let splitCurrentProjectVersion = currentProjectVersion.split(separator: ".").map {$0} - guard Int(currentProjectVersion.filter { $0 != "."})! < Int(marketingVersion.filter { $0 != "."})! else { - return action() - } - - DispatchQueue.main.async { - self.alertTitle = "업데이트 알림" - self.alertMessage = """ -JOBIS의 새로운 버전이 있습니다. -\(marketingVersion) 버전으로 업데이트 해주세요. -(현 버전: \(currentProjectVersion)) -""" - if splitCurrentProjectVersion[0] < splitMarketingVersion[0] || - splitCurrentProjectVersion[1] < splitMarketingVersion[1] { - self.forceAlert.toggle() - self.showUpdateAlert.toggle() - } else if splitCurrentProjectVersion[2] < splitMarketingVersion[2] { - self.showUpdateAlert.toggle() - } else { - action() - } - } - } - .resume() - } - - func openAppStore() { - let appStoreOpenUrlString = "itms-apps://itunes.apple.com/app/apple-store/\(appleID)" - guard let url = URL(string: appStoreOpenUrlString) else { return } - if UIApplication.shared.canOpenURL(url) { - UIApplication.shared.open(url, options: [:], completionHandler: nil) - } - } } From 97fc5e5d06b74a13555b1ec2788600c51e3195a1 Mon Sep 17 00:00:00 2001 From: "hsj._.06" Date: Tue, 10 Oct 2023 23:36:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?feat=20::=20token=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?=EB=8D=94=EA=B9=94=EB=81=94=ED=95=98=EA=B2=8C=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Interface/DTO/Transfer/ReissueTokenTransfer.swift | 4 ++-- .../Interface/DataSource/RemoteAuthDataSource.swift | 2 +- .../Interface/Entity/ReissueAuthorityEntity.swift | 9 +++++++++ .../AuthDomain/Interface/Repository/AuthRepository.swift | 2 +- .../Interface/UseCase/ReissueTokenUseCase.swift | 2 +- .../Sources/DataSource/RemoteAuthDataSourceImpl.swift | 2 +- .../Sources/Repository/AuthRepositoryImpl.swift | 2 +- .../Sources/UseCase/ReissueTokenUseCaseImpl.swift | 3 +-- .../Sources/Home/Components/StudentInfoView.swift | 2 +- 9 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 Projects/Domain/AuthDomain/Interface/Entity/ReissueAuthorityEntity.swift diff --git a/Projects/Domain/AuthDomain/Interface/DTO/Transfer/ReissueTokenTransfer.swift b/Projects/Domain/AuthDomain/Interface/DTO/Transfer/ReissueTokenTransfer.swift index 86cb2b9b..e864b97d 100644 --- a/Projects/Domain/AuthDomain/Interface/DTO/Transfer/ReissueTokenTransfer.swift +++ b/Projects/Domain/AuthDomain/Interface/DTO/Transfer/ReissueTokenTransfer.swift @@ -1,7 +1,7 @@ import Foundation public extension ReissueTokenResponseDTO { - func toDomain() -> Bool { - return authority == .developer + func toDomain() -> ReissueAuthorityEntity { + ReissueAuthorityEntity(authority: authority) } } diff --git a/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift b/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift index d23133d8..b7b625b6 100644 --- a/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift +++ b/Projects/Domain/AuthDomain/Interface/DataSource/RemoteAuthDataSource.swift @@ -3,6 +3,6 @@ import Foundation public protocol RemoteAuthDataSource { func sendAuthCode(req: SendAuthCodeRequestDTO) -> AnyPublisher - func reissueToken() -> AnyPublisher + func reissueToken() -> AnyPublisher func verifyAuthCode(email: String, authCode: String) -> AnyPublisher } diff --git a/Projects/Domain/AuthDomain/Interface/Entity/ReissueAuthorityEntity.swift b/Projects/Domain/AuthDomain/Interface/Entity/ReissueAuthorityEntity.swift new file mode 100644 index 00000000..c8bae182 --- /dev/null +++ b/Projects/Domain/AuthDomain/Interface/Entity/ReissueAuthorityEntity.swift @@ -0,0 +1,9 @@ +import Foundation + +public struct ReissueAuthorityEntity: Equatable { + public let authority: AuthAuthorityType + + public init(authority: AuthAuthorityType) { + self.authority = authority + } +} diff --git a/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift b/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift index d008038e..78a905ee 100644 --- a/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift +++ b/Projects/Domain/AuthDomain/Interface/Repository/AuthRepository.swift @@ -3,7 +3,7 @@ import Foundation public protocol AuthRepository { func sendAuthCode(req: SendAuthCodeRequestDTO) -> AnyPublisher - func reissueToken() -> AnyPublisher + func reissueToken() -> AnyPublisher func verifyAuthCode(email: String, authCode: String) -> AnyPublisher func logout() } diff --git a/Projects/Domain/AuthDomain/Interface/UseCase/ReissueTokenUseCase.swift b/Projects/Domain/AuthDomain/Interface/UseCase/ReissueTokenUseCase.swift index 4b59421f..b547e631 100644 --- a/Projects/Domain/AuthDomain/Interface/UseCase/ReissueTokenUseCase.swift +++ b/Projects/Domain/AuthDomain/Interface/UseCase/ReissueTokenUseCase.swift @@ -2,5 +2,5 @@ import Combine import UsersDomainInterface public protocol ReissueTokenUseCase { - func execute() -> AnyPublisher + func execute() -> AnyPublisher } diff --git a/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift b/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift index e19f29a5..983c4879 100644 --- a/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift +++ b/Projects/Domain/AuthDomain/Sources/DataSource/RemoteAuthDataSourceImpl.swift @@ -7,7 +7,7 @@ public final class RemoteAuthDataSourceImpl: BaseRemoteDataSource, Remo request(.sendAuthCode(req)) } - public func reissueToken() -> AnyPublisher { + public func reissueToken() -> AnyPublisher { request(.reissueToken, dto: ReissueTokenResponseDTO.self) .map { $0.toDomain() } .eraseToAnyPublisher() diff --git a/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift b/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift index 78c32d35..6181d3be 100644 --- a/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift +++ b/Projects/Domain/AuthDomain/Sources/Repository/AuthRepositoryImpl.swift @@ -17,7 +17,7 @@ public struct AuthRepositoryImpl: AuthRepository { remoteAuthDataSource.sendAuthCode(req: req) } - public func reissueToken() -> AnyPublisher { + public func reissueToken() -> AnyPublisher { remoteAuthDataSource.reissueToken() } diff --git a/Projects/Domain/AuthDomain/Sources/UseCase/ReissueTokenUseCaseImpl.swift b/Projects/Domain/AuthDomain/Sources/UseCase/ReissueTokenUseCaseImpl.swift index 9e339d34..20de595b 100644 --- a/Projects/Domain/AuthDomain/Sources/UseCase/ReissueTokenUseCaseImpl.swift +++ b/Projects/Domain/AuthDomain/Sources/UseCase/ReissueTokenUseCaseImpl.swift @@ -1,5 +1,4 @@ import AuthDomainInterface -import UsersDomainInterface import Combine public struct ReissueTokenUseCaseImpl: ReissueTokenUseCase { @@ -9,7 +8,7 @@ public struct ReissueTokenUseCaseImpl: ReissueTokenUseCase { self.authRepository = authRepository } - public func execute() -> AnyPublisher { + public func execute() -> AnyPublisher { authRepository.reissueToken() } } diff --git a/Projects/Feature/HomeFeature/Sources/Home/Components/StudentInfoView.swift b/Projects/Feature/HomeFeature/Sources/Home/Components/StudentInfoView.swift index 136aaf32..10dfdc75 100644 --- a/Projects/Feature/HomeFeature/Sources/Home/Components/StudentInfoView.swift +++ b/Projects/Feature/HomeFeature/Sources/Home/Components/StudentInfoView.swift @@ -15,7 +15,7 @@ struct StudentInfoView: View { Text("\(studentInfo?.studentGcn ?? "") \(studentInfo?.studentName ?? "Loading")") .JOBISFont(.body(.body1), color: .Sub.gray70) - Text((studentInfo?.department ?? .common)?.localizedString() ?? "") + Text(studentInfo?.department.localizedString() ?? "") .JOBISFont(.etc(.caption), color: .Sub.gray60) } }