This commit is contained in:
2026-05-10 03:16:13 +02:00
parent 5f05108132
commit 0b441b0759
77 changed files with 2100 additions and 71 deletions
+43
View File
@@ -0,0 +1,43 @@
use crate::models::group;
use crate::repositories::RepositoryContext;
use sea_orm::{ActiveModelTrait, ColumnTrait, DbErr, EntityTrait, QueryFilter};
use std::sync::Arc;
use uuid::Uuid;
#[derive(Clone)]
pub struct GroupRepository {
pub context: Arc<RepositoryContext>,
}
impl GroupRepository {
pub async fn get_all_by_server(&self, server_id: Uuid) -> Result<Vec<group::Model>, DbErr> {
group::Entity::find()
.filter(group::Column::ServerId.eq(server_id))
.all(&self.context.db)
.await
}
pub async fn get_by_id(&self, id: Uuid) -> Result<Option<group::Model>, DbErr> {
group::Entity::find_by_id(id).one(&self.context.db).await
}
pub async fn create(&self, active: group::ActiveModel) -> Result<group::Model, DbErr> {
let group = active.insert(&self.context.db).await?;
self.context.events.emit("group_created", group.clone());
Ok(group)
}
pub async fn update(&self, active: group::ActiveModel) -> Result<group::Model, DbErr> {
let group = active.update(&self.context.db).await?;
self.context.events.emit("group_updated", group.clone());
Ok(group)
}
pub async fn delete(&self, id: Uuid) -> Result<bool, DbErr> {
let res = group::Entity::delete_by_id(id)
.exec(&self.context.db)
.await?;
self.context.events.emit("group_deleted", id);
Ok(res.rows_affected > 0)
}
}