entertainarr-adapter-http 0.1.0

HTTP adapter for entertainarr
Documentation
use entertainarr_domain::auth::prelude::AuthenticationService;
use entertainarr_domain::media::prelude::MediaService;
use entertainarr_domain::podcast::prelude::PodcastService;
use entertainarr_domain::tvshow::prelude::TvShowService;

use crate::server::handler::client::prelude::ClientService;

pub trait ServerState: Send + Sync + 'static {
    fn authentication_service(&self) -> &impl AuthenticationService;
    fn client_service(&self) -> &impl ClientService;
    fn media_service(&self) -> &impl MediaService;
    fn podcast_service(&self) -> &impl PodcastService;
    fn tvshow_service(&self) -> &impl TvShowService;
}

#[cfg(test)]
pub mod tests {
    use std::sync::Arc;

    use entertainarr_domain::auth::prelude::AuthenticationService;
    use entertainarr_domain::podcast::prelude::PodcastService;

    use crate::server::handler::client::prelude::{ClientService, MockClientService};

    #[derive(Default)]
    pub struct MockServerStateBuilder {
        pub authentication: Option<entertainarr_domain::auth::prelude::MockAuthenticationService>,
        pub podcast: Option<entertainarr_domain::podcast::prelude::MockPodcastService>,
        pub media: Option<entertainarr_domain::media::prelude::MockMediaService>,
        pub tvshow: Option<entertainarr_domain::tvshow::prelude::MockTvShowService>,
    }

    impl MockServerStateBuilder {
        pub fn build(self) -> MockServerState {
            MockServerState {
                authentication: Arc::new(self.authentication.unwrap_or_default()),
                client: MockClientService,
                media: Arc::new(self.media.unwrap_or_default()),
                podcast: Arc::new(self.podcast.unwrap_or_default()),
                tvshow_service: Arc::new(self.tvshow.unwrap_or_default()),
            }
        }

        pub fn authentication(
            mut self,
            item: entertainarr_domain::auth::prelude::MockAuthenticationService,
        ) -> Self {
            self.authentication = Some(item);
            self
        }

        pub fn podcast(
            mut self,
            item: entertainarr_domain::podcast::prelude::MockPodcastService,
        ) -> Self {
            self.podcast = Some(item);
            self
        }

        pub fn tvshow(
            mut self,
            item: entertainarr_domain::tvshow::prelude::MockTvShowService,
        ) -> Self {
            self.tvshow = Some(item);
            self
        }
    }

    #[derive(Clone, Default)]
    pub struct MockServerState {
        pub authentication: Arc<entertainarr_domain::auth::prelude::MockAuthenticationService>,
        pub client: MockClientService,
        pub media: Arc<entertainarr_domain::media::prelude::MockMediaService>,
        pub podcast: Arc<entertainarr_domain::podcast::prelude::MockPodcastService>,
        pub tvshow_service: Arc<entertainarr_domain::tvshow::prelude::MockTvShowService>,
    }

    impl MockServerState {
        pub fn builder() -> MockServerStateBuilder {
            MockServerStateBuilder::default()
        }
    }

    impl super::ServerState for MockServerState {
        fn authentication_service(&self) -> &impl AuthenticationService {
            &self.authentication
        }

        fn client_service(&self) -> &impl ClientService {
            &self.client
        }

        fn media_service(&self) -> &impl entertainarr_domain::media::prelude::MediaService {
            &self.media
        }

        fn podcast_service(&self) -> &impl PodcastService {
            &self.podcast
        }

        fn tvshow_service(&self) -> &impl entertainarr_domain::tvshow::prelude::TvShowService {
            &self.tvshow_service
        }
    }
}