Init
This commit is contained in:
33
src/repositories/server.rs
Normal file
33
src/repositories/server.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use std::sync::Arc;
|
||||
use sea_orm::{DbErr, EntityTrait, ActiveModelTrait};
|
||||
use crate::models::server;
|
||||
use crate::repositories::RepositoryContext;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ServerRepository {
|
||||
pub context: Arc<RepositoryContext>
|
||||
}
|
||||
|
||||
impl ServerRepository {
|
||||
pub async fn get_by_id(&self, id: uuid::Uuid) -> Result<Option<server::Model>, DbErr> {
|
||||
server::Entity::find_by_id(id).one(&self.context.db).await
|
||||
}
|
||||
|
||||
pub async fn update(&self, active: server::ActiveModel) -> Result<server::Model, DbErr> {
|
||||
let model = active.update(&self.context.db).await?;
|
||||
// plus tard: self.context.events.publish(...)
|
||||
Ok(model)
|
||||
}
|
||||
|
||||
pub async fn create(&self, active: server::ActiveModel) -> Result<server::Model, DbErr> {
|
||||
let model = active.insert(&self.context.db).await?;
|
||||
// plus tard: emit post-save
|
||||
Ok(model)
|
||||
}
|
||||
|
||||
pub async fn delete(&self, id: uuid::Uuid) -> Result<(), DbErr> {
|
||||
server::Entity::delete_by_id(id).exec(&self.context.db).await?;
|
||||
// plus tard: emit post-delete
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user