Models WIP: Weekly, RantFeed

This commit is contained in:
Wilhelm Oks 2024-12-12 12:24:35 +01:00
parent b9d990b1f3
commit 2a15f2ea73
4 changed files with 167 additions and 0 deletions

View File

@ -0,0 +1,68 @@
public extension RantFeed {
/// Contains information about news given in rant feeds.
/// - note: This is mostly used for weekly group rants.
struct News: Hashable, Identifiable {
public enum Action: String {
case groupRant = "grouprant"
case none = "none"
case rant = "rant"
}
public let id: Int
/// Most of the time this is equal to the value `intlink`, this specifies the type of news.
/// This should be an enum but it's unknown what the other values are and weekly news are dead anyway.
public let type: String
/// The headline text of the news.
public let headlineText: String
/// The contents of the news.
public let text: String
/// The footer text of the news.
public let footerText: String
/// The height of the news view on the screen.
public let height: Int
/// The action that should be performed when the user taps/clicks on the news.
public let action: Action
public init(id: Int, type: String, headlineText: String, text: String, footerText: String, height: Int, action: Action) {
self.id = id
self.type = type
self.headlineText = headlineText
self.text = text
self.footerText = footerText
self.height = height
self.action = action
}
}
}
extension RantFeed.News {
struct CodingData: Codable {
let id: Int
let type: String
let headline: String
let body: String?
let footer: String
let height: Int
let action: String
}
}
extension RantFeed.News.CodingData {
var decoded: RantFeed.News {
.init(
id: id,
type: type,
headlineText: headline,
text: body ?? "",
footerText: footer,
height: height,
action: .init(rawValue: action) ?? .none
)
}
}

View File

@ -0,0 +1,47 @@
/// Contains the list of rants for the logged in user and other random things.
public struct RantFeed: Hashable {
public var rants: [Rant]
/// The notification settings for the logged-in user.
//public let settings: Settings
public let sessionHash: String?
/// The weekly group rant week number.
public let weeklyRantWeek: Int?
/// True if the logged in user is subscribed to devRant++.
public let devRantSupporter: Bool
//public let isUserDPP: Int
public let numberOfUnreadNotifications: Int
public let news: News?
}
public extension RantFeed {
enum Sort {
/// The devRant algorithm decides what rants appear in the feed.
case algorithm
/// The most recent rants appear in the feed.
case recent
/// The top rated rants appear in the feed.
case top(range: Range)
}
enum Range {
/// Rants from the one day.
case day
/// Rants from the one week.
case week
/// Rants from the one month.
case month
/// Rants from all time.
case all
}
}

View File

@ -1,7 +1,12 @@
public struct User: Identifiable, Hashable { public struct User: Identifiable, Hashable {
public let id: Int public let id: Int
public let name: String public let name: String
/// The number of upvotes from other users.
public let score: Int public let score: Int
/// True if the logged in user is subscribed to devRant++.
public let devRantSupporter: Bool public let devRantSupporter: Bool
/// A small avatar for the rant views and comment views. /// A small avatar for the rant views and comment views.

View File

@ -0,0 +1,47 @@
/// The weekly item data for the list of weeklies.
public struct Weekly: Hashable, Identifiable {
/// The number of the week. The first week starts with 1.
public let week: Int
/// The weekly subject/topic.
public let topic: String
/// The US formatted date the weekly.
public let formattedDate: String
/// How many rants have beeon posted for this weekly.
public let numberOfRants: Int
public var id: Int { week }
public init(week: Int, topic: String, formattedDate: String, numberOfRants: Int) {
self.week = week
self.topic = topic
self.formattedDate = formattedDate
self.numberOfRants = numberOfRants
}
}
extension Weekly {
struct CodingData: Codable {
let week: Int
let prompt: String
let date: String
let num_rants: Int
struct List: Codable {
let weeks: [CodingData]
}
}
}
extension Weekly.CodingData {
var decoded: Weekly {
.init(
week: week,
topic: prompt,
formattedDate: date,
numberOfRants: num_rants
)
}
}