Models WIP

This commit is contained in:
Wilhelm Oks 2024-12-11 17:23:53 +01:00
parent 19c645e59c
commit b9d990b1f3
3 changed files with 20 additions and 9 deletions

View File

@ -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

View File

@ -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,

View File

@ -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 ?? "",