Skip to content

Commit

Permalink
remove web dependencies on entity and entity_api
Browse files Browse the repository at this point in the history
  • Loading branch information
calebbourg committed Feb 25, 2025
1 parent d774660 commit d979e40
Show file tree
Hide file tree
Showing 38 changed files with 119 additions and 128 deletions.
3 changes: 0 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion domain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
1 change: 1 addition & 0 deletions domain/src/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use entity_api::action::{create, delete_by_id, find_by, find_by_id, update, update_status};
2 changes: 1 addition & 1 deletion domain/src/agreement.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 4 additions & 0 deletions domain/src/coaching_relationship.rs
Original file line number Diff line number Diff line change
@@ -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,
};
24 changes: 5 additions & 19 deletions domain/src/coaching_session.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -81,21 +85,3 @@ pub async fn create(
})
}
}

pub async fn find_by_id(db: &DatabaseConnection, id: entity::Id) -> Result<Model, Error> {
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<String, String>,
) -> Result<Vec<Model>, Error> {
Ok(coaching_session::find_by(db, params).await?)
}
12 changes: 4 additions & 8 deletions domain/src/jwt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -47,7 +43,7 @@ pub async fn generate_collab_token(
db: &DatabaseConnection,
config: &Config,
coaching_session_id: Id,
) -> Result<Jwt, Error> {
) -> Result<Jwts, Error> {
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(|| {
Expand Down Expand Up @@ -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,
})
Expand Down
15 changes: 14 additions & 1 deletion domain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
//! 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
//! consistent interface for working with query filters within the domain layer, while encapsulating
//! 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;
1 change: 1 addition & 0 deletions domain/src/note.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use entity_api::note::{create, find_by, find_by_id, update};
3 changes: 3 additions & 0 deletions domain/src/organization.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub use entity_api::organization::{
create, delete_by_id, find_all, find_by, find_by_id, find_by_user, update,
};
1 change: 1 addition & 0 deletions domain/src/overarching_goal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use entity_api::overarching_goal::{create, find_by, find_by_id, update, update_status};
1 change: 1 addition & 0 deletions domain/src/user.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub use entity_api::user::{create, find_by_email};
2 changes: 1 addition & 1 deletion entity/src/jwt.rs → entity/src/jwts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
2 changes: 1 addition & 1 deletion entity/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion entity_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions entity_api/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ 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};
use serde::Deserialize;
use std::sync::Arc;
use utoipa::ToSchema;

use crate::user::Entity;

pub async fn create(db: &DatabaseConnection, user_model: Model) -> Result<Model, Error> {
debug!(
"New User Relationship Model to be inserted: {:?}",
Expand Down
2 changes: 0 additions & 2 deletions web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
20 changes: 10 additions & 10 deletions web/src/controller/action_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
),
Expand Down Expand Up @@ -119,9 +119,9 @@ pub async fn update(
("id" = Id, Path, description = "Id of action to update"),
("value" = Option<String>, 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")
),
Expand Down Expand Up @@ -154,7 +154,7 @@ pub async fn update_status(
("coaching_session_id" = Option<Id>, 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")
),
Expand Down
16 changes: 8 additions & 8 deletions web/src/controller/agreement_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
),
Expand Down Expand Up @@ -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")
),
Expand Down
9 changes: 4 additions & 5 deletions web/src/controller/coaching_session_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,7 +23,7 @@ use log::*;
("to_date" = Option<NaiveDate>, 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")
),
Expand Down Expand Up @@ -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")
Expand Down
Loading

0 comments on commit d979e40

Please sign in to comment.