From 755f3fd6c7096271d7f7fd62af2b40e9a083db08 Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Wed, 10 Jul 2024 11:10:22 -0300 Subject: [PATCH] fix(storage): optional fields --- Sources/Storage/Bucket.swift | 21 +++++++++++++-------- Sources/Storage/FileObject.swift | 24 ++++++++++++------------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Sources/Storage/Bucket.swift b/Sources/Storage/Bucket.swift index ccdd29e4..3437d254 100644 --- a/Sources/Storage/Bucket.swift +++ b/Sources/Storage/Bucket.swift @@ -3,17 +3,22 @@ import Foundation public struct Bucket: Identifiable, Hashable, Codable, Sendable { public var id: String public var name: String - public var owner: String - public var isPublic: Bool - public var createdAt: Date - public var updatedAt: Date + public var owner: String? + public var isPublic: Bool? + public var createdAt: Date? + public var updatedAt: Date? public var allowedMimeTypes: [String]? - public var fileSizeLimit: Int? + public var fileSizeLimit: Int64? public init( - id: String, name: String, owner: String, isPublic: Bool, createdAt: Date, updatedAt: Date, - allowedMimeTypes: [String]?, - fileSizeLimit: Int? + id: String, + name: String, + owner: String? = nil, + isPublic: Bool? = nil, + createdAt: Date? = nil, + updatedAt: Date? = nil, + allowedMimeTypes: [String]? = nil, + fileSizeLimit: Int64? = nil ) { self.id = id self.name = name diff --git a/Sources/Storage/FileObject.swift b/Sources/Storage/FileObject.swift index 86775a0c..083577ec 100644 --- a/Sources/Storage/FileObject.swift +++ b/Sources/Storage/FileObject.swift @@ -2,26 +2,26 @@ import Foundation import Helpers public struct FileObject: Identifiable, Hashable, Codable, Sendable { - public var name: String + public var name: String? public var bucketId: String? public var owner: String? - public var id: String? + public var id: UUID public var updatedAt: Date? public var createdAt: Date? public var lastAccessedAt: Date? public var metadata: [String: AnyJSON]? - public var buckets: Bucket? + public var bucket: Bucket? public init( - name: String, + name: String? = nil, bucketId: String? = nil, owner: String? = nil, - id: String, - updatedAt: Date, - createdAt: Date, - lastAccessedAt: Date, - metadata: [String: AnyJSON], - buckets: Bucket? = nil + id: UUID, + updatedAt: Date? = nil, + createdAt: Date? = nil, + lastAccessedAt: Date? = nil, + metadata: [String: AnyJSON]? = nil, + bucket: Bucket? = nil ) { self.name = name self.bucketId = bucketId @@ -31,7 +31,7 @@ public struct FileObject: Identifiable, Hashable, Codable, Sendable { self.createdAt = createdAt self.lastAccessedAt = lastAccessedAt self.metadata = metadata - self.buckets = buckets + self.bucket = bucket } enum CodingKeys: String, CodingKey { @@ -43,6 +43,6 @@ public struct FileObject: Identifiable, Hashable, Codable, Sendable { case createdAt = "created_at" case lastAccessedAt = "last_accessed_at" case metadata - case buckets + case bucket = "buckets" } }