Create schema for the API (#28)

* feat(schema): add basic structs for schema

* feat(schema): implement base62 id parsing

* docs(schema): add documentation for schema structs
fix(schema): prevent integer overflow in base62 decoding

* refactor(schema): move ids into submodules, reexport from ids mod

* feat(schema): add random generation of base62 ids
style: run rustfmt
This commit is contained in:
Aeledfyr
2020-07-01 15:24:42 -05:00
committed by GitHub
parent f22e4f1cc7
commit 6d16b68f11
6 changed files with 327 additions and 0 deletions

33
src/models/teams.rs Normal file
View File

@@ -0,0 +1,33 @@
use super::ids::Base62Id;
use serde::{Deserialize, Serialize};
/// The ID of a specific user, encoded as base62 for usage in the API
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(from = "Base62Id")]
#[serde(into = "Base62Id")]
pub struct UserId(pub u64);
/// The ID of a team
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(from = "Base62Id")]
#[serde(into = "Base62Id")]
pub struct TeamId(pub u64);
// TODO: permissions, role names, etc
/// A team of users who control a mod
#[derive(Serialize, Deserialize)]
pub struct Team {
/// The id of the team
pub id: TeamId,
/// A list of the members of the team
pub members: Vec<TeamMember>,
}
/// A member of a team
#[derive(Serialize, Deserialize)]
pub struct TeamMember {
/// The ID of the user associated with the member
pub user_id: UserId,
/// The name of the user
pub name: String,
}