Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
merge :: (#182) 강제 업데이트 제거
Browse files Browse the repository at this point in the history
merge :: (#182) 강제 업데이트 제거
  • Loading branch information
HongSJae authored Oct 10, 2023
2 parents 60cdbc6 + 97fc5e5 commit 01f9394
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 114 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

public extension ReissueTokenResponseDTO {
func toDomain() -> Bool {
return authority == .developer
func toDomain() -> ReissueAuthorityEntity {
ReissueAuthorityEntity(authority: authority)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import Foundation

public protocol RemoteAuthDataSource {
func sendAuthCode(req: SendAuthCodeRequestDTO) -> AnyPublisher<Void, Error>
func reissueToken() -> AnyPublisher<Bool, Error>
func reissueToken() -> AnyPublisher<ReissueAuthorityEntity, Error>
func verifyAuthCode(email: String, authCode: String) -> AnyPublisher<Void, Error>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Foundation

public struct ReissueAuthorityEntity: Equatable {
public let authority: AuthAuthorityType

public init(authority: AuthAuthorityType) {
self.authority = authority
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation

public protocol AuthRepository {
func sendAuthCode(req: SendAuthCodeRequestDTO) -> AnyPublisher<Void, Error>
func reissueToken() -> AnyPublisher<Bool, Error>
func reissueToken() -> AnyPublisher<ReissueAuthorityEntity, Error>
func verifyAuthCode(email: String, authCode: String) -> AnyPublisher<Void, Error>
func logout()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ import Combine
import UsersDomainInterface

public protocol ReissueTokenUseCase {
func execute() -> AnyPublisher<Bool, Error>
func execute() -> AnyPublisher<ReissueAuthorityEntity, Error>
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public final class RemoteAuthDataSourceImpl: BaseRemoteDataSource<AuthAPI>, Remo
request(.sendAuthCode(req))
}

public func reissueToken() -> AnyPublisher<Bool, Error> {
public func reissueToken() -> AnyPublisher<ReissueAuthorityEntity, Error> {
request(.reissueToken, dto: ReissueTokenResponseDTO.self)
.map { $0.toDomain() }
.eraseToAnyPublisher()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct AuthRepositoryImpl: AuthRepository {
remoteAuthDataSource.sendAuthCode(req: req)
}

public func reissueToken() -> AnyPublisher<Bool, Error> {
public func reissueToken() -> AnyPublisher<ReissueAuthorityEntity, Error> {
remoteAuthDataSource.reissueToken()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import AuthDomainInterface
import UsersDomainInterface
import Combine

public struct ReissueTokenUseCaseImpl: ReissueTokenUseCase {
Expand All @@ -9,7 +8,7 @@ public struct ReissueTokenUseCaseImpl: ReissueTokenUseCase {
self.authRepository = authRepository
}

public func execute() -> AnyPublisher<Bool, Error> {
public func execute() -> AnyPublisher<ReissueAuthorityEntity, Error> {
authRepository.reissueToken()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
39 changes: 0 additions & 39 deletions Projects/Feature/SplashFeature/Sources/SplashView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 3 additions & 65 deletions Projects/Feature/SplashFeature/Sources/SplashViewModel.swift
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}
}
}

0 comments on commit 01f9394

Please sign in to comment.