Create internal User and API UserObject
This commit is contained in:
parent
3932df005b
commit
eea118b623
|
@ -3,7 +3,7 @@ pub mod schemas {
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::{collections::HashMap, fmt};
|
use std::{collections::HashMap, fmt};
|
||||||
|
|
||||||
use crate::errors::FieldFormatError;
|
use crate::{errors::FieldFormatError, URLBundle};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A struct that represents a well-formed email address.
|
A struct that represents a well-formed email address.
|
||||||
|
@ -380,6 +380,76 @@ pub mod schemas {
|
||||||
pub message: String,
|
pub message: String,
|
||||||
pub code: String,
|
pub code: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
|
pub struct UserObject {
|
||||||
|
id: String,
|
||||||
|
username: String,
|
||||||
|
discriminator: String,
|
||||||
|
avatar: Option<String>,
|
||||||
|
bot: Option<bool>,
|
||||||
|
system: Option<bool>,
|
||||||
|
mfa_enabled: Option<bool>,
|
||||||
|
banner: Option<bool>,
|
||||||
|
accent_color: Option<String>,
|
||||||
|
locale: String,
|
||||||
|
verified: Option<bool>,
|
||||||
|
email: Option<String>,
|
||||||
|
flags: i8,
|
||||||
|
premium_type: Option<i8>,
|
||||||
|
public_flags: Option<i8>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct User {
|
||||||
|
logged_in: bool,
|
||||||
|
belongs_to: URLBundle,
|
||||||
|
token: String,
|
||||||
|
pub settings: UserSettings,
|
||||||
|
pub object: UserObject,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl User {
|
||||||
|
pub fn is_logged_in(&self) -> bool {
|
||||||
|
if self.logged_in == true {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn belongs_to(&self) -> URLBundle {
|
||||||
|
return self.belongs_to.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn token(&self) -> String {
|
||||||
|
return self.token.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_logged_in(&mut self, bool: bool) {
|
||||||
|
self.logged_in = bool;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn set_token(&mut self, token: String) {
|
||||||
|
self.token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new(
|
||||||
|
logged_in: bool,
|
||||||
|
belongs_to: URLBundle,
|
||||||
|
token: String,
|
||||||
|
settings: UserSettings,
|
||||||
|
object: UserObject,
|
||||||
|
) -> User {
|
||||||
|
User {
|
||||||
|
logged_in,
|
||||||
|
belongs_to,
|
||||||
|
token,
|
||||||
|
settings,
|
||||||
|
object,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// I know that some of these tests are... really really basic and unneccessary, but sometimes, I
|
// I know that some of these tests are... really really basic and unneccessary, but sometimes, I
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::api::schemas::schemas::InstancePoliciesSchema;
|
use crate::api::schemas::schemas::{InstancePoliciesSchema, User};
|
||||||
use crate::errors::{FieldFormatError, InstanceServerError};
|
use crate::errors::{FieldFormatError, InstanceServerError};
|
||||||
use crate::limit::LimitedRequester;
|
use crate::limit::LimitedRequester;
|
||||||
use crate::URLBundle;
|
use crate::URLBundle;
|
||||||
|
@ -15,7 +15,7 @@ pub struct Instance {
|
||||||
pub instance_info: InstancePoliciesSchema,
|
pub instance_info: InstancePoliciesSchema,
|
||||||
pub requester: LimitedRequester,
|
pub requester: LimitedRequester,
|
||||||
//pub gateway: Gateway,
|
//pub gateway: Gateway,
|
||||||
pub users: HashMap<Token, Username>,
|
pub users: HashMap<Token, User>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
|
@ -29,7 +29,7 @@ impl Instance {
|
||||||
urls: URLBundle,
|
urls: URLBundle,
|
||||||
requester: LimitedRequester,
|
requester: LimitedRequester,
|
||||||
) -> Result<Instance, InstanceServerError> {
|
) -> Result<Instance, InstanceServerError> {
|
||||||
let users: HashMap<Token, Username> = HashMap::new();
|
let users: HashMap<Token, User> = HashMap::new();
|
||||||
let mut instance = Instance {
|
let mut instance = Instance {
|
||||||
urls,
|
urls,
|
||||||
instance_info: InstancePoliciesSchema::new(
|
instance_info: InstancePoliciesSchema::new(
|
||||||
|
|
Loading…
Reference in New Issue