Mod Creation (#34)

* Inital creation stuff

* File Reader

* Upload bodies

* Major rework:

* Finish Multiple Files

* Proper Error Handling

* Switch to database models

* Run formatter

* Make dependencies dependent on Versions over mods

* Fixes

* Fix clippy

* Run lint one last time

* Update src/models/mods.rs

Co-authored-by: AppleTheGolden <scotsbox@protonmail.com>

Co-authored-by: AppleTheGolden <scotsbox@protonmail.com>
This commit is contained in:
Geometrically
2020-07-16 10:16:35 -07:00
committed by GitHub
parent b1d3e258bd
commit 39b1435725
17 changed files with 567 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
mod mod_item;
mod team_item;
mod version_item;
use crate::database::DatabaseError::NotFound;
@@ -8,7 +9,11 @@ use bson::doc;
use bson::Document;
pub use mod_item::Mod;
use mongodb::Database;
pub use team_item::Team;
pub use team_item::TeamMember;
pub use version_item::FileHash;
pub use version_item::Version;
pub use version_item::VersionFile;
#[async_trait]
pub trait Item {

View File

@@ -1,3 +1,4 @@
use crate::database::models::team_item::Team;
use crate::database::models::Item;
use crate::database::Result;
use bson::{Bson, Document};
@@ -5,15 +6,23 @@ use serde::{Deserialize, Serialize};
#[derive(Deserialize, Serialize)]
pub struct Mod {
/// The ID for the mod, must be serializable to base62
pub id: i32,
//Todo: Move to own table
/// The team that owns the mod
pub team: Team,
pub title: String,
pub description: String,
pub body_url: String,
pub published: String,
pub author: String,
pub downloads: i32,
pub categories: Vec<String>,
pub body_path: String,
pub icon_path: String,
///A vector of Version IDs specifying the mod version of a dependency
pub version_ids: Vec<i32>,
pub icon_url: Option<String>,
pub issues_url: Option<String>,
pub source_url: Option<String>,
pub wiki_url: Option<String>,
}
impl Item for Mod {
fn get_collection() -> &'static str {

View File

@@ -0,0 +1,20 @@
use serde::{Deserialize, Serialize};
/// A team of users who control a mod
#[derive(Serialize, Deserialize)]
pub struct Team {
/// The id of the team
pub id: i32,
/// A list of the members of the team
pub members: Vec<TeamMember>,
}
/// A member of a team
#[derive(Serialize, Deserialize, Clone)]
pub struct TeamMember {
/// The ID of the user associated with the member
pub user_id: i32,
/// The name of the user
pub name: String,
pub role: String,
}

View File

@@ -3,19 +3,39 @@ use crate::database::Result;
use bson::{Bson, Document};
use serde::{Deserialize, Serialize};
//TODO: Files should probably be moved to their own table
#[derive(Deserialize, Serialize)]
pub struct Version {
///The unqiue VersionId of this version
pub version_id: i32,
/// The ModId of the mod that this version belongs to
pub mod_id: i32,
pub title: String,
pub changelog_path: String,
pub files_path: Vec<String>,
pub name: String,
pub number: String,
pub changelog_url: Option<String>,
pub date_published: String,
pub author: String,
pub downloads: i32,
pub dependencies: Vec<String>,
pub files: Vec<VersionFile>,
pub dependencies: Vec<i32>,
pub game_versions: Vec<String>,
pub loaders: Vec<String>,
pub version_type: String,
}
#[derive(Serialize, Deserialize)]
pub struct VersionFile {
pub game_versions: Vec<String>,
pub hashes: Vec<FileHash>,
pub url: String,
}
/// A hash of a mod's file
#[derive(Serialize, Deserialize)]
pub struct FileHash {
pub algorithm: String,
pub hash: String,
}
impl Item for Version {
fn get_collection() -> &'static str {
"versions"