Introduced "pot" concept for isolating different apps' elements from each other. Removed tracing_setup macro since it disabled most logging output

This commit is contained in:
Philip (a-0) 2024-01-14 14:38:05 +01:00
parent 4f8d6ec3d0
commit a768ce0f4e
17 changed files with 424 additions and 41 deletions

View file

@ -1,12 +1,15 @@
use reqwest::Method;
use serde::{Deserialize, Serialize};
use crate::types::PotId;
use super::UbisyncRequest;
#[derive(Serialize, Deserialize)]
pub struct AppRegisterRequest {
pub name: String,
pub description: String,
pub app_type: String,
}
#[derive(Serialize, Deserialize)]
@ -25,3 +28,47 @@ impl UbisyncRequest for AppRegisterRequest {
"/app/register".to_string()
}
}
#[derive(Serialize, Deserialize)]
pub struct AppCreatePotRequest {
pub app_type: Option<String>,
}
#[derive(Serialize, Deserialize)]
pub struct AppCreatePotResponse {
pub pot_id: PotId,
}
impl UbisyncRequest for AppCreatePotRequest {
type PathParameters = ();
type Response = AppCreatePotResponse;
fn method(&self) -> Method {
Method::PUT
}
fn path(&self, _: Self::PathParameters) -> String {
"/app/pot".to_string()
}
}
#[derive(Serialize, Deserialize)]
pub struct AppSetDefaultPotRequest {
pub pot_id: PotId,
}
#[derive(Serialize, Deserialize)]
pub struct AppSetDefaultPotResponse;
impl UbisyncRequest for AppSetDefaultPotRequest {
type PathParameters = ();
type Response = AppSetDefaultPotResponse;
fn method(&self) -> Method {
Method::POST
}
fn path(&self, _: Self::PathParameters) -> String {
"/app/pot/default".to_string()
}
}

View file

@ -2,15 +2,3 @@ pub mod api;
pub mod messages;
pub mod peer;
pub mod types;
#[macro_export]
macro_rules! tracing_setup {
($level:expr) => {
let _tracing_default_guard = tracing::subscriber::set_default(
tracing_subscriber::fmt()
.pretty()
.with_max_level($level)
.finish(),
);
};
}

View file

@ -13,5 +13,11 @@ pub use message_id::MessageId;
mod peer_id;
pub use peer_id::PeerId;
mod pot_id;
pub use pot_id::PotId;
mod pot;
pub use pot::Pot;
mod tag;
pub use tag::Tag;

View file

@ -0,0 +1,22 @@
use serde::{Deserialize, Serialize};
use super::PotId;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct Pot {
id: PotId,
app_type: String,
}
impl Pot {
pub fn new(id: PotId, app_type: String) -> Self {
Pot { id, app_type }
}
pub fn id(&self) -> &PotId {
&self.id
}
pub fn app_type(&self) -> &str {
&self.app_type
}
}

View file

@ -0,0 +1,29 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct PotId(Uuid);
impl PotId {
pub fn new() -> Self {
PotId(Uuid::new_v4())
}
}
impl ToString for PotId {
fn to_string(&self) -> String {
self.0.to_string()
}
}
impl From<&PotId> for String {
fn from(value: &PotId) -> Self {
value.0.to_string()
}
}
impl TryFrom<&str> for PotId {
type Error = serde_json::Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
serde_json::from_str(value)
}
}