Compare commits

...

2 Commits

Author SHA1 Message Date
Joshua Perry 9ae4b9552f todos 2024-06-06 18:19:38 +01:00
Joshua Perry c59d9eb34a database entities 2024-06-06 18:19:27 +01:00
5 changed files with 74 additions and 0 deletions

1
src/api.rs Normal file
View File

@ -0,0 +1 @@
//TODO: Api Structure

3
src/auth.rs Normal file
View File

@ -0,0 +1,3 @@
//TODO: New User Auth loop
//TODO: Existing User Auth loop
//TODO: Hash Function

1
src/backup.rs Normal file
View File

@ -0,0 +1 @@
//TODO: Logic for backing up an account

66
src/db.rs Normal file
View File

@ -0,0 +1,66 @@
use serde::{Deserialize, Serialize};
use mongodb::{
bson::{DateTime, oid::ObjectId},
Client,
Database,
error::Error,
};
pub async fn get_database_client() -> Result<Database, Error> {
Ok(Client::with_uri_str("mongodb:://localhost:27017").await?.database("dermy"))
}
#[derive(Serialize, Deserialize)]
pub struct Mole {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
id: Option<ObjectId>,
#[serde(rename="_user_id")]
user_id: ObjectId,
#[serde(rename="_image_path")]
image_path: Option<String>,
location: Location,
}
#[derive(Serialize, Deserialize)]
pub enum Location {
FrontLocation(FrontLocation),
LeftSideLocation(LeftSideLocation),
RightSideLocation(RightSideLocation),
BackLocation(BackLocation),
}
#[derive(Serialize, Deserialize)]
pub enum FrontLocation {} //TODO: Add front locations
#[derive(Serialize, Deserialize)]
pub enum LeftSideLocation {} //TODO: Add left side locations
#[derive(Serialize, Deserialize)]
pub enum RightSideLocation {} //TODO: Add right side locations
#[derive(Serialize, Deserialize)]
pub enum BackLocation {} //TODO: Add back locations
#[derive(Serialize, Deserialize)]
pub struct LogEntry {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
id: Option<ObjectId>,
#[serde(rename = "_date_created")]
date_created: DateTime,
contents: String,
#[serde(rename = "_mole_id")]
mole_id: ObjectId
}
#[derive(Serialize, Deserialize)]
pub struct User {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
id: Option<ObjectId>,
#[serde(rename="_auth")]
auth: Auth,
username: String,
}
#[derive(Serialize, Deserialize)]
pub struct Auth {
#[serde(rename = "_hash", skip_serializing_if = "String::is_empty")]
hash: String,
#[serde(rename = "_salt", skip_serializing_if = "String::is_empty")]
salt: String,
}

3
src/lib.rs Normal file
View File

@ -0,0 +1,3 @@
mod api;
mod backup;
mod db;