Get old bets

pull/28/head
Emre KARTAL 11 months ago
parent c9fb2ca2ed
commit 68e8c4d41c

@ -12,7 +12,7 @@ import Model
class CurrentBetViewModel: ObservableObject { class CurrentBetViewModel: ObservableObject {
@Inject var manager: Manager @Inject var manager: Manager
@Published private(set) var bets: [BetDetail] = [] @Published private(set) var bets: [BetDetail] = []
init() { init() {

@ -13,12 +13,16 @@ import Model
class HistoricBetViewModel: ObservableObject { class HistoricBetViewModel: ObservableObject {
@Inject var manager: Manager @Inject var manager: Manager
@Published private(set) var bets: [BetDetail] = []
init() { init() {
getItems() getItems()
} }
func getItems() { func getItems() {
manager.getHistoricBets(withIndex: 0, withCount: 20) { bets in
self.bets = bets
}
} }
} }

@ -7,7 +7,6 @@
import SwiftUI import SwiftUI
import Model import Model
import StubLib
struct CurrentBetView: View { struct CurrentBetView: View {

@ -6,9 +6,11 @@
// //
import SwiftUI import SwiftUI
import Model
struct HistoricBetView: View { struct HistoricBetView: View {
@StateObject private var viewModel = HistoricBetViewModel()
@Binding var showMenu: Bool @Binding var showMenu: Bool
@State private var showingSheet = false @State private var showingSheet = false
@ -22,8 +24,9 @@ struct HistoricBetView: View {
.textStyle(weight: .bold, color: AllInColors.grey500Color, size: 25) .textStyle(weight: .bold, color: AllInColors.grey500Color, size: 25)
.padding([.top],15) .padding([.top],15)
VStack(spacing: 20){ VStack(spacing: 20){
// ReviewCard(amountBetted: 110, isAWin: true) ForEach(viewModel.bets, id: \.bet.id) { (bet: BetDetail) in
// ReviewCard(amountBetted: 3, isAWin: false) ReviewCard(betDetail: bet, amountBetted: 110, isAWin: false)
}
} }
.padding([.trailing, .leading, .bottom],25) .padding([.trailing, .leading, .bottom],25)
} }

@ -194,8 +194,35 @@ public struct UserApiManager: UserDataManager {
}.resume() }.resume()
} }
public func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { public func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void) {
fatalError("Not implemented yet") let url = URL(string: allInApi + "bets/history")!
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("Bearer \(token)", forHTTPHeaderField: "Authorization")
var bets: [BetDetail] = []
URLSession.shared.dataTask(with: request) { data, response, error in
if let data = data {
print ("ALLIN : get current bets")
do {
if let httpResponse = response as? HTTPURLResponse, let jsonArray = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
for json in jsonArray {
print(json)
if let bet = FactoryApiBet().toBetDetail(from: json) {
bets.append(bet)
}
}
print(httpResponse.statusCode)
completion(bets)
}
} catch {
print("Error parsing JSON: \(error)")
}
}
}.resume()
} }
public func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void) { public func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void) {

@ -64,7 +64,7 @@ public struct Manager {
} }
} }
public func getHistoricBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) { public func getHistoricBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void) {
userDataManager.getOldBets(withIndex: index, withCount: count) { bets in userDataManager.getOldBets(withIndex: index, withCount: count) { bets in
completion(bets) completion(bets)
} }

@ -16,7 +16,7 @@ public protocol UserDataManager {
func getFriends(completion: @escaping ([User]) -> Void) func getFriends(completion: @escaping ([User]) -> Void)
func getUsers(withName name: String, completion: @escaping ([User]) -> Void) func getUsers(withName name: String, completion: @escaping ([User]) -> Void)
func getGifts(completion : @escaping (Int, Int)-> ()) func getGifts(completion : @escaping (Int, Int)-> ())
func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([Bet]) -> Void) func getOldBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void)
func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void) func getCurrentBets(withIndex index: Int, withCount count: Int, completion: @escaping ([BetDetail]) -> Void)
func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ()) func addParticipation(withId id: String, withAnswer answer: String, andStake stake: Int, completion : @escaping (Int)-> ())
func addResponse(withIdBet id: String, andResponse responseBet: String) func addResponse(withIdBet id: String, andResponse responseBet: String)

Loading…
Cancel
Save