Skip to content

Commit

Permalink
Black magic cooking
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac Ecob committed Jul 19, 2024
1 parent 256b6e8 commit 4fa8c46
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
1 change: 1 addition & 0 deletions backend/aide
Submodule aide added at 2bad9a
6 changes: 4 additions & 2 deletions backend/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ rust-s3 = "0.34.0"
rs-snowflake = "0.6"
jsonwebtoken = "9.1"
dotenvy = "0.15"
aide = { version = "0.13.4", features = ["axum", "macros"]}
#aide = { version = "0.13.4", features = ["axum", "macros", "http"]}
aide = { path="../aide/crates/aide", features = ["axum", "macros", "http"]}
aide-macros = { path="../aide/crates/aide-macros"}
axum-jsonschema = { path="../aide/crates/axum-jsonschema"}
schemars = {version = "0.8.21", features = ["chrono"]}

3 changes: 1 addition & 2 deletions backend/server/src/handler/organisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ use crate::models::transaction::DBTransaction;
use crate::service;
use axum::extract::{Json, Path, State};
use axum::http::StatusCode;
use axum::response::IntoResponse;
use aide::OperationOutput;
//use http::status::StatusCode;
use aide::axum::IntoApiResponse;

pub struct OrganisationHandler;
Expand Down
1 change: 1 addition & 0 deletions backend/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use sqlx::postgres::PgPoolOptions;
use std::env;

use axum::Json;
use aide::OperationOutput;
use aide::{
axum::{
routing::{get, post, patch, put},
Expand Down
27 changes: 24 additions & 3 deletions backend/server/src/models/error.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
use axum::http::StatusCode;
use axum::response::{IntoResponse, Redirect, Response};
use aide::OperationIo;
use aide::{OperationIo, OperationOutput,
gen,
openapi::Operation,
};
use schemars::JsonSchema;

/// Custom error enum for Chaos.
///
/// Handles all errors thrown by libraries (when `?` is used) alongside
/// specific errors for business logic.
#[derive(thiserror::Error, Debug, OperationIo)]
#[aide(output)]
//#[derive(thiserror::Error, Debug, OperationIo)]
//#[aide(output)]
#[derive(thiserror::Error, Debug)]
pub enum ChaosError {
#[error("Not logged in")]
NotLoggedIn,
Expand Down Expand Up @@ -59,3 +64,19 @@ impl IntoResponse for ChaosError {
}
}
}

impl OperationOutput for ChaosError {
type Inner = Self;

fn inferred_responses(
ctx: &mut gen::GenContext,
operation: &mut Operation,
) -> Vec<(Option<u16>, aide::openapi::Response)> {
Vec::from([
(Some(400), Default::default()), // Bad request
(Some(401), Default::default()), // Unauthorized
(Some(403), Default::default()), // Forbidden
(Some(500), Default::default()), // Internal Server Error
])
}
}
8 changes: 4 additions & 4 deletions backend/server/src/models/organisation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,29 @@ pub struct NewOrganisation {
}


#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, JsonSchema)]
pub struct OrganisationDetails {
pub id: i64,
pub name: String,
pub logo: Option<String>,
pub created_at: DateTime<Utc>,
}

#[derive(Deserialize, Serialize, sqlx::Type, Clone)]
#[derive(Deserialize, Serialize, sqlx::Type, Clone, JsonSchema)]
#[sqlx(type_name = "organisation_role", rename_all = "PascalCase")]
pub enum OrganisationRole {
User,
Admin,
}

#[derive(Deserialize, Serialize, FromRow)]
#[derive(Deserialize, Serialize, FromRow, JsonSchema)]
pub struct Member {
pub id: i64,
pub name: String,
pub role: OrganisationRole,
}

#[derive(Deserialize, Serialize)]
#[derive(Deserialize, Serialize, OperationIo, JsonSchema)]
pub struct MemberList {
pub members: Vec<Member>,
}
Expand Down

0 comments on commit 4fa8c46

Please sign in to comment.