Compare commits
14 Commits
Author | SHA1 | Date | |
---|---|---|---|
6854a5e14d | |||
5d89ccb7c1 | |||
e429534100 | |||
1881650e9c | |||
e9ae99520c | |||
cd0ab2dec6 | |||
5d20d8576f | |||
3979a59665 | |||
a2371b7bf1 | |||
6bed8590ca | |||
daeb208448 | |||
9ffc1aad05 | |||
a08a879f5a | |||
d4b415dca3 |
@@ -2,7 +2,7 @@
|
||||
name = "icarus-models"
|
||||
description = "models used for the icarus project"
|
||||
license = "MIT"
|
||||
version = "0.1.3"
|
||||
version = "0.1.7"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
|
@@ -19,13 +19,12 @@ impl Default for AccessLevel {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn default_level() -> AccessLevel {
|
||||
return AccessLevel {
|
||||
id: -1,
|
||||
level: String::from("Public"),
|
||||
song_id: -1,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
pub fn private_level() -> AccessLevel {
|
||||
@@ -33,11 +32,9 @@ pub fn private_level() -> AccessLevel {
|
||||
id: -1,
|
||||
level: String::from("Private"),
|
||||
song_id: -1,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl AccessLevel {
|
||||
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
|
||||
return serde_json::to_string_pretty(&self);
|
||||
|
5
src/constants.rs
Normal file
5
src/constants.rs
Normal file
@@ -0,0 +1,5 @@
|
||||
pub const DEFAULT_MUSIC_EXTENSION: &str = FLAC_EXTENSION;
|
||||
pub const FLAC_EXTENSION: &str = ".flac";
|
||||
pub const WAV_EXTENSION: &str = ".wav";
|
||||
pub const MPTHREE_EXTENSION: &str = ".mp3";
|
||||
pub const JPG_EXTENSION: &str = ".jpg";
|
@@ -1,4 +1,5 @@
|
||||
pub mod access_level;
|
||||
pub mod constants;
|
||||
pub mod login_result;
|
||||
pub mod song;
|
||||
pub mod token;
|
||||
|
24
src/token.rs
24
src/token.rs
@@ -11,6 +11,22 @@ pub struct Token {
|
||||
pub issued: i32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct AccessToken {
|
||||
#[serde(alias = "user_id")]
|
||||
pub user_id: i32,
|
||||
#[serde(alias = "username")]
|
||||
pub username: String,
|
||||
#[serde(alias = "token")]
|
||||
pub token: String,
|
||||
#[serde(alias = "token_type")]
|
||||
pub token_type: String,
|
||||
#[serde(alias = "expiration")]
|
||||
pub expiration: i32,
|
||||
#[serde(alias = "message")]
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Default for Token {
|
||||
fn default() -> Self {
|
||||
Token {
|
||||
@@ -23,6 +39,14 @@ impl Default for Token {
|
||||
}
|
||||
}
|
||||
|
||||
impl AccessToken {
|
||||
pub fn bearer_token(&self) -> String {
|
||||
let mut token: String = String::from("Bearer ");
|
||||
token += &self.token.clone();
|
||||
return token;
|
||||
}
|
||||
}
|
||||
|
||||
impl Token {
|
||||
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
|
||||
return serde_json::to_string_pretty(&self);
|
||||
|
22
src/user.rs
22
src/user.rs
@@ -4,19 +4,33 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct User {
|
||||
#[serde(skip_serializing_if = "is_id_valid")]
|
||||
pub id: i32,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub username: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub password: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub email: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub phone: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub firstname: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub lastname: String,
|
||||
pub email_verified: bool,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub date_created: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub status: String,
|
||||
#[serde(skip_serializing_if = "String::is_empty")]
|
||||
pub last_login: String,
|
||||
}
|
||||
|
||||
fn is_id_valid(num: &i32) -> bool {
|
||||
*num > 0
|
||||
}
|
||||
|
||||
impl Default for User {
|
||||
fn default() -> Self {
|
||||
User {
|
||||
@@ -36,7 +50,11 @@ impl Default for User {
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn _to_json(&self) -> Result<String, serde_json::Error> {
|
||||
return serde_json::to_string_pretty(&self);
|
||||
pub fn to_json(&self, output_pretty: bool) -> Result<String, serde_json::Error> {
|
||||
if output_pretty {
|
||||
return serde_json::to_string_pretty(&self);
|
||||
} else {
|
||||
return serde_json::to_string(&self);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user