Add a command client to libjirac
This commit is contained in:
parent
6102233bc5
commit
8a7c989f48
16 changed files with 253 additions and 60 deletions
5
crates/libjirac/src/client/commands.rs
Normal file
5
crates/libjirac/src/client/commands.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
mod search_command;
|
||||
mod self_command;
|
||||
|
||||
pub use search_command::SearchCommand;
|
||||
pub use self_command::SelfCommand;
|
35
crates/libjirac/src/client/commands/search_command.rs
Normal file
35
crates/libjirac/src/client/commands/search_command.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
use crate::client::{JiraCommand, JiraRequestType};
|
||||
use crate::entities::search::JiraSearchResponse;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SearchCommand {
|
||||
jql: String,
|
||||
}
|
||||
|
||||
impl SearchCommand {
|
||||
pub fn new(jql: &str) -> Self {
|
||||
Self {
|
||||
jql: jql.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl JiraCommand for SearchCommand {
|
||||
type TResponse = JiraSearchResponse;
|
||||
type TPayload = ();
|
||||
const REQUEST_TYPE: JiraRequestType = JiraRequestType::Read;
|
||||
|
||||
fn endpoint(&self) -> String {
|
||||
"/rest/api/2/search".to_string()
|
||||
}
|
||||
|
||||
fn request_body(&self) -> Option<&Self::TPayload> {
|
||||
None
|
||||
}
|
||||
|
||||
fn query_params(&self) -> Option<Vec<(String, String)>> {
|
||||
let params = vec![("jql".to_string(), self.jql.clone())];
|
||||
|
||||
Some(params)
|
||||
}
|
||||
}
|
46
crates/libjirac/src/client/commands/self_command.rs
Normal file
46
crates/libjirac/src/client/commands/self_command.rs
Normal file
|
@ -0,0 +1,46 @@
|
|||
use crate::client::{JiraCommand, JiraRequestType};
|
||||
use serde::de::DeserializeOwned;
|
||||
use url::Url;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SelfCommand<T>
|
||||
where
|
||||
T: DeserializeOwned + Clone,
|
||||
{
|
||||
href: String,
|
||||
_marker: std::marker::PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> SelfCommand<T>
|
||||
where
|
||||
T: DeserializeOwned + Clone,
|
||||
{
|
||||
pub fn new(href: &str) -> Self {
|
||||
Self {
|
||||
href: href.to_owned(),
|
||||
_marker: std::marker::PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> JiraCommand for SelfCommand<T>
|
||||
where
|
||||
T: DeserializeOwned + Clone,
|
||||
{
|
||||
type TResponse = T;
|
||||
type TPayload = ();
|
||||
const REQUEST_TYPE: JiraRequestType = JiraRequestType::Read;
|
||||
|
||||
fn endpoint(&self) -> String {
|
||||
let url = Url::parse(&self.href).unwrap();
|
||||
url.path().to_string()
|
||||
}
|
||||
|
||||
fn request_body(&self) -> Option<&Self::TPayload> {
|
||||
None
|
||||
}
|
||||
|
||||
fn query_params(&self) -> Option<Vec<(String, String)>> {
|
||||
None
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue