pre-metrics
This commit is contained in:
+11
-11
@@ -1,39 +1,39 @@
|
||||
use crate::models::group;
|
||||
use crate::repositories::RepositoryContext;
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, DbErr, EntityTrait, QueryFilter};
|
||||
use crate::repositories::{AnyResult, RepositoryContext};
|
||||
use sea_orm::{ActiveModelTrait, ColumnTrait, EntityTrait, QueryFilter};
|
||||
use std::sync::Arc;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
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()
|
||||
pub async fn get_all_by_server(&self, server_id: Uuid) -> AnyResult<Vec<group::Model>> {
|
||||
Ok(group::Entity::find()
|
||||
.filter(group::Column::ServerId.eq(server_id))
|
||||
.all(&self.context.db)
|
||||
.await
|
||||
.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 get_by_id(&self, id: Uuid) -> AnyResult<Option<group::Model>> {
|
||||
Ok(group::Entity::find_by_id(id).one(&self.context.db).await?)
|
||||
}
|
||||
|
||||
pub async fn create(&self, active: group::ActiveModel) -> Result<group::Model, DbErr> {
|
||||
pub async fn create(&self, active: group::ActiveModel) -> AnyResult<group::Model> {
|
||||
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> {
|
||||
pub async fn update(&self, active: group::ActiveModel) -> AnyResult<group::Model> {
|
||||
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> {
|
||||
pub async fn delete(&self, id: Uuid) -> AnyResult<bool> {
|
||||
let res = group::Entity::delete_by_id(id)
|
||||
.exec(&self.context.db)
|
||||
.await?;
|
||||
|
||||
Reference in New Issue
Block a user