Settings and activity
3 results found
-
335 votes
Priyatham Anisetty supported this idea ·
-
233 votes
Priyatham Anisetty supported this idea ·
-
1 vote
An error occurred while saving the comment Priyatham Anisetty shared this idea ·
Right now I have this struct
public struct InventoryItem: Decodable, Sendable ,Hashable, Equatable, Identifiable {
public var
id: UUID
public var
name: String
public var
stockInHand: Double
public var
unit: String
public var
lastUpdated: Timestamp
public var
costPerUnit: Double
public var
supplierName: String?
public var
threshold: Double?
public var inventoryItemKey: InventoryItemKey {
return InventoryItemKey(
id: id
)
}
public func hash(into hasher: inout Hasher) {
hasher.combine(id)
}
public static func == (lhs: InventoryItem, rhs: InventoryItem) -> Bool {
return lhs.id == rhs.id
}
enum CodingKeys: String, CodingKey {
case id
case name
case stockInHand
case unit
case lastUpdated
case costPerUnit
case supplierName
case threshold
}
public init(from decoder: any Decoder) throws {
var container = try decoder.container(keyedBy: CodingKeys.self)
let codecHelper = CodecHelper<CodingKeys>()
self.id = try codecHelper.decode(UUID.self, forKey: .id, container: &container)
self.name = try codecHelper.decode(String.self, forKey: .name, container: &container)
self.stockInHand = try codecHelper.decode(Double.self, forKey: .stockInHand, container: &container)
self.unit = try codecHelper.decode(String.self, forKey: .unit, container: &container)
self.lastUpdated = try codecHelper.decode(Timestamp.self, forKey: .lastUpdated, container: &container)
self.costPerUnit = try codecHelper.decode(Double.self, forKey: .costPerUnit, container: &container)
self.supplierName = try codecHelper.decode(String?.self, forKey: .supplierName, container: &container)
self.threshold = try codecHelper.decode(Double?.self, forKey: .threshold, container: &container)
}
}
public var
inventoryItems: [InventoryItem]
}
public func ref(
storeId: String
) -> QueryRefObservableObject<GetAllInventoryForStoreQuery.Data,GetAllInventoryForStoreQuery.Variables> {
var variables = GetAllInventoryForStoreQuery.Variables(storeId:storeId)
let ref = dataConnect.query(name: "getAllInventoryForStore", variables: variables, resultsDataType:GetAllInventoryForStoreQuery.Data.self, publisher: .observableObject)
return ref as! QueryRefObservableObject<GetAllInventoryForStoreQuery.Data,GetAllInventoryForStoreQuery.Variables>
}
@MainActor
public func execute(
storeId: String
) async throws -> OperationResult<GetAllInventoryForStoreQuery.Data> {
var variables = GetAllInventoryForStoreQuery.Variables(storeId:storeId)
let ref = dataConnect.query(name: "getAllInventoryForStore", variables: variables, resultsDataType:GetAllInventoryForStoreQuery.Data.self, publisher: .observableObject)
let refCast = ref as! QueryRefObservableObject<GetAllInventoryForStoreQuery.Data,GetAllInventoryForStoreQuery.Variables>
return try await refCast.execute()
}
}
I can only init by creating a JSON object serialize it and then pass it to the decoder to decode. it makes me write unnecessary code in my Preview functions.