Implement users in API

This commit is contained in:
Jai A
2020-09-28 10:48:15 -07:00
parent cd28a75c86
commit 05235f8385
10 changed files with 188 additions and 22 deletions

View File

@@ -1,7 +1,8 @@
use thiserror::Error;
pub use super::mods::{ModId, VersionId};
pub use super::teams::{TeamId, UserId};
pub use super::teams::TeamId;
pub use super::users::UserId;
/// Generates a random 64 bit integer that is exactly `n` characters
/// long when encoded as base62.

View File

@@ -2,3 +2,4 @@ pub mod error;
pub mod ids;
pub mod mods;
pub mod teams;
pub mod users;

View File

@@ -1,13 +1,8 @@
use super::ids::Base62Id;
use serde::{Deserialize, Serialize};
use crate::models::users::UserId;
//TODO Implement Item for teams
/// 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")]

19
src/models/users.rs Normal file
View File

@@ -0,0 +1,19 @@
use super::ids::Base62Id;
use serde::{Deserialize, Serialize};
#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(from = "Base62Id")]
#[serde(into = "Base62Id")]
pub struct UserId(pub u64);
#[derive(Serialize, Deserialize)]
pub struct User {
pub id: UserId,
pub github_id: UserId,
pub username: String,
pub name: String,
pub email: Option<String>,
pub avatar_url: String,
pub bio: String,
pub created: chrono::DateTime<chrono::Utc>,
}