// // LoginViewModel.swift // AcaMate // // Created by Sean Kim on 12/14/24. // import SwiftUI import Combine class LoginViewModel: ObservableObject { private var cancellables = Set() @Published var toggleLoading: Bool = false @Published var navigateToAcademy: Bool = false @Published var bidArray: [String] = [] func loginAction(type: SNSLoginType) { LoginController().login(type) .flatMap{ snsId in loadAPIData(url: "\(API_URL)", path: "/api/v1/in/user/login", parameters: [ "acctype": "\(type == .Apple ? "ST00": "ST01")", "sns_id": "\(snsId.snsId)" ], decodingType: APIResponse.self) } .sink { [weak self] completion in switch completion { case .failure(let error): printLog("\(error)") self?.toggleLoading = false case .finished: self?.toggleLoading = false } } receiveValue: { [weak self] response in guard let self = self else { return } guard let ua = response as? APIResponse else {return} if let bids = ua.data.toStringDict()["bid"] { printLog(bids) if let bidArray: [String] = jsonToSwift(bids) { // 정상 적으로 학원 ID를 불러 온거니까 이제 여기서 할 걸 정해야 함 printLog("GOOD") self.navigateToAcademy = true self.bidArray = bidArray } else { printLog("JSON 변환 실패") } } } .store(in: &cancellables) } }