pre-metrics

This commit is contained in:
2026-05-15 19:35:06 +02:00
parent 0b441b0759
commit 132057217d
43 changed files with 1170 additions and 170 deletions
+10 -8
View File
@@ -1,31 +1,33 @@
use crate::models::channel;
use crate::repositories::RepositoryContext;
use sea_orm::{ActiveModelTrait, DbErr, EntityTrait};
use crate::repositories::{AnyResult, RepositoryContext};
use sea_orm::{ActiveModelTrait, EntityTrait};
use std::sync::Arc;
#[derive(Clone)]
#[derive(Clone, Debug)]
pub struct ChannelRepository {
pub context: Arc<RepositoryContext>,
}
impl ChannelRepository {
pub async fn get_by_id(&self, id: uuid::Uuid) -> Result<Option<channel::Model>, DbErr> {
channel::Entity::find_by_id(id).one(&self.context.db).await
pub async fn get_by_id(&self, id: uuid::Uuid) -> AnyResult<Option<channel::Model>> {
Ok(channel::Entity::find_by_id(id)
.one(&self.context.db)
.await?)
}
pub async fn update(&self, active: channel::ActiveModel) -> Result<channel::Model, DbErr> {
pub async fn update(&self, active: channel::ActiveModel) -> AnyResult<channel::Model> {
let channel = active.update(&self.context.db).await?;
self.context.events.emit("channel_updated", channel.clone());
Ok(channel)
}
pub async fn create(&self, active: channel::ActiveModel) -> Result<channel::Model, DbErr> {
pub async fn create(&self, active: channel::ActiveModel) -> AnyResult<channel::Model> {
let channel = active.insert(&self.context.db).await?;
self.context.events.emit("channel_created", channel.clone());
Ok(channel)
}
pub async fn delete(&self, id: uuid::Uuid) -> Result<(), DbErr> {
pub async fn delete(&self, id: uuid::Uuid) -> AnyResult<()> {
channel::Entity::delete_by_id(id)
.exec(&self.context.db)
.await?;