diff --git a/como_api/src/router.rs b/como_api/src/router.rs index 89d4574..b210bc7 100644 --- a/como_api/src/router.rs +++ b/como_api/src/router.rs @@ -12,7 +12,7 @@ use crate::controllers::graphql::GraphQLController; pub struct Api; impl Api { - pub async fn new( + pub async fn run_api( port: u32, cors_origin: &str, service_register: ServiceRegister, diff --git a/como_bin/src/error.rs b/como_bin/src/error.rs index bc8201a..f5f37e6 100644 --- a/como_bin/src/error.rs +++ b/como_bin/src/error.rs @@ -1,6 +1,7 @@ use axum::{http::StatusCode, response::IntoResponse, Json}; use serde_json::json; +#[allow(dead_code)] #[derive(Debug)] pub enum AppError { WrongCredentials, diff --git a/como_bin/src/main.rs b/como_bin/src/main.rs index a3739d6..7c74c50 100644 --- a/como_bin/src/main.rs +++ b/como_bin/src/main.rs @@ -29,7 +29,7 @@ async fn main() -> anyhow::Result<()> { let service_register = ServiceRegister::new(pool, config.clone()); - Api::new( + Api::run_api( config.api_port, &config.cors_origin, service_register.clone(), diff --git a/como_domain/src/item/mod.rs b/como_domain/src/item/mod.rs index 26e0a6e..306e545 100644 --- a/como_domain/src/item/mod.rs +++ b/como_domain/src/item/mod.rs @@ -2,7 +2,7 @@ pub mod queries; pub mod requests; pub mod responses; -use async_graphql::{Enum, InputObject, SimpleObject}; +use async_graphql::{Enum, InputObject}; use serde::{Deserialize, Serialize}; use uuid::Uuid; diff --git a/como_gql/src/graphql.rs b/como_gql/src/graphql.rs index 0b6fa6b..aa6b848 100644 --- a/como_gql/src/graphql.rs +++ b/como_gql/src/graphql.rs @@ -4,8 +4,6 @@ use como_domain::{ item::{ queries::{GetItemQuery, GetItemsQuery}, requests::CreateItemDto, - responses::CreatedItemDto, - ItemDto, }, projects::{ queries::{GetProjectQuery, GetProjectsQuery}, diff --git a/como_gql/src/items.rs b/como_gql/src/items.rs index 61f25bc..293b8fb 100644 --- a/como_gql/src/items.rs +++ b/como_gql/src/items.rs @@ -35,19 +35,19 @@ pub struct Item { #[Object] impl Item { pub async fn id(&self, _ctx: &Context<'_>) -> anyhow::Result { - return Ok(self.id); + Ok(self.id) } pub async fn title(&self, _ctx: &Context<'_>) -> anyhow::Result { - return Ok(self.title.clone()); + Ok(self.title.clone()) } pub async fn description(&self, _ctx: &Context<'_>) -> anyhow::Result> { - return Ok(self.description.clone()); + Ok(self.description.clone()) } pub async fn state(&self, _ctx: &Context<'_>) -> anyhow::Result { - return Ok(self.state); + Ok(self.state) } pub async fn project(&self, ctx: &Context<'_>) -> anyhow::Result { diff --git a/como_infrastructure/src/register.rs b/como_infrastructure/src/register.rs index 504dcfb..cf9dc62 100644 --- a/como_infrastructure/src/register.rs +++ b/como_infrastructure/src/register.rs @@ -7,8 +7,7 @@ use crate::{ configs::AppConfig, database::ConnectionPool, services::{ - item_service::{DefaultItemService, MemoryItemService}, - project_service::{DefaultProjectService, MemoryProjectService}, + item_service::MemoryItemService, project_service::MemoryProjectService, user_service::DefaultUserService, }, }; @@ -26,14 +25,14 @@ impl ServiceRegister { let item_service = Arc::new(MemoryItemService::new()) as DynItemService; let project_service = Arc::new(MemoryProjectService::new()) as DynProjectService; - let user_service = Arc::new(DefaultUserService::new(pool.clone())) as DynUserService; + let user_service = Arc::new(DefaultUserService::new(pool)) as DynUserService; info!("services created succesfully"); - return Self { + Self { item_service, user_service, project_service, - }; + } } } diff --git a/como_infrastructure/src/services/item_service.rs b/como_infrastructure/src/services/item_service.rs index c5faf65..4a376f5 100644 --- a/como_infrastructure/src/services/item_service.rs +++ b/como_infrastructure/src/services/item_service.rs @@ -3,6 +3,7 @@ use std::{ sync::{Arc, Mutex}, }; +use anyhow::Context; use axum::async_trait; use como_core::items::ItemService; use como_domain::item::{ @@ -21,6 +22,12 @@ impl DefaultItemService { } } +impl Default for DefaultItemService { + fn default() -> Self { + Self::new() + } +} + #[async_trait] impl ItemService for DefaultItemService { async fn add_item(&self, _item: CreateItemDto) -> anyhow::Result { @@ -48,6 +55,12 @@ impl MemoryItemService { } } +impl Default for MemoryItemService { + fn default() -> Self { + Self::new() + } +} + #[async_trait] impl ItemService for MemoryItemService { async fn add_item(&self, create_item: CreateItemDto) -> anyhow::Result { @@ -71,7 +84,7 @@ impl ItemService for MemoryItemService { if let Ok(item_store) = self.item_store.lock() { let item = item_store .get(&query.item_id.to_string()) - .ok_or(anyhow::anyhow!("could not find item"))?; + .context("could not find item")?; return Ok(item.clone()); } else { Err(anyhow::anyhow!("could not unlock item_store"))