Skip to content

Commit

Permalink
Merge branch '89-documentation-finalization' of github.com:ECDAR-AAU-…
Browse files Browse the repository at this point in the history
…SW-P5/Ecdar-API into 89-documentation-finalization
  • Loading branch information
Murmeldyret committed Dec 11, 2023
2 parents c8b818c + 8324d0b commit 02f8bc3
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/contexts/context_impls/access_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl AccessContext {

#[async_trait]
impl EntityContextTrait<access::Model> for AccessContext {
/// Used for creating an access::Model entity
/// Used for creating an [`access::Model`] entity
/// # Example
/// ```
/// let access = access::Model {
Expand Down
1 change: 0 additions & 1 deletion src/contexts/context_impls/query_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ impl EntityContextTrait<query::Model> for QueryContext {
.await
}

/// Delete a query entity by id
async fn delete(&self, entity_id: i32) -> Result<query::Model, DbErr> {
let query = self.get_by_id(entity_id).await?;
match query {
Expand Down
2 changes: 1 addition & 1 deletion src/contexts/context_traits/access_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use sea_orm::DbErr;

#[async_trait]
pub trait AccessContextTrait: EntityContextTrait<access::Model> {
/// Searches for an access entity by `User` and `Project` id,
/// Searches for an access entity by `User` and `Project` id,
/// returning [`Some`] if any entity was found, [`None`] otherwise
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
Expand Down
4 changes: 4 additions & 0 deletions src/contexts/context_traits/database_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ use std::sync::Arc;

#[async_trait]
pub trait DatabaseContextTrait: Send + Sync + Debug {
/// Resets the database, usually by truncating all tables, useful for testing on a single database
/// # Errors
/// Errors on failed connection or execution error.
async fn reset(&self) -> Result<Arc<dyn DatabaseContextTrait>, DbErr>;
/// Gets the connection to the database
fn get_connection(&self) -> DatabaseConnection;
}
4 changes: 2 additions & 2 deletions src/contexts/context_traits/entity_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait EntityContextTrait<T>: Send + Sync {
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
/// # Notes
/// Most implementations does not allow the caller to set the primary key manually,
/// Most implementations does not allow the caller to set the primary key manually,
/// if the key is needed, use the returned value to ensure that the correct key is used
async fn create(&self, entity: T) -> Result<T, DbErr>;
/// Searches for an entity by its primary key, returning [`Some`] if an entity is found, [`None`] otherwise
Expand All @@ -25,7 +25,7 @@ pub trait EntityContextTrait<T>: Send + Sync {
/// Updates a given entity. This is usually done by searching by primary key
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
/// # Notes
/// # Notes
/// It is not possible to change the primary key, as it is used to look up the given entity.
async fn update(&self, entity: T) -> Result<T, DbErr>;
/// Searches for an entity by primary key and deletes it
Expand Down
3 changes: 3 additions & 0 deletions src/contexts/context_traits/project_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ use sea_orm::DbErr;

#[async_trait]
pub trait ProjectContextTrait: EntityContextTrait<project::Model> {
/// Returns the projects owned by a given user id
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
async fn get_project_info_by_uid(&self, uid: i32) -> Result<Vec<ProjectInfo>, DbErr>;
}
1 change: 1 addition & 0 deletions src/contexts/context_traits/query_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ use sea_orm::DbErr;

#[async_trait]
pub trait QueryContextTrait: EntityContextTrait<query::Model> {
/// Returns the queries associated with a given project id
async fn get_all_by_project_id(&self, project_id: i32) -> Result<Vec<query::Model>, DbErr>;
}
8 changes: 7 additions & 1 deletion src/contexts/context_traits/session_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ use sea_orm::DbErr;

#[async_trait]
pub trait SessionContextTrait: EntityContextTrait<session::Model> {
/// Searches for a token by `Access` or `Refresh` token,
/// returning [`Some`] if one is found, [`None`] otherwise
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
async fn get_by_token(
&self,
token_type: TokenType,
token: String,
) -> Result<Option<session::Model>, DbErr>;

/// Searches for a token by `Access` or `Refresh` token, deleting and returning it
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
async fn delete_by_token(
&self,
token_type: TokenType,
Expand Down
10 changes: 10 additions & 0 deletions src/contexts/context_traits/user_context_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,17 @@ use sea_orm::DbErr;

#[async_trait]
pub trait UserContextTrait: EntityContextTrait<user::Model> {
/// Searches for a `User` by username, returning [`Some`] if one is found, [`None`] otherwise.
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
/// # Notes
/// Since usernames are unique, it is guaranteed that at most one user with the given username exists.
async fn get_by_username(&self, username: String) -> Result<Option<user::Model>, DbErr>;
/// Searches for a `User` by email address, returning [`Some`] if one is found, [`None`] otherwise.
/// # Errors
/// Errors on failed connection, execution error or constraint violations.
/// # Notes
/// Since email address' are unique, it is guaranteed that at most one user with the given email address exists.
async fn get_by_email(&self, email: String) -> Result<Option<user::Model>, DbErr>;
/// Returns all the user entities with the given ids
/// # Example
Expand Down

0 comments on commit 02f8bc3

Please sign in to comment.