diff --git a/src/config.rs b/src/config.rs index c11029b..7890518 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,15 +6,7 @@ use crate::trello::TrelloConfig; use crate::{f, s, Ctx, NAME}; #[derive( - Clone, - Debug, - derive_more::From, - PartialEq, - Eq, - PartialOrd, - Ord, - derive_more::AsRef, - serde::Deserialize, + Clone, Debug, derive_more::From, PartialEq, Eq, derive_more::AsRef, serde::Deserialize, )] pub(crate) struct AppConfig { pub(crate) trello: TrelloConfig, diff --git a/src/trello/api/boards.rs b/src/trello/api/boards.rs index 5ddf1c6..185b606 100644 --- a/src/trello/api/boards.rs +++ b/src/trello/api/boards.rs @@ -1,5 +1,16 @@ // -use crate::trello::types::{board::TrelloBoard, TrelloBoardName}; +use crate::trello::model::board::TrelloBoard; +// use color_eyre::Result; +// use kxio::net::Net; +// +// use crate::{ +// f, +// trello::{ +// model::{TrelloAuth, TrelloBoardId}, +// url, +// }, +// }; +use crate::trello::model::TrelloBoardName; // pub(crate) async fn get_board( // auth: &TrelloAuth, diff --git a/src/trello/api/members.rs b/src/trello/api/members.rs index 8e6571c..3b84b69 100644 --- a/src/trello/api/members.rs +++ b/src/trello/api/members.rs @@ -1,12 +1,11 @@ // use kxio::{net::Net, print::Printer}; -use crate::trello::TrelloConfig; use crate::{ api_result::APIResult, trello::{ - types::{auth::TrelloAuth, board::TrelloBoard}, - url, + model::{auth::TrelloAuth, board::TrelloBoard}, + url, TrelloConfig, }, }; @@ -50,7 +49,7 @@ pub(crate) async fn get_boards_that_member_belongs_to( }; APIResult::new( net.get(url("/members/me/boards?lists=open")) - .headers(auth.into()) + .headers((&auth).into()) .header("Accept", "application/json") .send() .await, diff --git a/src/trello/api/tests/mod.rs b/src/trello/api/tests/mod.rs index 883402f..5c2d72b 100644 --- a/src/trello/api/tests/mod.rs +++ b/src/trello/api/tests/mod.rs @@ -6,7 +6,9 @@ use serde_json::json; use crate::{ s, - trello::{api::members::get_boards_that_member_belongs_to, types::board::TrelloBoard}, + trello::{ + api::members::get_boards_that_member_belongs_to, model::board::TrelloBoard, TrelloConfig, + }, }; mod given; @@ -15,7 +17,6 @@ type TestResult = color_eyre::Result<()>; mod members { use super::*; - use crate::trello::TrelloConfig; #[tokio::test] async fn get_member_boards() -> TestResult { diff --git a/src/trello/client.rs b/src/trello/client.rs index d39c001..f2dd728 100644 --- a/src/trello/client.rs +++ b/src/trello/client.rs @@ -1,6 +1,6 @@ // use crate::api_result::APIResult; -use crate::trello::types::board::TrelloBoard; +use crate::trello::model::board::TrelloBoard; use crate::trello::TrelloConfig; use crate::FullCtx; diff --git a/src/trello/mod.rs b/src/trello/mod.rs index 9a7cac0..3defb10 100644 --- a/src/trello/mod.rs +++ b/src/trello/mod.rs @@ -2,16 +2,23 @@ pub(crate) mod api; pub(crate) mod boards; pub(crate) mod client; -pub(crate) mod types; +pub(crate) mod model; -// #[cfg(test)] -// mod tests; +#[cfg(test)] +mod tests; -use crate::execute::Execute; -use crate::trello::boards::TrelloBoardCommand; -use crate::trello::types::auth::{TrelloApiKey, TrelloApiSecret}; -use crate::trello::types::TrelloBoardName; -use crate::{f, FullCtx}; +use crate::{ + execute::Execute, + f, + trello::{ + boards::TrelloBoardCommand, + model::{ + auth::{TrelloApiKey, TrelloApiSecret}, + TrelloBoardName, + }, + }, + FullCtx, +}; use clap::Parser; pub(crate) fn url(path: impl Into) -> String { @@ -34,7 +41,7 @@ impl Execute for TrelloCommand { } } -#[derive(Clone, Debug, derive_more::From, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)] +#[derive(Clone, Debug, derive_more::From, PartialEq, Eq, serde::Deserialize)] pub struct TrelloConfig { pub(crate) api_key: TrelloApiKey, pub(crate) api_secret: TrelloApiSecret, diff --git a/src/trello/types/auth.rs b/src/trello/model/auth.rs similarity index 82% rename from src/trello/types/auth.rs rename to src/trello/model/auth.rs index 6543c4e..2cae623 100644 --- a/src/trello/types/auth.rs +++ b/src/trello/model/auth.rs @@ -1,6 +1,6 @@ -// use std::collections::HashMap; +// use derive_more::derive::Display; use crate::newtype; @@ -16,12 +16,12 @@ newtype!( ); #[derive(Debug, Clone)] -pub struct TrelloAuth<'cfg> { +pub(crate) struct TrelloAuth<'cfg> { pub(crate) api_key: &'cfg TrelloApiKey, pub(crate) api_secret: &'cfg TrelloApiSecret, } -impl From> for HashMap { - fn from(value: TrelloAuth) -> Self { +impl From<&TrelloAuth<'_>> for HashMap { + fn from(value: &TrelloAuth) -> Self { HashMap::from([( "Authorization".into(), format!( diff --git a/src/trello/types/board.rs b/src/trello/model/board.rs similarity index 66% rename from src/trello/types/board.rs rename to src/trello/model/board.rs index 1b5c8ef..6d70899 100644 --- a/src/trello/types/board.rs +++ b/src/trello/model/board.rs @@ -1,6 +1,6 @@ // -use crate::trello::types::list::TrelloList; -use crate::trello::types::{TrelloBoardId, TrelloBoardName}; +use super::{TrelloBoardId, TrelloBoardName}; +use crate::trello::model::list::TrelloList; #[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)] pub(crate) struct TrelloBoard { diff --git a/src/trello/types/card.rs b/src/trello/model/card.rs similarity index 100% rename from src/trello/types/card.rs rename to src/trello/model/card.rs diff --git a/src/trello/model/list.rs b/src/trello/model/list.rs new file mode 100644 index 0000000..5b6c0d3 --- /dev/null +++ b/src/trello/model/list.rs @@ -0,0 +1,8 @@ +// +use super::{TrelloListId, TrelloListName}; + +#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize)] +pub(crate) struct TrelloList { + pub(crate) id: TrelloListId, + pub(crate) name: TrelloListName, +} diff --git a/src/trello/types/mod.rs b/src/trello/model/mod.rs similarity index 61% rename from src/trello/types/mod.rs rename to src/trello/model/mod.rs index e983aa4..8d9df06 100644 --- a/src/trello/types/mod.rs +++ b/src/trello/model/mod.rs @@ -9,14 +9,7 @@ use derive_more::derive::Display; use crate::newtype; newtype!(TrelloBoardId, String, Display, "Board ID"); -newtype!( - TrelloBoardName, - String, - Display, - PartialOrd, - Ord, - "Board Name" -); +newtype!(TrelloBoardName, String, Display, "Board Name"); newtype!(TrelloListId, String, "List ID"); newtype!( TrelloListName, @@ -26,5 +19,5 @@ newtype!( Ord, "List Name" ); -// newtype!(TrelloCardId, String, Display, "Card ID"); -// newtype!(TrelloCardName, String, Display, "Card Name"); +newtype!(TrelloCardId, String, Display, "Card ID"); +newtype!(TrelloCardName, String, Display, "Card Name"); diff --git a/src/trello/types/new_card.rs b/src/trello/model/new_card.rs similarity index 100% rename from src/trello/types/new_card.rs rename to src/trello/model/new_card.rs diff --git a/src/trello/tests.rs b/src/trello/tests.rs index ba864b4..d235d10 100644 --- a/src/trello/tests.rs +++ b/src/trello/tests.rs @@ -1,146 +1,43 @@ -mod board { - // use crate::trello::{ - // // api::boards::TrelloBoards as _, - // types::{ - // board::TrelloBoard, TrelloBoardId, TrelloBoardName, TrelloListId, TrelloListName, - // }, - // }; +// +use crate::trello::{ + api::boards::TrelloBoards, + api::boards::TrelloBoards as _, + model::{board::TrelloBoard, TrelloBoardId, TrelloBoardName}, +}; - // #[test] - // fn list_of_boards_find_by_name_returns_board() { - // //given - // let board = TrelloBoard::new( - // TrelloBoardId::new("2"), - // TrelloBoardName::new("beta"), - // vec![], - // ); - // let boards = vec![ - // TrelloBoard::new( - // TrelloBoardId::new("1"), - // TrelloBoardName::new("alpha"), - // vec![], - // ), - // board.clone(), - // TrelloBoard::new( - // TrelloBoardId::new("3"), - // TrelloBoardName::new("gamma"), - // vec![], - // ), - // ]; - // - // //when - // let result = boards.find_by_name(board.name()); - // - // //then - // assert_eq!(result, Some(&board)); - // } - mod commands { - mod board { - #[test] - fn name_returns_name() { - //given - let board = TrelloBoard::new( - TrelloBoardId::new("board-id"), - TrelloBoardName::new("board-name"), - vec![], - ); +mod commands { + use super::*; - //when - let result = board.name(); + mod board { + use super::*; - //then - assert_eq!(result, &TrelloBoardName::new("board-name")); - } + #[test] + fn list_of_boards_find_by_name_returns_board() { + //given + let board = TrelloBoard { + id: TrelloBoardId::new("2"), + name: TrelloBoardName::new("beta"), + lists: vec![], + }; + let boards = vec![ + TrelloBoard { + id: TrelloBoardId::new("1"), + name: TrelloBoardName::new("alpha"), + lists: vec![], + }, + board.clone(), + TrelloBoard { + id: TrelloBoardId::new("3"), + name: TrelloBoardName::new("gamma"), + lists: vec![], + }, + ]; - #[test] - fn lists_should_return_lists() { - //given - let lists = vec![TrelloList::new( - TrelloListId::new("list-id"), - TrelloListName::new("list-name"), - )]; - let board = TrelloBoard::new( - TrelloBoardId::new("board-id"), - TrelloBoardName::new("board-name"), - lists.clone(), - ); + //when + let result = boards.find_by_name(&board.name); - //when - let result = board.lists(); - - //then - assert_eq!(result, lists); - } - - #[test] - fn list_of_boards_find_by_name_returns_board() { - //given - let board = TrelloBoard::new( - TrelloBoardId::new("2"), - TrelloBoardName::new("beta"), - vec![], - ); - let boards = vec![TrelloBoard::new( - TrelloBoardId::new("1"), - TrelloBoardName::new("alpha"), - vec![], - )]; - - //when - let result = board.name(); - - //then - assert_eq!(result, &TrelloBoardName::new("board-name")); - } - - #[test] - fn lists_should_return_lists() { - //given - let lists = vec![TrelloList::new( - TrelloListId::new("list-id"), - TrelloListName::new("list-name"), - )]; - let board = TrelloBoard::new( - TrelloBoardId::new("board-id"), - TrelloBoardName::new("board-name"), - lists.clone(), - ); - - //when - let result = board.lists(); - - //then - assert_eq!(result, lists); - } - - #[test] - fn list_of_boards_find_by_name_returns_board() { - //given - let board = TrelloBoard::new( - TrelloBoardId::new("2"), - TrelloBoardName::new("beta"), - vec![], - ); - let boards = vec![ - TrelloBoard::new( - TrelloBoardId::new("1"), - TrelloBoardName::new("alpha"), - vec![], - ), - board.clone(), - TrelloBoard::new( - TrelloBoardId::new("3"), - TrelloBoardName::new("gamma"), - vec![], - ), - ]; - - //when - let result = boards.find_by_name(board.name()); - - //then - assert_eq!(result, Some(&board)); - } + //then + assert_eq!(result, Some(&board)); } } } diff --git a/src/trello/types/list.rs b/src/trello/types/list.rs deleted file mode 100644 index aeebf93..0000000 --- a/src/trello/types/list.rs +++ /dev/null @@ -1,10 +0,0 @@ -// -use derive_more::derive::Constructor; - -use crate::trello::types::{TrelloListId, TrelloListName}; - -#[derive(Debug, Clone, PartialEq, Eq, serde::Deserialize, Constructor)] -pub(crate) struct TrelloList { - pub(crate) id: TrelloListId, - pub(crate) name: TrelloListName, -}