55 lines
1.2 KiB
Swift
Raw Normal View History

import Foundation
2024-12-22 16:24:48 +00:00
public struct AuthToken: Hashable, Sendable {
public let id: Int
public let key: String
public let expireTime: Date
public let userId: Int
public init(id: Int, key: String, expireTime: Date, userId: Int) {
self.id = id
self.key = key
self.expireTime = expireTime
self.userId = userId
}
public var isExpired: Bool {
expireTime < Date()
}
}
2024-12-22 16:24:48 +00:00
public extension AuthToken {
public struct CodingData: Codable {
public struct Container: Codable {
let auth_token: AuthToken.CodingData
}
2024-12-22 16:24:48 +00:00
public let id: Int
public let key: String
public let expire_time: Int
public let user_id: Int
}
}
2024-12-22 16:24:48 +00:00
public extension AuthToken.CodingData {
public var decoded: AuthToken {
.init(
id: id,
key: key,
expireTime: Date(timeIntervalSince1970: TimeInterval(expire_time)),
userId: user_id
)
}
}
2024-12-22 16:24:48 +00:00
public extension AuthToken {
public var encoded: AuthToken.CodingData {
.init(
id: id,
key: key,
expire_time: Int(expireTime.timeIntervalSince1970),
user_id: userId
)
}
}