From d979e40ebaaec93efa2facac4ae9096efce4e4cc Mon Sep 17 00:00:00 2001 From: Caleb Bourg Date: Mon, 24 Feb 2025 14:02:51 -0500 Subject: [PATCH] remove web dependencies on entity and entity_api --- Cargo.lock | 3 --- domain/Cargo.toml | 1 - domain/src/action.rs | 1 + domain/src/agreement.rs | 2 +- domain/src/coaching_relationship.rs | 4 ++++ domain/src/coaching_session.rs | 24 ++++--------------- domain/src/jwt/mod.rs | 12 ++++------ domain/src/lib.rs | 15 +++++++++++- domain/src/note.rs | 1 + domain/src/organization.rs | 3 +++ domain/src/overarching_goal.rs | 1 + domain/src/user.rs | 1 + entity/src/{jwt.rs => jwts.rs} | 2 +- entity/src/lib.rs | 2 +- entity_api/src/lib.rs | 5 +++- entity_api/src/user.rs | 4 +--- web/Cargo.toml | 2 -- web/src/controller/action_controller.rs | 20 ++++++++-------- web/src/controller/agreement_controller.rs | 16 ++++++------- .../controller/coaching_session_controller.rs | 9 ++++--- web/src/controller/note_controller.rs | 15 ++++++------ .../coaching_relationship_controller.rs | 12 +++++----- web/src/controller/organization_controller.rs | 15 ++++++------ .../controller/overarching_goal_controller.rs | 4 ++-- web/src/controller/user_controller.rs | 7 +++--- web/src/controller/user_session_controller.rs | 12 +++++----- web/src/extractors/authenticated_user.rs | 5 ++-- web/src/lib.rs | 2 +- web/src/params/agreement.rs | 2 +- web/src/params/jwt.rs | 2 +- web/src/protect/actions.rs | 3 +-- web/src/protect/agreements.rs | 2 +- web/src/protect/coaching_relationships.rs | 3 +-- web/src/protect/coaching_sessions.rs | 3 +-- web/src/protect/jwt.rs | 2 +- web/src/protect/notes.rs | 3 +-- web/src/protect/overarching_goals.rs | 3 +-- web/src/router.rs | 24 +++++++++---------- 38 files changed, 119 insertions(+), 128 deletions(-) create mode 100644 domain/src/action.rs create mode 100644 domain/src/coaching_relationship.rs create mode 100644 domain/src/note.rs create mode 100644 domain/src/organization.rs create mode 100644 domain/src/overarching_goal.rs create mode 100644 domain/src/user.rs rename entity/src/{jwt.rs => jwts.rs} (96%) diff --git a/Cargo.lock b/Cargo.lock index 88b69fc3..376d0eed 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -838,7 +838,6 @@ name = "domain" version = "1.0.0-beta1" dependencies = [ "chrono", - "entity", "entity_api", "jsonwebtoken", "log", @@ -3914,8 +3913,6 @@ dependencies = [ "axum-login", "chrono", "domain", - "entity", - "entity_api", "log", "password-auth", "reqwest", diff --git a/domain/Cargo.toml b/domain/Cargo.toml index 2e15f571..35a50894 100644 --- a/domain/Cargo.toml +++ b/domain/Cargo.toml @@ -5,7 +5,6 @@ edition = "2021" [dependencies] chrono = { version = "0.4.38", features = ["serde"] } -entity = { path = "../entity" } entity_api = { path = "../entity_api" } jsonwebtoken = "9" service = { path = "../service" } diff --git a/domain/src/action.rs b/domain/src/action.rs new file mode 100644 index 00000000..d54420fd --- /dev/null +++ b/domain/src/action.rs @@ -0,0 +1 @@ +pub use entity_api::action::{create, delete_by_id, find_by, find_by_id, update, update_status}; diff --git a/domain/src/agreement.rs b/domain/src/agreement.rs index 7b2f07ae..d53d0b29 100644 --- a/domain/src/agreement.rs +++ b/domain/src/agreement.rs @@ -1,5 +1,5 @@ +use crate::agreements::Model; use crate::error::Error; -use entity::agreements::Model; pub use entity_api::agreement::{create, delete_by_id, find_by_id, update}; use entity_api::{agreement, IntoQueryFilterMap}; use sea_orm::DatabaseConnection; diff --git a/domain/src/coaching_relationship.rs b/domain/src/coaching_relationship.rs new file mode 100644 index 00000000..dc9ea228 --- /dev/null +++ b/domain/src/coaching_relationship.rs @@ -0,0 +1,4 @@ +pub use entity_api::coaching_relationship::{ + create, find_by, find_by_id, find_by_organization_with_user_names, find_by_user, + get_relationship_with_user_names, CoachingRelationshipWithUserNames, +}; diff --git a/domain/src/coaching_session.rs b/domain/src/coaching_session.rs index 5e361211..fff17fdb 100644 --- a/domain/src/coaching_session.rs +++ b/domain/src/coaching_session.rs @@ -1,13 +1,17 @@ +use crate::coaching_sessions::Model; use crate::error::{DomainErrorKind, Error, ExternalErrorKind, InternalErrorKind}; use crate::gateway::tiptap::client as tiptap_client; use chrono::{DurationRound, TimeDelta}; -use entity::coaching_sessions::Model; use entity_api::{coaching_relationship, coaching_session, organization}; use log::*; use sea_orm::DatabaseConnection; use serde_json::json; use service::config::Config; +pub use entity_api::coaching_session::{ + find_by, find_by_id, find_by_id_with_coaching_relationship, +}; + pub async fn create( db: &DatabaseConnection, config: &Config, @@ -81,21 +85,3 @@ pub async fn create( }) } } - -pub async fn find_by_id(db: &DatabaseConnection, id: entity::Id) -> Result { - Ok(coaching_session::find_by_id(db, id).await?) -} - -pub async fn find_by_id_with_coaching_relationship( - db: &DatabaseConnection, - id: entity::Id, -) -> Result<(Model, entity::coaching_relationships::Model), Error> { - Ok(coaching_session::find_by_id_with_coaching_relationship(db, id).await?) -} - -pub async fn find_by( - db: &DatabaseConnection, - params: std::collections::HashMap, -) -> Result, Error> { - Ok(coaching_session::find_by(db, params).await?) -} diff --git a/domain/src/jwt/mod.rs b/domain/src/jwt/mod.rs index b7010df6..0cb6e2bd 100644 --- a/domain/src/jwt/mod.rs +++ b/domain/src/jwt/mod.rs @@ -13,7 +13,7 @@ //! use domain::jwt::generate_collab_token; //! use sea_orm::DatabaseConnection; //! use service::config::Config; -//! use entity::Id; +//! use crate::Id; //! //! async fn example(db: &DatabaseConnection, config: &Config, coaching_session_id: Id) { //! match generate_collab_token(db, config, coaching_session_id).await { @@ -23,18 +23,14 @@ //! } //! ``` -use crate::coaching_session; use crate::error::{DomainErrorKind, Error, InternalErrorKind}; +use crate::{coaching_session, jwts::Jwts, Id}; use claims::TiptapCollabClaims; -use entity::Id; use jsonwebtoken::{encode, EncodingKey, Header}; use log::*; use sea_orm::DatabaseConnection; use service::config::Config; -// re-export the Jwt struct from the entity module -pub use entity::jwt::Jwt; - pub(crate) mod claims; /// Generates a collaboration token for a coaching session. @@ -47,7 +43,7 @@ pub async fn generate_collab_token( db: &DatabaseConnection, config: &Config, coaching_session_id: Id, -) -> Result { +) -> Result { let coaching_session = coaching_session::find_by_id(db, coaching_session_id).await?; let collab_document_name = coaching_session.collab_document_name.ok_or_else(|| { @@ -105,7 +101,7 @@ pub async fn generate_collab_token( &EncodingKey::from_secret(tiptap_jwt_signing_key.as_bytes()), )?; - Ok(Jwt { + Ok(Jwts { token, sub: collab_document_name, }) diff --git a/domain/src/lib.rs b/domain/src/lib.rs index 2ffb5bf8..e54522f3 100644 --- a/domain/src/lib.rs +++ b/domain/src/lib.rs @@ -1,4 +1,4 @@ -//! This module re-exports `IntoQueryFilterMap` and `QueryFilterMap` from the `entity_api` crate. +//! This module re-exports various items from the `entity_api` crate. //! //! The purpose of this re-export is to ensure that consumers of the `domain` crate do not need to //! directly depend on the `entity_api` crate. By re-exporting these items, we provide a clear and @@ -6,9 +6,22 @@ //! the underlying implementation details remain in the `entity_api` crate. pub use entity_api::{IntoQueryFilterMap, QueryFilterMap}; +// Re-exports from `entity` +pub use entity_api::user::{AuthSession, Backend, Credentials}; +pub use entity_api::{ + actions, agreements, coachees, coaches, coaching_relationships, coaching_sessions, jwts, notes, + organizations, overarching_goals, users, Id, +}; + +pub mod action; pub mod agreement; +pub mod coaching_relationship; pub mod coaching_session; pub mod error; pub mod jwt; +pub mod note; +pub mod organization; +pub mod overarching_goal; +pub mod user; pub(crate) mod gateway; diff --git a/domain/src/note.rs b/domain/src/note.rs new file mode 100644 index 00000000..c7141a8b --- /dev/null +++ b/domain/src/note.rs @@ -0,0 +1 @@ +pub use entity_api::note::{create, find_by, find_by_id, update}; diff --git a/domain/src/organization.rs b/domain/src/organization.rs new file mode 100644 index 00000000..3c76adc1 --- /dev/null +++ b/domain/src/organization.rs @@ -0,0 +1,3 @@ +pub use entity_api::organization::{ + create, delete_by_id, find_all, find_by, find_by_id, find_by_user, update, +}; diff --git a/domain/src/overarching_goal.rs b/domain/src/overarching_goal.rs new file mode 100644 index 00000000..49a34acb --- /dev/null +++ b/domain/src/overarching_goal.rs @@ -0,0 +1 @@ +pub use entity_api::overarching_goal::{create, find_by, find_by_id, update, update_status}; diff --git a/domain/src/user.rs b/domain/src/user.rs new file mode 100644 index 00000000..cd0a3c6d --- /dev/null +++ b/domain/src/user.rs @@ -0,0 +1 @@ +pub use entity_api::user::{create, find_by_email}; diff --git a/entity/src/jwt.rs b/entity/src/jwts.rs similarity index 96% rename from entity/src/jwt.rs rename to entity/src/jwts.rs index 6ffeecf9..1f8063b3 100644 --- a/entity/src/jwt.rs +++ b/entity/src/jwts.rs @@ -11,7 +11,7 @@ use utoipa::ToSchema; /// the subject without having to decode the JWT. #[derive(Serialize, Debug, ToSchema)] #[schema(as = jwt::Jwt)] // OpenAPI schema -pub struct Jwt { +pub struct Jwts { pub token: String, pub sub: String, } diff --git a/entity/src/lib.rs b/entity/src/lib.rs index 3410d88c..06772760 100644 --- a/entity/src/lib.rs +++ b/entity/src/lib.rs @@ -8,7 +8,7 @@ pub mod coachees; pub mod coaches; pub mod coaching_relationships; pub mod coaching_sessions; -pub mod jwt; +pub mod jwts; pub mod notes; pub mod organizations; pub mod overarching_goals; diff --git a/entity_api/src/lib.rs b/entity_api/src/lib.rs index 49d3c80b..5f1b09bc 100644 --- a/entity_api/src/lib.rs +++ b/entity_api/src/lib.rs @@ -3,7 +3,10 @@ use password_auth::generate_hash; use sea_orm::{ActiveModelTrait, DatabaseConnection, Set, Value}; use std::collections::HashMap; -use entity::{coaching_relationships, coaching_sessions, organizations, users, Id}; +pub use entity::{ + actions, agreements, coachees, coaches, coaching_relationships, coaching_sessions, jwts, notes, + organizations, overarching_goals, users, Id, +}; pub mod action; pub mod agreement; diff --git a/entity_api/src/user.rs b/entity_api/src/user.rs index cdc82753..01a7172b 100644 --- a/entity_api/src/user.rs +++ b/entity_api/src/user.rs @@ -2,7 +2,7 @@ use super::error::{EntityApiErrorKind, Error}; use async_trait::async_trait; use axum_login::{AuthnBackend, UserId}; use chrono::Utc; -use entity::users::*; +use entity::users::{ActiveModel, Column, Entity, Model}; use log::*; use password_auth::{generate_hash, verify_password}; use sea_orm::{entity::prelude::*, DatabaseConnection, Set}; @@ -10,8 +10,6 @@ use serde::Deserialize; use std::sync::Arc; use utoipa::ToSchema; -use crate::user::Entity; - pub async fn create(db: &DatabaseConnection, user_model: Model) -> Result { debug!( "New User Relationship Model to be inserted: {:?}", diff --git a/web/Cargo.toml b/web/Cargo.toml index 8bf1be02..9a414ecd 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -7,8 +7,6 @@ edition = "2021" [dependencies] domain = { path = "../domain" } -entity = { path = "../entity" } -entity_api = { path = "../entity_api" } service = { path = "../service" } axum = "0.7.7" diff --git a/web/src/controller/action_controller.rs b/web/src/controller/action_controller.rs index f23b9f7b..035c9b2b 100644 --- a/web/src/controller/action_controller.rs +++ b/web/src/controller/action_controller.rs @@ -7,8 +7,8 @@ use axum::extract::{Path, Query, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use entity::{actions::Model, Id}; -use entity_api::action as ActionApi; +use domain::{action as ActionApi, actions::Model, Id}; + use serde_json::json; use service::config::ApiVersion; use std::collections::HashMap; @@ -20,9 +20,9 @@ use log::*; post, path = "/actions", params(ApiVersion), - request_body = entity::actions::Model, + request_body = actions::Model, responses( - (status = 201, description = "Successfully Created a New Action", body = [entity::actions::Model]), + (status = 201, description = "Successfully Created a New Action", body = [actions::Model]), (status= 422, description = "Unprocessable Entity"), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") @@ -55,7 +55,7 @@ pub async fn create( ("id" = String, Path, description = "Action id to retrieve") ), responses( - (status = 200, description = "Successfully retrieved a specific Action by its id", body = [entity::notes::Model]), + (status = 200, description = "Successfully retrieved a specific Action by its id", body = [notes::Model]), (status = 401, description = "Unauthorized"), (status = 404, description = "Action not found"), (status = 405, description = "Method not allowed") @@ -83,9 +83,9 @@ pub async fn read( ApiVersion, ("id" = Id, Path, description = "Id of action to update"), ), - request_body = entity::actions::Model, + request_body = actions::Model, responses( - (status = 200, description = "Successfully Updated Action", body = [entity::actions::Model]), + (status = 200, description = "Successfully Updated Action", body = [actions::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -119,9 +119,9 @@ pub async fn update( ("id" = Id, Path, description = "Id of action to update"), ("value" = Option, Query, description = "Status value to update"), ), - request_body = entity::actions::Model, + request_body = actions::Model, responses( - (status = 200, description = "Successfully Updated Action", body = [entity::actions::Model]), + (status = 200, description = "Successfully Updated Action", body = [actions::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -154,7 +154,7 @@ pub async fn update_status( ("coaching_session_id" = Option, Query, description = "Filter by coaching_session_id") ), responses( - (status = 200, description = "Successfully retrieved all Actions", body = [entity::actions::Model]), + (status = 200, description = "Successfully retrieved all Actions", body = [actions::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), diff --git a/web/src/controller/agreement_controller.rs b/web/src/controller/agreement_controller.rs index e231c263..95ae0d82 100644 --- a/web/src/controller/agreement_controller.rs +++ b/web/src/controller/agreement_controller.rs @@ -8,8 +8,8 @@ use axum::extract::{Path, Query, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use domain::agreement as AgreementApi; -use entity::{agreements::Model, Id}; +use domain::{agreement as AgreementApi, agreements::Model, Id}; + use serde_json::json; use service::config::ApiVersion; @@ -20,9 +20,9 @@ use log::*; post, path = "/agreements", params(ApiVersion), - request_body = entity::agreements::Model, + request_body = agreements::Model, responses( - (status = 201, description = "Successfully Created a New Agreement", body = [entity::agreements::Model]), + (status = 201, description = "Successfully Created a New Agreement", body = [agreements::Model]), (status= 422, description = "Unprocessable Entity"), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") @@ -61,7 +61,7 @@ pub async fn create( ("id" = String, Path, description = "Agreement id to retrieve") ), responses( - (status = 200, description = "Successfully retrieved a specific Agreement by its id", body = [entity::notes::Model]), + (status = 200, description = "Successfully retrieved a specific Agreement by its id", body = [notes::Model]), (status = 401, description = "Unauthorized"), (status = 404, description = "Agreement not found"), (status = 405, description = "Method not allowed") @@ -89,9 +89,9 @@ pub async fn read( ApiVersion, ("id" = Id, Path, description = "Id of agreement to update"), ), - request_body = entity::agreements::Model, + request_body = agreements::Model, responses( - (status = 200, description = "Successfully Updated Agreement", body = [entity::agreements::Model]), + (status = 200, description = "Successfully Updated Agreement", body = [agreements::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -125,7 +125,7 @@ pub async fn update( ("coaching_session_id" = Id, Query, description = "Filter by coaching_session_id") ), responses( - (status = 200, description = "Successfully retrieved all Agreements", body = [entity::agreements::Model]), + (status = 200, description = "Successfully retrieved all Agreements", body = [agreements::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), diff --git a/web/src/controller/coaching_session_controller.rs b/web/src/controller/coaching_session_controller.rs index 09cc757c..23a47523 100644 --- a/web/src/controller/coaching_session_controller.rs +++ b/web/src/controller/coaching_session_controller.rs @@ -7,8 +7,7 @@ use axum::extract::{Query, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use domain::coaching_session as CoachingSessionApi; -use entity::coaching_sessions::Model; +use domain::{coaching_session as CoachingSessionApi, coaching_sessions::Model}; use service::config::ApiVersion; use std::collections::HashMap; @@ -24,7 +23,7 @@ use log::*; ("to_date" = Option, Query, description = "Filter by to_date") ), responses( - (status = 200, description = "Successfully retrieved all Coaching Sessions", body = [entity::coaching_sessions::Model]), + (status = 200, description = "Successfully retrieved all Coaching Sessions", body = [coaching_sessions::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -58,9 +57,9 @@ pub async fn index( post, path = "/coaching_sessions", params(ApiVersion), - request_body = entity::coaching_sessions::Model, + request_body = coaching_sessions::Model, responses( - (status = 201, description = "Successfully Created a new Coaching Session", body = [entity::coaching_sessions::Model]), + (status = 201, description = "Successfully Created a new Coaching Session", body = [coaching_sessions::Model]), (status= 422, description = "Unprocessable Entity"), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") diff --git a/web/src/controller/note_controller.rs b/web/src/controller/note_controller.rs index 1fe30014..45faca69 100644 --- a/web/src/controller/note_controller.rs +++ b/web/src/controller/note_controller.rs @@ -7,8 +7,7 @@ use axum::extract::{Path, Query, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use entity::{notes, Id}; -use entity_api::note as NoteApi; +use domain::{note as NoteApi, notes, Id}; use service::config::ApiVersion; use std::collections::HashMap; @@ -19,9 +18,9 @@ use log::*; post, path = "/notes", params(ApiVersion), - request_body = entity::notes::Model, + request_body = notes::Model, responses( - (status = 201, description = "Successfully Created a New Note", body = [entity::notes::Model]), + (status = 201, description = "Successfully Created a New Note", body = [notes::Model]), (status= 422, description = "Unprocessable Entity"), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") @@ -55,9 +54,9 @@ pub async fn create( ApiVersion, ("id" = Id, Path, description = "Id of note to update"), ), - request_body = entity::notes::Model, + request_body = notes::Model, responses( - (status = 200, description = "Successfully Updated Note", body = [entity::notes::Model]), + (status = 200, description = "Successfully Updated Note", body = [notes::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -91,7 +90,7 @@ pub async fn update( ("coaching_session_id" = Option, Query, description = "Filter by coaching_session_id") ), responses( - (status = 200, description = "Successfully retrieved all Notes", body = [entity::coaching_sessions::Model]), + (status = 200, description = "Successfully retrieved all Notes", body = [coaching_sessions::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -126,7 +125,7 @@ pub async fn index( ("id" = String, Path, description = "Note id to retrieve") ), responses( - (status = 200, description = "Successfully retrieved a certain Note by its id", body = [entity::notes::Model]), + (status = 200, description = "Successfully retrieved a certain Note by its id", body = [notes::Model]), (status = 401, description = "Unauthorized"), (status = 404, description = "Note not found"), (status = 405, description = "Method not allowed") diff --git a/web/src/controller/organization/coaching_relationship_controller.rs b/web/src/controller/organization/coaching_relationship_controller.rs index 0f639da0..2cd2cf54 100644 --- a/web/src/controller/organization/coaching_relationship_controller.rs +++ b/web/src/controller/organization/coaching_relationship_controller.rs @@ -7,8 +7,8 @@ use axum::extract::{Path, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use entity::{coaching_relationships, Id}; -use entity_api::coaching_relationship as CoachingRelationshipApi; +use domain::coaching_relationship::CoachingRelationshipWithUserNames; +use domain::{coaching_relationship as CoachingRelationshipApi, coaching_relationships, Id}; use service::config::ApiVersion; use log::*; @@ -22,7 +22,7 @@ use log::*; ), request_body = entity::coaching_relationships::Model, responses( - (status = 200, description = "Successfully created a new Coaching Relationship", body = [entity::coaching_relationships::Model]), + (status = 200, description = "Successfully created a new Coaching Relationship", body = [coaching_relationships::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -65,7 +65,7 @@ pub async fn create( ("relationship_id" = String, Path, description = "CoachingRelationship id to retrieve") ), responses( - (status = 200, description = "Successfully retrieved a certain CoachingRelationship by its id", body = [entity::coaching_relationships::Model]), + (status = 200, description = "Successfully retrieved a certain CoachingRelationship by its id", body = [coaching_relationships::Model]), (status = 401, description = "Unauthorized"), (status = 404, description = "CoachingRelationship not found"), (status = 405, description = "Method not allowed") @@ -84,7 +84,7 @@ pub async fn read( ) -> Result { debug!("GET CoachingRelationship by id: {}", relationship_id); - let relationship: Option = + let relationship: Option = CoachingRelationshipApi::get_relationship_with_user_names( app_state.db_conn_ref(), relationship_id, @@ -103,7 +103,7 @@ pub async fn read( ("organization_id" = Id, Path, description = "Organization id to retrieve CoachingRelationships") ), responses( - (status = 200, description = "Successfully retrieved all CoachingRelationships", body = [entity::coaching_relationships::Model]), + (status = 200, description = "Successfully retrieved all CoachingRelationships", body = [coaching_relationships::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), diff --git a/web/src/controller/organization_controller.rs b/web/src/controller/organization_controller.rs index 36a8b504..38e14bab 100644 --- a/web/src/controller/organization_controller.rs +++ b/web/src/controller/organization_controller.rs @@ -7,8 +7,7 @@ use axum::extract::{Path, Query, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use entity::{organizations, Id}; -use entity_api::organization as OrganizationApi; +use domain::{organization as OrganizationApi, organizations, Id}; use serde_json::json; use service::config::ApiVersion; @@ -25,7 +24,7 @@ use log::debug; ("user_id" = Option, Query, description = "Filter by user_id") ), responses( - (status = 200, description = "Successfully retrieved all Organizations", body = [entity::organizations::Model]), + (status = 200, description = "Successfully retrieved all Organizations", body = [organizations::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -61,7 +60,7 @@ pub async fn index( ("id" = String, Path, description = "Organization id to retrieve") ), responses( - (status = 200, description = "Successfully retrieved a certain Organization by its id", body = [entity::organizations::Model]), + (status = 200, description = "Successfully retrieved a certain Organization by its id", body = [organizations::Model]), (status = 401, description = "Unauthorized"), (status = 404, description = "Organization not found"), (status = 405, description = "Method not allowed") @@ -89,9 +88,9 @@ pub async fn read( params( ApiVersion, ), - request_body = entity::organizations::Model, + request_body = organizations::Model, responses( - (status = 200, description = "Successfully created a new Organization", body = [entity::organizations::Model]), + (status = 200, description = "Successfully created a new Organization", body = [organizations::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), @@ -125,9 +124,9 @@ pub async fn create( ApiVersion, ("id" = i32, Path, description = "Organization id to update") ), - request_body = entity::organizations::Model, + request_body = organizations::Model, responses( - (status = 200, description = "Successfully updated a certain Organization by its id", body = [entity::organizations::Model]), + (status = 200, description = "Successfully updated a certain Organization by its id", body = [organizations::Model]), (status = 401, description = "Unauthorized"), (status = 404, description = "Organization not found"), (status = 405, description = "Method not allowed") diff --git a/web/src/controller/overarching_goal_controller.rs b/web/src/controller/overarching_goal_controller.rs index 3da30e61..f74ef7c4 100644 --- a/web/src/controller/overarching_goal_controller.rs +++ b/web/src/controller/overarching_goal_controller.rs @@ -7,8 +7,8 @@ use axum::extract::{Path, Query, State}; use axum::http::StatusCode; use axum::response::IntoResponse; use axum::Json; -use entity::{overarching_goals::Model, Id}; -use entity_api::overarching_goal as OverarchingGoalApi; +use domain::overarching_goal as OverarchingGoalApi; +use domain::{overarching_goals::Model, Id}; use service::config::ApiVersion; use std::collections::HashMap; diff --git a/web/src/controller/user_controller.rs b/web/src/controller/user_controller.rs index 42e82283..40faf1b0 100644 --- a/web/src/controller/user_controller.rs +++ b/web/src/controller/user_controller.rs @@ -1,8 +1,7 @@ use crate::{controller::ApiResponse, extractors::compare_api_version::CompareApiVersion}; use crate::{AppState, Error}; use axum::{extract::State, http::StatusCode, response::IntoResponse, Json}; -use entity::users; -use entity_api::user as UserApi; +use domain::{user as UserApi, users}; use service::config::ApiVersion; use log::*; @@ -14,9 +13,9 @@ use log::*; params( ApiVersion, ), - request_body = entity::users::Model, + request_body = users::Model, responses( - (status = 200, description = "Successfully created a new User", body = [entity::users::Model]), + (status = 200, description = "Successfully created a new User", body = [users::Model]), (status = 401, description = "Unauthorized"), (status = 405, description = "Method not allowed") ), diff --git a/web/src/controller/user_session_controller.rs b/web/src/controller/user_session_controller.rs index c03575ab..a14ffc95 100644 --- a/web/src/controller/user_session_controller.rs +++ b/web/src/controller/user_session_controller.rs @@ -1,6 +1,6 @@ use crate::controller::ApiResponse; use axum::{http::StatusCode, response::IntoResponse, Form, Json}; -use entity_api::user as UserApi; +use domain::{AuthSession, Credentials}; use log::*; use serde::Deserialize; use serde_json::json; @@ -12,7 +12,7 @@ pub struct NextUrl { _next: Option, } -pub async fn protected(auth_session: UserApi::AuthSession) -> impl IntoResponse { +pub async fn protected(auth_session: AuthSession) -> impl IntoResponse { debug!("UserSessionController::protected()"); match auth_session.user { @@ -37,7 +37,7 @@ pub async fn protected(auth_session: UserApi::AuthSession) -> impl IntoResponse #[utoipa::path( post, path = "/login", - request_body(content = entity_api::user::Credentials, content_type = "application/x-www-form-urlencoded"), + request_body(content = Credentials, content_type = "application/x-www-form-urlencoded"), responses( (status = 200, description = "Logs in and returns session authentication cookie"), (status = 401, description = "Unauthorized"), @@ -48,8 +48,8 @@ pub async fn protected(auth_session: UserApi::AuthSession) -> impl IntoResponse ) )] pub async fn login( - mut auth_session: UserApi::AuthSession, - Form(creds): Form, + mut auth_session: AuthSession, + Form(creds): Form, ) -> impl IntoResponse { debug!("UserSessionController::login()"); let user = match auth_session.authenticate(creds.clone()).await { @@ -94,7 +94,7 @@ security( ("cookie_auth" = []) ) )] -pub async fn logout(mut auth_session: UserApi::AuthSession) -> impl IntoResponse { +pub async fn logout(mut auth_session: domain::AuthSession) -> impl IntoResponse { debug!("UserSessionController::logout()"); match auth_session.logout().await { Ok(_) => StatusCode::OK.into_response(), diff --git a/web/src/extractors/authenticated_user.rs b/web/src/extractors/authenticated_user.rs index 7a58d284..dd8644b1 100644 --- a/web/src/extractors/authenticated_user.rs +++ b/web/src/extractors/authenticated_user.rs @@ -5,8 +5,7 @@ use axum::{ http::{request::Parts, StatusCode}, }; use axum_login::AuthSession; -use entity::users; -use entity_api::user; +use domain::users; pub(crate) struct AuthenticatedUser(pub users::Model); @@ -20,7 +19,7 @@ where // This extractor wraps the AuthSession extractor from axum_login. It extracts the user from the AuthSession and returns an AuthenticatedUser. // If the user is authenticated. If the user is not authenticated, it returns an Unauthorized error. async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { - let session: user::AuthSession = AuthSession::from_request_parts(parts, state) + let session: domain::AuthSession = AuthSession::from_request_parts(parts, state) .await .map_err(|(status, msg)| (status, msg.to_string()))?; match session.user { diff --git a/web/src/lib.rs b/web/src/lib.rs index 58f1cfd7..3ad1bdbe 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -6,7 +6,7 @@ use axum_login::{ tower_sessions::{Expiry, SessionManagerLayer}, AuthManagerLayerBuilder, }; -use entity_api::user::Backend; +use domain::Backend; use tower_sessions::session_store::ExpiredDeletion; use tower_sessions_sqlx_store::PostgresStore; diff --git a/web/src/params/agreement.rs b/web/src/params/agreement.rs index 81ac04ce..44f34040 100644 --- a/web/src/params/agreement.rs +++ b/web/src/params/agreement.rs @@ -1,4 +1,4 @@ -use entity::Id; +use domain::Id; use sea_orm::Value; use serde::Deserialize; use utoipa::IntoParams; diff --git a/web/src/params/jwt.rs b/web/src/params/jwt.rs index c117beac..84d78e79 100644 --- a/web/src/params/jwt.rs +++ b/web/src/params/jwt.rs @@ -1,4 +1,4 @@ -use entity::Id; +use domain::Id; use serde::Deserialize; use utoipa::IntoParams; diff --git a/web/src/protect/actions.rs b/web/src/protect/actions.rs index 057d9229..07979e4b 100644 --- a/web/src/protect/actions.rs +++ b/web/src/protect/actions.rs @@ -5,8 +5,7 @@ use axum::{ middleware::Next, response::IntoResponse, }; -use entity::Id; -use entity_api::coaching_session; +use domain::{coaching_session, Id}; use log::*; use serde::Deserialize; diff --git a/web/src/protect/agreements.rs b/web/src/protect/agreements.rs index 29483c68..f2edacb5 100644 --- a/web/src/protect/agreements.rs +++ b/web/src/protect/agreements.rs @@ -6,7 +6,7 @@ use axum::{ middleware::Next, response::IntoResponse, }; -use entity_api::coaching_session; +use domain::coaching_session; use log::*; /// Checks that coaching relationship record associated with the coaching session diff --git a/web/src/protect/coaching_relationships.rs b/web/src/protect/coaching_relationships.rs index 57d078ac..1536ac0e 100644 --- a/web/src/protect/coaching_relationships.rs +++ b/web/src/protect/coaching_relationships.rs @@ -6,8 +6,7 @@ use axum::{ response::IntoResponse, }; -use entity::Id; -use entity_api::organization; +use domain::{organization, Id}; use std::collections::HashSet; /// Checks that the organization record referenced by `organization_id` diff --git a/web/src/protect/coaching_sessions.rs b/web/src/protect/coaching_sessions.rs index 85ef5fdc..0eaa1331 100644 --- a/web/src/protect/coaching_sessions.rs +++ b/web/src/protect/coaching_sessions.rs @@ -7,8 +7,7 @@ use axum::{ }; use serde::Deserialize; -use entity::Id; -use entity_api::coaching_relationship; +use domain::{coaching_relationship, Id}; #[derive(Debug, Deserialize)] pub(crate) struct QueryParams { diff --git a/web/src/protect/jwt.rs b/web/src/protect/jwt.rs index 3e3624bd..241ea268 100644 --- a/web/src/protect/jwt.rs +++ b/web/src/protect/jwt.rs @@ -7,7 +7,7 @@ use axum::{ middleware::Next, response::IntoResponse, }; -use entity_api::coaching_session; +use domain::coaching_session; use log::*; /// Checks that coaching relationship record associated with the coaching session diff --git a/web/src/protect/notes.rs b/web/src/protect/notes.rs index 057d9229..07979e4b 100644 --- a/web/src/protect/notes.rs +++ b/web/src/protect/notes.rs @@ -5,8 +5,7 @@ use axum::{ middleware::Next, response::IntoResponse, }; -use entity::Id; -use entity_api::coaching_session; +use domain::{coaching_session, Id}; use log::*; use serde::Deserialize; diff --git a/web/src/protect/overarching_goals.rs b/web/src/protect/overarching_goals.rs index 057d9229..07979e4b 100644 --- a/web/src/protect/overarching_goals.rs +++ b/web/src/protect/overarching_goals.rs @@ -5,8 +5,7 @@ use axum::{ middleware::Next, response::IntoResponse, }; -use entity::Id; -use entity_api::coaching_session; +use domain::{coaching_session, Id}; use log::*; use serde::Deserialize; diff --git a/web/src/router.rs b/web/src/router.rs index 2a29db8a..6c8d7cbe 100644 --- a/web/src/router.rs +++ b/web/src/router.rs @@ -5,7 +5,7 @@ use axum::{ Router, }; use axum_login::login_required; -use entity_api::user::Backend; +use domain::Backend; use tower_http::services::ServeDir; use crate::controller::{ @@ -67,15 +67,15 @@ use self::organization::coaching_relationship_controller; ), components( schemas( - entity::actions::Model, - entity::agreements::Model, - entity::coaching_sessions::Model, - entity::coaching_relationships::Model, - entity::notes::Model, - entity::organizations::Model, - entity::overarching_goals::Model, - entity::users::Model, - entity_api::user::Credentials, + domain::actions::Model, + domain::agreements::Model, + domain::coaching_sessions::Model, + domain::coaching_relationships::Model, + domain::notes::Model, + domain::organizations::Model, + domain::overarching_goals::Model, + domain::users::Model, + domain::Credentials, ) ), modifiers(&SecurityAddon), @@ -326,8 +326,8 @@ mod organization_endpoints_tests { AuthManagerLayerBuilder, }; use chrono::Utc; - use entity::{organizations, users, Id}; - use entity_api::user::Backend; + use domain::Backend; + use domain::{organizations, users, Id}; use log::{debug, LevelFilter}; use password_auth::generate_hash; use reqwest::{header, header::HeaderValue, Url};