gglib_core/ports/
model_repository.rs

1//! Model repository trait definition.
2//!
3//! This port defines the interface for model persistence operations.
4//! Implementations must handle all storage details internally.
5
6use async_trait::async_trait;
7
8use super::RepositoryError;
9use crate::domain::{Model, NewModel};
10
11/// Repository for model persistence operations.
12///
13/// This trait defines CRUD operations for models. Implementations
14/// are responsible for all storage details (SQL, filesystem, etc.).
15///
16/// # Design Rules
17///
18/// - No `sqlx` types in signatures
19/// - CRUD-only: list, get, insert, update, delete
20/// - Tags and search logic belong in `ModelService`, not here
21#[async_trait]
22pub trait ModelRepository: Send + Sync {
23    /// List all models in the repository.
24    async fn list(&self) -> Result<Vec<Model>, RepositoryError>;
25
26    /// Get a model by its database ID.
27    ///
28    /// Returns `Err(RepositoryError::NotFound)` if the model doesn't exist.
29    async fn get_by_id(&self, id: i64) -> Result<Model, RepositoryError>;
30
31    /// Get a model by its name.
32    ///
33    /// Returns `Err(RepositoryError::NotFound)` if no model with that name exists.
34    async fn get_by_name(&self, name: &str) -> Result<Model, RepositoryError>;
35
36    /// Insert a new model into the repository.
37    ///
38    /// Returns the persisted model with its assigned ID.
39    /// Returns `Err(RepositoryError::AlreadyExists)` if a model with the same
40    /// file path already exists.
41    async fn insert(&self, model: &NewModel) -> Result<Model, RepositoryError>;
42
43    /// Update an existing model.
44    ///
45    /// Returns `Err(RepositoryError::NotFound)` if the model doesn't exist.
46    async fn update(&self, model: &Model) -> Result<(), RepositoryError>;
47
48    /// Delete a model by its database ID.
49    ///
50    /// Returns `Err(RepositoryError::NotFound)` if the model doesn't exist.
51    async fn delete(&self, id: i64) -> Result<(), RepositoryError>;
52}