a lot
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::{
|
||||
ActiveValue::{NotSet, Set},
|
||||
entity::prelude::*,
|
||||
sqlx::types::chrono::{self, Utc},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
|
||||
@@ -28,3 +32,42 @@ impl Related<super::stream_key::Entity> for Entity {
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl Model {
|
||||
pub async fn create_stream_session(
|
||||
db: &DatabaseConnection,
|
||||
stream_key_id: i32,
|
||||
started_at: chrono::DateTime<Utc>,
|
||||
) -> Result<Model, DbErr> {
|
||||
ActiveModel {
|
||||
id: NotSet,
|
||||
stream_key_id: Set(stream_key_id),
|
||||
started_at: Set(started_at),
|
||||
..Default::default()
|
||||
}
|
||||
.insert(db)
|
||||
.await
|
||||
}
|
||||
pub async fn get_stream_session(
|
||||
db: &DatabaseConnection,
|
||||
stream_session_id: i32,
|
||||
) -> Result<Model, DbErr> {
|
||||
Entity::find_by_id(stream_session_id)
|
||||
.one(db)
|
||||
.await?
|
||||
.ok_or(DbErr::RecordNotFound(format!(
|
||||
"stream_session {stream_session_id}"
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModel {
|
||||
pub async fn finish_stream_session(
|
||||
mut self,
|
||||
db: &DatabaseConnection,
|
||||
ended_at: chrono::DateTime<Utc>,
|
||||
) -> Result<Model, DbErr> {
|
||||
self.ended_at = Set(Some(ended_at));
|
||||
self.update(db).await
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user