You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.5 KiB
67 lines
1.5 KiB
//
|
|
// DetailsViewModel.swift
|
|
// AllIn
|
|
//
|
|
// Created by Emre on 16/01/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
import DependencyInjection
|
|
import Model
|
|
import WidgetKit
|
|
|
|
class DetailsViewModel: ObservableObject {
|
|
|
|
@Inject var manager: Manager
|
|
var id: String
|
|
@Published var answer = 0
|
|
@Published var mise: String = ""
|
|
|
|
@Published var betDetail: BetDetail?
|
|
|
|
init(id: String) {
|
|
self.id = id
|
|
getItem(withId: id)
|
|
}
|
|
|
|
func getItem(withId id: String) {
|
|
manager.getBet(withId: id) { bet in
|
|
DispatchQueue.main.async {
|
|
for par in bet.participations {
|
|
print(par.id)
|
|
}
|
|
self.betDetail = bet
|
|
}
|
|
}
|
|
}
|
|
|
|
func addParticipate() {
|
|
if let stake = Int(mise) {
|
|
var rep: String = ""
|
|
if answer == 0 {
|
|
rep = "Yes"
|
|
} else {
|
|
rep = "No"
|
|
}
|
|
manager.addParticipation(withId: id, withAnswer: rep, andStake: stake) { statusCode in
|
|
switch statusCode {
|
|
case 201:
|
|
AppStateContainer.shared.user?.nbCoins -= stake
|
|
WidgetCenter.shared.reloadAllTimelines()
|
|
|
|
self.getItem(withId: self.id)
|
|
default:
|
|
break
|
|
}
|
|
}
|
|
}
|
|
mise = ""
|
|
answer = 0
|
|
}
|
|
|
|
func checkAndSetError() {
|
|
|
|
}
|
|
}
|