refactor(trello): rename module types as model
This commit is contained in:
parent
74862f278c
commit
4e5e35c1da
13 changed files with 89 additions and 75 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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>) -> String {
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
//
|
||||
use std::collections::HashMap;
|
||||
|
||||
//
|
||||
use derive_more::derive::Display;
|
||||
|
||||
use crate::newtype;
|
||||
|
||||
newtype!(TrelloApiKey, String, Display, "API Key");
|
||||
newtype!(TrelloApiKey, String, Display, PartialOrd, Ord, "API Key");
|
||||
newtype!(
|
||||
TrelloApiSecret,
|
||||
String,
|
||||
Display,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
"API Secret token for Trello"
|
||||
);
|
||||
|
||||
#[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<TrelloAuth<'_>> for HashMap<String, String> {
|
||||
fn from(value: TrelloAuth) -> Self {
|
||||
impl From<&TrelloAuth<'_>> for HashMap<String, String> {
|
||||
fn from(value: &TrelloAuth) -> Self {
|
||||
HashMap::from([(
|
||||
"Authorization".into(),
|
||||
format!(
|
|
@ -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 {
|
8
src/trello/model/list.rs
Normal file
8
src/trello/model/list.rs
Normal 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,
|
||||
}
|
|
@ -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");
|
|
@ -3,52 +3,55 @@ use std::collections::HashMap;
|
|||
|
||||
use crate::{
|
||||
s,
|
||||
trello::types::auth::TrelloAuth,
|
||||
trello::{
|
||||
api::boards::TrelloBoards as _,
|
||||
types::{
|
||||
TrelloBoard, TrelloBoardId, TrelloBoardName, TrelloList, TrelloListId, TrelloListName,
|
||||
},
|
||||
model::{auth::TrelloAuth, board::TrelloBoard, TrelloBoardId, TrelloBoardName},
|
||||
},
|
||||
};
|
||||
|
||||
mod board {
|
||||
mod commands {
|
||||
use super::*;
|
||||
|
||||
mod board {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn list_of_boards_find_by_name_returns_board() {
|
||||
//given
|
||||
let board = TrelloBoard::new(
|
||||
TrelloBoardId::new("2"),
|
||||
TrelloBoardName::new("beta"),
|
||||
vec![],
|
||||
);
|
||||
let board = TrelloBoard {
|
||||
id: TrelloBoardId::new("2"),
|
||||
name: TrelloBoardName::new("beta"),
|
||||
lists: vec![],
|
||||
};
|
||||
let boards = vec![
|
||||
TrelloBoard::new(
|
||||
TrelloBoardId::new("1"),
|
||||
TrelloBoardName::new("alpha"),
|
||||
vec![],
|
||||
),
|
||||
TrelloBoard {
|
||||
id: TrelloBoardId::new("1"),
|
||||
name: TrelloBoardName::new("alpha"),
|
||||
lists: vec![],
|
||||
},
|
||||
board.clone(),
|
||||
TrelloBoard::new(
|
||||
TrelloBoardId::new("3"),
|
||||
TrelloBoardName::new("gamma"),
|
||||
vec![],
|
||||
),
|
||||
TrelloBoard {
|
||||
id: TrelloBoardId::new("3"),
|
||||
name: TrelloBoardName::new("gamma"),
|
||||
lists: vec![],
|
||||
},
|
||||
];
|
||||
|
||||
//when
|
||||
let result = boards.find_by_name(board.name());
|
||||
let result = boards.find_by_name(&board.name);
|
||||
|
||||
//then
|
||||
assert_eq!(result, Some(&board));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trello_auth_into_hashmap() {
|
||||
//given
|
||||
let trello_auth = TrelloAuth {
|
||||
api_key: s!("key").into(),
|
||||
api_secret: s!("token").into(),
|
||||
api_key: &s!("key").into(),
|
||||
api_secret: &s!("token").into(),
|
||||
};
|
||||
|
||||
//when
|
||||
|
|
|
@ -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,
|
||||
}
|
Loading…
Reference in a new issue