File size: 812 Bytes
8c9f41d
 
 
a02919a
 
8c9f41d
 
 
 
 
 
 
 
 
a8c4fcf
 
 
8c9f41d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use deadpool_diesel::postgres::Pool;

use crate::{
    models::{dtos::keyframes::KeyframeDto, states::AppState},
    repositories::keyframes::KeyframeRepository,
};

#[derive(Clone, Copy)]
pub struct KeyframeService<'a> {
    pool: &'a Pool,
}

impl<'a> From<&'a AppState> for KeyframeService<'a> {
    fn from(value: &'a AppState) -> Self {
        Self {
            pool: value.diesel_pool(),
        }
    }
}

impl<'a> KeyframeService<'a> {
    pub const fn pool(&self) -> &'a Pool {
        self.pool
    }
}

impl<'a> KeyframeService<'a> {
    pub async fn find_by_id(&self, id: i64) -> anyhow::Result<Option<KeyframeDto>> {
        let repository = KeyframeRepository::from(self);
        Ok(repository
            .find_by_id_and_join_video(id)
            .await?
            .map(Into::into))
    }
}