fixed the Profile request
This commit is contained in:
parent
6a254cc2ae
commit
fa362e24b6
@ -256,7 +256,7 @@ public extension DevRantRequest {
|
|||||||
|
|
||||||
let config = makeConfig(.get, path: "users/\(userId)", urlParameters: parameters, token: token)
|
let config = makeConfig(.get, path: "users/\(userId)", urlParameters: parameters, token: token)
|
||||||
|
|
||||||
let response: Profile.CodingData = try await request.requestJson(config: config, apiError: DevRantApiError.CodingData.self)
|
let response: Profile.CodingData.Container = try await request.requestJson(config: config, apiError: DevRantApiError.CodingData.self)
|
||||||
|
|
||||||
return response.decoded
|
return response.decoded
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public struct Profile: Hashable, Sendable {
|
|||||||
public let devRantSupporter: Bool
|
public let devRantSupporter: Bool
|
||||||
|
|
||||||
/// True if the logged in user is subscribed to the user of this profile.
|
/// True if the logged in user is subscribed to the user of this profile.
|
||||||
public var subscribed: Bool //TODO: where is this set? It's not in the json data of the profile
|
public var subscribed: Bool
|
||||||
|
|
||||||
public init(username: String, score: Int, created: Date, about: String?, location: String?, skills: String?, github: String?, website: String?, content: Profile.Content, avatarLarge: User.Avatar, avatarSmall: User.Avatar, devRantSupporter: Bool, subscribed: Bool) {
|
public init(username: String, score: Int, created: Date, about: String?, location: String?, skills: String?, github: String?, website: String?, content: Profile.Content, avatarLarge: User.Avatar, avatarSmall: User.Avatar, devRantSupporter: Bool, subscribed: Bool) {
|
||||||
self.username = username
|
self.username = username
|
||||||
@ -82,6 +82,11 @@ public extension Profile {
|
|||||||
|
|
||||||
extension Profile {
|
extension Profile {
|
||||||
struct CodingData: Codable {
|
struct CodingData: Codable {
|
||||||
|
struct Container: Codable {
|
||||||
|
let profile: Profile.CodingData
|
||||||
|
let subscribed: Int?
|
||||||
|
}
|
||||||
|
|
||||||
let username: String
|
let username: String
|
||||||
let score: Int
|
let score: Int
|
||||||
let created_time: Int
|
let created_time: Int
|
||||||
@ -94,26 +99,25 @@ extension Profile {
|
|||||||
let avatar: User.Avatar.CodingData
|
let avatar: User.Avatar.CodingData
|
||||||
let avatar_sm: User.Avatar.CodingData
|
let avatar_sm: User.Avatar.CodingData
|
||||||
let dpp: Int?
|
let dpp: Int?
|
||||||
let subscribed: Bool? //TODO: check if it exists in the json data
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extension Profile.CodingData {
|
extension Profile.CodingData.Container {
|
||||||
var decoded: Profile {
|
var decoded: Profile {
|
||||||
.init(
|
return .init(
|
||||||
username: username,
|
username: profile.username,
|
||||||
score: score,
|
score: profile.score,
|
||||||
created: Date(timeIntervalSince1970: TimeInterval(created_time)),
|
created: Date(timeIntervalSince1970: TimeInterval(profile.created_time)),
|
||||||
about: about.isEmpty ? nil : about,
|
about: profile.about.isEmpty ? nil : profile.about,
|
||||||
location: location.isEmpty ? nil : location,
|
location: profile.location.isEmpty ? nil : profile.location,
|
||||||
skills: skills.isEmpty ? nil : skills,
|
skills: profile.skills.isEmpty ? nil : profile.skills,
|
||||||
github: github.isEmpty ? nil : github,
|
github: profile.github.isEmpty ? nil : profile.github,
|
||||||
website: website.isEmpty ? nil : website,
|
website: profile.website.isEmpty ? nil : profile.website,
|
||||||
content: content.decoded,
|
content: profile.content.decoded,
|
||||||
avatarLarge: avatar.decoded,
|
avatarLarge: profile.avatar.decoded,
|
||||||
avatarSmall: avatar_sm.decoded,
|
avatarSmall: profile.avatar_sm.decoded,
|
||||||
devRantSupporter: (dpp ?? 0) != 0,
|
devRantSupporter: (profile.dpp ?? 0) != 0,
|
||||||
subscribed: subscribed ?? false
|
subscribed: (subscribed ?? 0) != 0
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user