Add a command client to libjirac

This commit is contained in:
Daan Boerlage 2025-01-21 23:43:35 +01:00
parent 6102233bc5
commit 8a7c989f48
Signed by: daan
GPG key ID: FCE070E1E4956606
16 changed files with 253 additions and 60 deletions

View file

@ -0,0 +1,5 @@
mod search_command;
mod self_command;
pub use search_command::SearchCommand;
pub use self_command::SelfCommand;

View 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)
}
}

View 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
}
}