From b9d990b1f3334a388bede1a844b9f3a809288047 Mon Sep 17 00:00:00 2001 From: Wilhelm Oks Date: Wed, 11 Dec 2024 17:23:53 +0100 Subject: [PATCH] Models WIP --- Sources/SwiftDevRant/Models/Collaboration.swift | 15 ++++++++++++--- Sources/SwiftDevRant/Models/Comment.swift | 4 ++-- Sources/SwiftDevRant/Models/Rant.swift | 10 ++++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/Sources/SwiftDevRant/Models/Collaboration.swift b/Sources/SwiftDevRant/Models/Collaboration.swift index af35f30..50ca926 100644 --- a/Sources/SwiftDevRant/Models/Collaboration.swift +++ b/Sources/SwiftDevRant/Models/Collaboration.swift @@ -1,12 +1,21 @@ public struct Collaboration: Hashable { - public let type: String //TODO: check if this is a kind of enum or some arbitrary text entered by the user. + public enum Kind: Int { + case openSourceIdea = 1 + case existingOpenSourceProject = 2 + case projectIdea = 3 + case existingProject = 4 + } + + public let kind: Kind? + public let kindDescription: String public let description: String public let techStack: String public let teamSize: String public let url: String - public init(type: String, description: String, techStack: String, teamSize: String, url: String) { - self.type = type + public init(kind: Kind?, kindDescription: String, description: String, techStack: String, teamSize: String, url: String) { + self.kind = kind + self.kindDescription = kindDescription self.description = description self.techStack = techStack self.teamSize = teamSize diff --git a/Sources/SwiftDevRant/Models/Comment.swift b/Sources/SwiftDevRant/Models/Comment.swift index 0529968..fc50fe7 100644 --- a/Sources/SwiftDevRant/Models/Comment.swift +++ b/Sources/SwiftDevRant/Models/Comment.swift @@ -59,7 +59,7 @@ extension Comment { let user_username: String let user_score: Int let user_avatar: User.Avatar.CodingData - //let user_avatar_lg: User.Avatar.CodingData //TODO: check if this exists in the JSON data + let user_avatar_lg: User.Avatar.CodingData? let user_dpp: Int? let attached_image: AttachedImage.CodingData? let edited: Bool? @@ -79,7 +79,7 @@ extension Comment.CodingData { score: user_score, devRantSupporter: (user_dpp ?? 0) != 0, avatar: user_avatar.decoded, - avatarLarge: nil + avatarLarge: user_avatar_lg?.decoded ), created: Date(timeIntervalSince1970: TimeInterval(created_time)), isEdited: edited ?? false, diff --git a/Sources/SwiftDevRant/Models/Rant.swift b/Sources/SwiftDevRant/Models/Rant.swift index 2de59ff..8fd923d 100644 --- a/Sources/SwiftDevRant/Models/Rant.swift +++ b/Sources/SwiftDevRant/Models/Rant.swift @@ -80,6 +80,7 @@ extension Rant { let link: String? let links: [Link.CodingData]? let weekly: Weekly.CodingData? + let c_type: Int? let c_type_long: String? let c_description: String? let c_tech_stack: String? @@ -123,11 +124,12 @@ extension Rant.CodingData { } private var decodedCollaboration: Collaboration? { - let collaborationProperties = [c_type_long, c_description, c_tech_stack, c_team_size, c_url] - let nonNilProperties = collaborationProperties.compactMap { $0 } - guard !nonNilProperties.isEmpty else { return nil } + guard c_type != nil || c_type_long != nil || c_description != nil || c_tech_stack != nil || c_team_size != nil || c_url != nil else { + return nil + } return .init( - type: c_type_long ?? "", + kind: c_type.flatMap { .init(rawValue: $0) }, + kindDescription: c_type_long ?? "", description: c_description ?? "", techStack: c_tech_stack ?? "", teamSize: c_team_size ?? "",