Skip to content

Commit

Permalink
[Refactor] #201 - Mypage ViewModel 파일 생생 및 서버와 연관된 코드 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
GodSamble committed Oct 26, 2023
1 parent 39333c4 commit 969ab90
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Winey/Winey/Source/Scenes/MyPage/ViewModels/MypageViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// MypageViewModel.swift
// Winey
//
// Created by 고영민 on 10/26/23.
//

import Foundation
import UIKit


class MypageViewModel {


// MARK: - Properties

var userService = UserService()
var collectionView: UICollectionView?
var nickname: String?
var userLevel: UserLevel?
var duringGoalAmount: Int?
var duringGoalCount: Int?
var targetMoney: Int?
var dday: Int?
var isOver: Bool = false

// 데이터 업데이트를 알리기 위한 클로저
var dataUpdated: (() -> Void)?

// MARK: - Server
func getTotalUser() {
userService.getTotalUser() { [weak self] response in
guard let response = response, let data = response.data else { return }
guard let self else { return }
let userData = data.userResponseUserDto
self.userLevel = self.judgeUserLevel(userData.userLevel)
self.nickname = userData.nickname

let goal = data.userResponseGoalDto
self.duringGoalCount = goal?.duringGoalCount
self.duringGoalAmount = goal?.duringGoalAmount
self.dday = goal?.dday
self.targetMoney = goal?.targetMoney
self.isOver = data.userResponseGoalDto?.isOver ?? false

let hasGoal = data.userResponseGoalDto != nil
UserSingleton.saveGoal(hasGoal)

self.collectionView?.reloadData()
self.dataUpdated?()
}
}
private func judgeUserLevel(_ userLevel: String) -> UserLevel? {
return UserLevel(rawValue: userLevel)
}
}

0 comments on commit 969ab90

Please sign in to comment.