General cleanup: fix some bugs, some refactoring (#65)

* Merged mod file upload in version creation, mod creation and
  version file add to one function;  This makes sure that they are
  consistent
* Made some fields on `User` optional: `github_id`, `avatar_url`, `bio`.
    * We may not want to publicly show the `github_id` to everyone
      with access to the API
    * If we allow non-github users, some of those fields would be
      invalid; some oauth providers may not have avatars or bios
* Made CORS origins should configurable
* Made `--reconfigure-indices` and `--reset-indices` exit after
  completion instead of starting the server
This commit is contained in:
Aeledfyr
2020-10-01 00:07:52 -05:00
committed by GitHub
parent 43a791db65
commit c4fb7b7928
16 changed files with 318 additions and 561 deletions

View File

@@ -89,7 +89,7 @@ pub struct VersionFile {
pub hashes: std::collections::HashMap<String, String>,
/// A direct link to the file for downloading it.
pub url: String,
/// A direct link to the file for downloading it.
/// The filename of the file.
pub filename: String,
}
@@ -101,14 +101,13 @@ pub enum VersionType {
Alpha,
}
impl ToString for VersionType {
fn to_string(&self) -> String {
impl std::fmt::Display for VersionType {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
VersionType::Release => "release",
VersionType::Beta => "beta",
VersionType::Alpha => "alpha",
VersionType::Release => write!(fmt, "release"),
VersionType::Beta => write!(fmt, "beta"),
VersionType::Alpha => write!(fmt, "alpha"),
}
.to_string()
}
}
@@ -122,6 +121,8 @@ pub struct GameVersion(pub String);
#[serde(transparent)]
pub struct ModLoader(pub String);
// These fields must always succeed parsing; deserialize errors aren't
// processed correctly (don't return JSON errors)
#[derive(Serialize, Deserialize)]
pub struct SearchRequest {
pub query: Option<String>,
@@ -133,5 +134,5 @@ pub struct SearchRequest {
pub version: Option<String>,
pub offset: Option<String>,
pub index: Option<String>,
pub limit: Option<usize>,
pub limit: Option<String>,
}

View File

@@ -2,7 +2,6 @@ use super::ids::Base62Id;
use crate::models::users::UserId;
use serde::{Deserialize, Serialize};
//TODO Implement Item for teams
/// The ID of a team
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(from = "Base62Id")]
@@ -26,6 +25,6 @@ pub struct TeamMember {
pub user_id: UserId,
/// The name of the user
pub name: String,
///The role of the use in the team
/// The role of the user in the team
pub role: String,
}

View File

@@ -9,29 +9,30 @@ pub struct UserId(pub u64);
#[derive(Serialize, Deserialize)]
pub struct User {
pub id: UserId,
pub github_id: u64,
pub github_id: Option<u64>,
pub username: String,
pub name: String,
pub email: Option<String>,
pub avatar_url: String,
pub bio: String,
pub avatar_url: Option<String>,
pub bio: Option<String>,
pub created: chrono::DateTime<chrono::Utc>,
pub role: Role,
}
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Role {
Developer,
Moderator,
Admin,
}
impl ToString for Role {
fn to_string(&self) -> String {
impl std::fmt::Display for Role {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Role::Developer => String::from("developer"),
Role::Moderator => String::from("moderator"),
Role::Admin => String::from("admin"),
Role::Developer => write!(fmt, "developer"),
Role::Moderator => write!(fmt, "moderator"),
Role::Admin => write!(fmt, "admin"),
}
}
}