init
This commit is contained in:
9
dollhouse/crates/dollhouse-api-types/Cargo.toml
Executable file
9
dollhouse/crates/dollhouse-api-types/Cargo.toml
Executable file
@@ -0,0 +1,9 @@
|
||||
[package]
|
||||
name = "dollhouse-api-types"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
validator = { version = "0.20.0", features = ["derive"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
uuid = { workspace = true }
|
||||
163
dollhouse/crates/dollhouse-api-types/src/lib.rs
Executable file
163
dollhouse/crates/dollhouse-api-types/src/lib.rs
Executable file
@@ -0,0 +1,163 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::convert::TryFrom;
|
||||
use uuid::Uuid;
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ReplicantGender {
|
||||
Male,
|
||||
Female,
|
||||
NonBinary,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ReplicantStatus {
|
||||
Active,
|
||||
Decommissioned,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ReplicantResponse {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub status: ReplicantStatus,
|
||||
pub gender: ReplicantGender,
|
||||
pub is_private: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ReplicantFullResponse {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub status: ReplicantStatus,
|
||||
pub gender: ReplicantGender,
|
||||
pub firmware_file: Option<String>,
|
||||
pub is_private: bool,
|
||||
pub corp_id: Uuid,
|
||||
pub health: i32,
|
||||
pub strength: i32,
|
||||
pub intelligence: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum UserRole {
|
||||
CorpAdmin,
|
||||
User,
|
||||
}
|
||||
|
||||
impl TryFrom<String> for UserRole {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_from(value: String) -> Result<Self, Self::Error> {
|
||||
match value.as_str() {
|
||||
"corp_admin" => Ok(UserRole::CorpAdmin),
|
||||
"user" => Ok(UserRole::User),
|
||||
_ => Err("Invalid user role"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<String> for UserRole {
|
||||
type Error = &'static str;
|
||||
|
||||
fn try_into(self) -> Result<String, Self::Error> {
|
||||
match self {
|
||||
UserRole::CorpAdmin => Ok("corp_admin".to_string()),
|
||||
UserRole::User => Ok("user".to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
pub struct CreateUserRequest {
|
||||
#[validate(length(min = 5, max = 50))]
|
||||
pub username: String,
|
||||
#[validate(length(min = 8))]
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
pub struct CreateCorpRequest {
|
||||
#[validate(length(min = 5, max = 50))]
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
pub struct CreateReplicantRequest {
|
||||
#[validate(length(min = 5, max = 50))]
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub gender: ReplicantGender,
|
||||
pub corp_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct CreateReplicantResponse {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: Option<String>,
|
||||
pub gender: ReplicantGender,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Validate)]
|
||||
pub struct LoginRequest {
|
||||
#[validate(length(min = 5, max = 50))]
|
||||
pub username: String,
|
||||
#[validate(length(min = 12, max = 50))]
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct UserResponse {
|
||||
pub id: Uuid,
|
||||
pub role: UserRole,
|
||||
pub username: String,
|
||||
pub corp_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct StaffResponse {
|
||||
pub id: Uuid,
|
||||
pub role: UserRole,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct CorpResponse {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub staff: Vec<StaffResponse>,
|
||||
pub invite_code: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct InviteCodeResponse {
|
||||
pub code: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct JoinCorpRequest {
|
||||
pub invite_code: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ChangePrivacyRequest {
|
||||
pub is_private: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct ChangeReplicantOwnerRequest {
|
||||
pub new_corp: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct FirmwareOutputResponse {
|
||||
pub output: String,
|
||||
}
|
||||
Reference in New Issue
Block a user