From 4b65d7417f07f3074660a5b070f3bdad9272068a Mon Sep 17 00:00:00 2001 From: William Brawner Date: Fri, 8 Dec 2023 23:01:07 -0700 Subject: [PATCH] Idk, updated something --- Sources/TwigsCore/Budget.swift | 39 ++++++++++++++----------- Sources/TwigsCore/TwigsApiService.swift | 7 +++-- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Sources/TwigsCore/Budget.swift b/Sources/TwigsCore/Budget.swift index eb70ad4..d956904 100644 --- a/Sources/TwigsCore/Budget.swift +++ b/Sources/TwigsCore/Budget.swift @@ -17,26 +17,31 @@ public struct Budget: Identifiable, Hashable, Codable { public struct BudgetOverview: Equatable { public let budget: Budget public let balance: Int - public var maxValue: Float { - get { - return Float(max( - max(expectedIncome, actualIncome), - max(expectedExpenses, actualExpenses) - )) - } - } - public var expectedIncome: Int - public var actualIncome: Int - public var expectedExpenses: Int - public var actualExpenses: Int + public let transactionCount: Int + public let categories: [Category] + public var expectedIncome: Float + public var actualIncome: Float + public var expectedExpenses: Float + public var actualExpenses: Float - public init(budget: Budget, balance: Int, expectedIncome: Int = 0, actualIncome: Int = 0, expectedExpenses: Int = 0, actualExpenses: Int = 0) { + public init( + budget: Budget, + balance: Int, + categories: [Category], + transactionCount: Int, + expectedIncome: Int = 0, + actualIncome: Int = 0, + expectedExpenses: Int = 0, + actualExpenses: Int = 0 + ) { self.budget = budget self.balance = balance - self.expectedIncome = expectedIncome - self.actualIncome = actualIncome - self.expectedExpenses = expectedExpenses - self.actualExpenses = actualExpenses + self.categories = categories + self.transactionCount = transactionCount + self.expectedIncome = Float(expectedIncome) / 100.0 + self.actualIncome = Float(actualIncome) / 100.0 + self.expectedExpenses = Float(expectedExpenses) / 100.0 + self.actualExpenses = Float(actualExpenses) / 100.0 } } diff --git a/Sources/TwigsCore/TwigsApiService.swift b/Sources/TwigsCore/TwigsApiService.swift index d7ebeab..f069680 100644 --- a/Sources/TwigsCore/TwigsApiService.swift +++ b/Sources/TwigsCore/TwigsApiService.swift @@ -272,7 +272,7 @@ public class RequestHelper { var combinedEndPoint = endPoint if (queries != nil) { for (key, values) in queries! { - for value in values { + for value in values { let separator = combinedEndPoint.contains("?") ? "&" : "?" combinedEndPoint += separator + key + "=" + value } @@ -392,6 +392,9 @@ public class RequestHelper { return try self.decoder.decode(ResultType.self, from: data) } catch { print("error decoding json: \(error)") + if let data = data { + print(String(decoding: data, as: UTF8.self)) + } throw NetworkError.jsonParsingFailed(error) } } @@ -468,7 +471,7 @@ extension Date { dateFormatter.timeZone = TimeZone(identifier: "UTC") return dateFormatter }() - + func toISO8601String() -> String { return Date.iso8601DateFormatter.string(from: self) }