refactor(trello): rename module types as model

This commit is contained in:
Paul Campbell 2024-12-08 22:31:37 +00:00
parent 8692bb2be4
commit b3ec9f736b
14 changed files with 88 additions and 190 deletions

View file

@ -6,15 +6,7 @@ use crate::trello::TrelloConfig;
use crate::{f, s, Ctx, NAME}; use crate::{f, s, Ctx, NAME};
#[derive( #[derive(
Clone, Clone, Debug, derive_more::From, PartialEq, Eq, derive_more::AsRef, serde::Deserialize,
Debug,
derive_more::From,
PartialEq,
Eq,
PartialOrd,
Ord,
derive_more::AsRef,
serde::Deserialize,
)] )]
pub(crate) struct AppConfig { pub(crate) struct AppConfig {
pub(crate) trello: TrelloConfig, pub(crate) trello: TrelloConfig,

View file

@ -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( // pub(crate) async fn get_board(
// auth: &TrelloAuth, // auth: &TrelloAuth,

View file

@ -1,12 +1,11 @@
// //
use kxio::{net::Net, print::Printer}; use kxio::{net::Net, print::Printer};
use crate::trello::TrelloConfig;
use crate::{ use crate::{
api_result::APIResult, api_result::APIResult,
trello::{ trello::{
types::{auth::TrelloAuth, board::TrelloBoard}, model::{auth::TrelloAuth, board::TrelloBoard},
url, url, TrelloConfig,
}, },
}; };
@ -50,7 +49,7 @@ pub(crate) async fn get_boards_that_member_belongs_to(
}; };
APIResult::new( APIResult::new(
net.get(url("/members/me/boards?lists=open")) net.get(url("/members/me/boards?lists=open"))
.headers(auth.into()) .headers((&auth).into())
.header("Accept", "application/json") .header("Accept", "application/json")
.send() .send()
.await, .await,

View file

@ -6,7 +6,9 @@ use serde_json::json;
use crate::{ use crate::{
s, 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; mod given;
@ -15,7 +17,6 @@ type TestResult = color_eyre::Result<()>;
mod members { mod members {
use super::*; use super::*;
use crate::trello::TrelloConfig;
#[tokio::test] #[tokio::test]
async fn get_member_boards() -> TestResult { async fn get_member_boards() -> TestResult {

View file

@ -1,6 +1,6 @@
// //
use crate::api_result::APIResult; use crate::api_result::APIResult;
use crate::trello::types::board::TrelloBoard; use crate::trello::model::board::TrelloBoard;
use crate::trello::TrelloConfig; use crate::trello::TrelloConfig;
use crate::FullCtx; use crate::FullCtx;

View file

@ -2,16 +2,23 @@
pub(crate) mod api; pub(crate) mod api;
pub(crate) mod boards; pub(crate) mod boards;
pub(crate) mod client; pub(crate) mod client;
pub(crate) mod types; pub(crate) mod model;
// #[cfg(test)] #[cfg(test)]
// mod tests; mod tests;
use crate::execute::Execute; use crate::{
use crate::trello::boards::TrelloBoardCommand; execute::Execute,
use crate::trello::types::auth::{TrelloApiKey, TrelloApiSecret}; f,
use crate::trello::types::TrelloBoardName; trello::{
use crate::{f, FullCtx}; boards::TrelloBoardCommand,
model::{
auth::{TrelloApiKey, TrelloApiSecret},
TrelloBoardName,
},
},
FullCtx,
};
use clap::Parser; use clap::Parser;
pub(crate) fn url(path: impl Into<String>) -> String { pub(crate) fn url(path: impl Into<String>) -> 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 struct TrelloConfig {
pub(crate) api_key: TrelloApiKey, pub(crate) api_key: TrelloApiKey,
pub(crate) api_secret: TrelloApiSecret, pub(crate) api_secret: TrelloApiSecret,

View file

@ -1,6 +1,6 @@
//
use std::collections::HashMap; use std::collections::HashMap;
//
use derive_more::derive::Display; use derive_more::derive::Display;
use crate::newtype; use crate::newtype;
@ -16,12 +16,12 @@ newtype!(
); );
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct TrelloAuth<'cfg> { pub(crate) struct TrelloAuth<'cfg> {
pub(crate) api_key: &'cfg TrelloApiKey, pub(crate) api_key: &'cfg TrelloApiKey,
pub(crate) api_secret: &'cfg TrelloApiSecret, pub(crate) api_secret: &'cfg TrelloApiSecret,
} }
impl From<TrelloAuth<'_>> for HashMap<String, String> { impl From<&TrelloAuth<'_>> for HashMap<String, String> {
fn from(value: TrelloAuth) -> Self { fn from(value: &TrelloAuth) -> Self {
HashMap::from([( HashMap::from([(
"Authorization".into(), "Authorization".into(),
format!( format!(

View file

@ -1,6 +1,6 @@
// //
use crate::trello::types::list::TrelloList; use super::{TrelloBoardId, TrelloBoardName};
use crate::trello::types::{TrelloBoardId, TrelloBoardName}; use crate::trello::model::list::TrelloList;
#[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, serde::Deserialize)]
pub(crate) struct TrelloBoard { pub(crate) struct TrelloBoard {

8
src/trello/model/list.rs Normal file
View file

@ -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,
}

View file

@ -9,14 +9,7 @@ use derive_more::derive::Display;
use crate::newtype; use crate::newtype;
newtype!(TrelloBoardId, String, Display, "Board ID"); newtype!(TrelloBoardId, String, Display, "Board ID");
newtype!( newtype!(TrelloBoardName, String, Display, "Board Name");
TrelloBoardName,
String,
Display,
PartialOrd,
Ord,
"Board Name"
);
newtype!(TrelloListId, String, "List ID"); newtype!(TrelloListId, String, "List ID");
newtype!( newtype!(
TrelloListName, TrelloListName,
@ -26,5 +19,5 @@ newtype!(
Ord, Ord,
"List Name" "List Name"
); );
// newtype!(TrelloCardId, String, Display, "Card ID"); newtype!(TrelloCardId, String, Display, "Card ID");
// newtype!(TrelloCardName, String, Display, "Card Name"); newtype!(TrelloCardName, String, Display, "Card Name");

View file

@ -1,146 +1,43 @@
mod board { //
// use crate::trello::{ use crate::trello::{
// // api::boards::TrelloBoards as _, api::boards::TrelloBoards,
// types::{ api::boards::TrelloBoards as _,
// board::TrelloBoard, TrelloBoardId, TrelloBoardName, TrelloListId, TrelloListName, model::{board::TrelloBoard, TrelloBoardId, TrelloBoardName},
// }, };
// };
// #[test] mod commands {
// fn list_of_boards_find_by_name_returns_board() { use super::*;
// //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![],
);
//when mod board {
let result = board.name(); use super::*;
//then #[test]
assert_eq!(result, &TrelloBoardName::new("board-name")); 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] //when
fn lists_should_return_lists() { let result = boards.find_by_name(&board.name);
//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 //then
let result = board.lists(); assert_eq!(result, Some(&board));
//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));
}
} }
} }
} }

View file

@ -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,
}