46 lines
1.3 KiB
Rust
46 lines
1.3 KiB
Rust
//! Traits describing everything the core needs from a persistence layer.
|
|
//! The implementation lives in `services/database` (sqlx/postgres).
|
|
//!
|
|
//! Thanks to this indirection the business logic never depends on sqlx, and can
|
|
//! be tested against another implementation.
|
|
|
|
use async_trait::async_trait;
|
|
use thiserror::Error;
|
|
|
|
use crate::core::repositories::{
|
|
course_files_repository::CourseFilesRepository, courses_repository::CoursesRepository,
|
|
grades_repository::GradesRepository, tags_repository::TagsRepository,
|
|
tasks_repository::TasksRepository,
|
|
};
|
|
|
|
pub mod course_files_repository;
|
|
pub mod courses_repository;
|
|
pub mod grades_repository;
|
|
pub mod pdf_renderer;
|
|
pub mod storage_repository;
|
|
pub mod tags_repository;
|
|
pub mod tasks_repository;
|
|
pub mod time_tracker;
|
|
|
|
/// Add every new repository trait here so the controller can use it through `db`
|
|
#[async_trait]
|
|
pub trait DatabaseRepository:
|
|
CoursesRepository
|
|
+ TagsRepository
|
|
+ GradesRepository
|
|
+ TasksRepository
|
|
+ CourseFilesRepository
|
|
+ Send
|
|
+ Sync
|
|
{
|
|
}
|
|
|
|
#[derive(Error, Debug)]
|
|
pub enum RepositoryError {
|
|
#[error("not found: {0}")]
|
|
NotFound(String),
|
|
#[error("type conversion error: {0}")]
|
|
TypeConversion(String),
|
|
#[error("Internal error: {0}")]
|
|
Internal(String),
|
|
}
|