use serde::{Deserialize, Serialize};
pub trait ProjectInfo {
fn get_id(&self) -> &str;
fn get_slug(&self) -> Option<&str>;
fn get_title(&self) -> Option<&str>;
fn get_description(&self) -> Option<&str>;
fn get_categories(&self) -> Option<&[String]>;
fn get_client_side(&self) -> Option<&str>;
fn get_server_side(&self) -> Option<&str>;
fn get_project_type(&self) -> &str;
fn get_downloads(&self) -> i32;
fn get_versions(&self) -> &[String];
fn get_followers(&self) -> i32;
fn get_author(&self) -> &str;
fn get_date_created(&self) -> &str;
fn get_date_modified(&self) -> &str;
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Project {
pub id: String,
pub team: String,
pub published: String,
pub updated: String,
pub followers: i32,
pub versions: Vec<String>,
pub downloads: i32,
pub project_type: String,
pub slug: Option<String>,
pub title: Option<String>,
pub description: Option<String>,
pub game_versions: Option<Vec<String>>,
pub loaders: Option<Vec<String>>,
pub categories: Option<Vec<String>>,
pub client_side: Option<String>,
pub server_side: Option<String>,
pub body: Option<String>,
pub license: Option<License>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct License {
pub id: String,
pub name: String,
pub url: Option<String>,
}
impl ProjectInfo for Project {
fn get_id(&self) -> &str { &self.id }
fn get_slug(&self) -> Option<&str> { self.slug.as_deref() }
fn get_title(&self) -> Option<&str> { self.title.as_deref() }
fn get_description(&self) -> Option<&str> { self.description.as_deref() }
fn get_categories(&self) -> Option<&[String]> { self.categories.as_deref() }
fn get_client_side(&self) -> Option<&str> { self.client_side.as_deref() }
fn get_server_side(&self) -> Option<&str> { self.server_side.as_deref() }
fn get_project_type(&self) -> &str { &self.project_type }
fn get_downloads(&self) -> i32 { self.downloads }
fn get_versions(&self) -> &[String] { &self.versions }
fn get_followers(&self) -> i32 { self.followers }
fn get_author(&self) -> &str { &self.team }
fn get_date_created(&self) -> &str { &self.published }
fn get_date_modified(&self) -> &str { &self.updated }
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SearchHit {
pub project_type: String,
pub downloads: i32,
pub project_id: String,
pub author: String,
pub versions: Vec<String>,
pub follows: i32,
pub date_created: String,
pub date_modified: String,
pub license: String,
pub slug: Option<String>,
pub title: Option<String>,
pub description: Option<String>,
pub categories: Option<Vec<String>>,
pub client_side: Option<String>,
pub server_side: Option<String>,
}
impl ProjectInfo for SearchHit {
fn get_id(&self) -> &str { &self.project_id }
fn get_slug(&self) -> Option<&str> { self.slug.as_deref() }
fn get_title(&self) -> Option<&str> { self.title.as_deref() }
fn get_description(&self) -> Option<&str> { self.description.as_deref() }
fn get_categories(&self) -> Option<&[String]> { self.categories.as_deref() }
fn get_client_side(&self) -> Option<&str> { self.client_side.as_deref() }
fn get_server_side(&self) -> Option<&str> { self.server_side.as_deref() }
fn get_project_type(&self) -> &str { &self.project_type }
fn get_downloads(&self) -> i32 { self.downloads }
fn get_versions(&self) -> &[String] { &self.versions }
fn get_followers(&self) -> i32 { self.follows }
fn get_author(&self) -> &str { &self.author }
fn get_date_created(&self) -> &str { &self.date_created }
fn get_date_modified(&self) -> &str { &self.date_modified }
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SearchResult {
pub hits: Vec<SearchHit>,
pub offset: i32,
pub limit: i32,
pub total_hits: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Version {
pub id: String,
pub project_id: String,
pub author_id: String,
pub date_published: String,
pub downloads: i32,
pub files: Vec<VersionFile>,
pub name: Option<String>,
pub version_number: Option<String>,
pub changelog: Option<String>,
pub dependencies: Option<Vec<VersionDependency>>,
pub game_versions: Option<Vec<String>>,
pub version_type: Option<String>,
pub loaders: Option<Vec<String>>,
pub featured: Option<bool>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VersionFile {
pub hashes: Hashes,
pub url: String,
pub filename: String,
pub primary: bool,
pub size: i32,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Hashes {
pub sha512: String,
pub sha1: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct Dependencies {
pub projects: Vec<Project>,
pub versions: Vec<Version>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct VersionDependency {
pub dependency_type: String,
pub version_id: Option<String>,
pub project_id: Option<String>,
pub file_name: Option<String>,
}