acosmi/casehall/
client.rs1use super::types::{
9 BookConsultationRequest, BookConsultationResult, CaseLead, CaseLeadIdResult, CaseMatter,
10 LawyerCredentialMyView, LawyerSummary, LegalConsultation, LegalServiceOrder, LegalServiceSku,
11 ListLawyersParams, SubmitCaseLeadRequest,
12};
13use crate::billing::entitlements::urlencoding;
14use crate::core::client::Client;
15use crate::shared::{Error, Result};
16use tokio_util::sync::CancellationToken;
17
18impl Client {
19 pub async fn list_lawyers(
27 &self,
28 params: Option<&ListLawyersParams>,
29 signal: Option<CancellationToken>,
30 ) -> Result<Vec<LawyerSummary>> {
31 let mut qs: Vec<String> = Vec::new();
32 if let Some(p) = params {
33 if let Some(pa) = &p.practice_area {
34 qs.push(format!("practiceArea={}", urlencoding(pa)));
35 }
36 if let Some(loc) = &p.location {
37 qs.push(format!("location={}", urlencoding(loc)));
38 }
39 if let Some(n) = p.page_no {
40 qs.push(format!("pageNo={n}"));
41 }
42 if let Some(sz) = p.page_size {
43 qs.push(format!("pageSize={sz}"));
44 }
45 }
46 let path = if qs.is_empty() {
47 "/casehall/app/lawyers".to_string()
48 } else {
49 format!("/casehall/app/lawyers?{}", qs.join("&"))
50 };
51 self.commerce_get_list(&path, signal).await
52 }
53
54 pub async fn get_lawyer(
58 &self,
59 id: i64,
60 signal: Option<CancellationToken>,
61 ) -> Result<LawyerSummary> {
62 self.commerce_get_opt::<LawyerSummary>(&format!("/casehall/app/lawyers/{id}"), signal)
63 .await?
64 .ok_or_else(|| Error::other(format!("lawyer {id} not found")))
65 }
66
67 pub async fn submit_case_lead(
75 &self,
76 req: &SubmitCaseLeadRequest,
77 signal: Option<CancellationToken>,
78 ) -> Result<CaseLeadIdResult> {
79 let body = serde_json::to_string(req)
80 .map_err(|e| Error::other(format!("submitCaseLead: marshal: {e}")))?;
81 Ok(self
82 .commerce_post_opt::<CaseLeadIdResult>("/casehall/me/case-leads", Some(&body), signal)
83 .await?
84 .unwrap_or(CaseLeadIdResult { id: 0 }))
85 }
86
87 pub async fn list_my_case_leads(
89 &self,
90 signal: Option<CancellationToken>,
91 ) -> Result<Vec<CaseLead>> {
92 self.commerce_get_list("/casehall/me/case-leads", signal)
93 .await
94 }
95
96 pub async fn get_my_cases(&self, signal: Option<CancellationToken>) -> Result<Vec<CaseMatter>> {
98 self.commerce_get_list("/casehall/me/cases", signal).await
99 }
100
101 pub async fn book_consultation(
109 &self,
110 req: &BookConsultationRequest,
111 signal: Option<CancellationToken>,
112 ) -> Result<BookConsultationResult> {
113 let body = serde_json::to_string(req)
114 .map_err(|e| Error::other(format!("bookConsultation: marshal: {e}")))?;
115 Ok(self
116 .commerce_post_opt::<BookConsultationResult>(
117 "/casehall/me/consultations",
118 Some(&body),
119 signal,
120 )
121 .await?
122 .unwrap_or(BookConsultationResult { consultation_id: 0 }))
123 }
124
125 pub async fn list_my_consultations(
127 &self,
128 signal: Option<CancellationToken>,
129 ) -> Result<Vec<LegalConsultation>> {
130 self.commerce_get_list("/casehall/me/consultations", signal)
131 .await
132 }
133
134 pub async fn list_my_legal_orders(
140 &self,
141 signal: Option<CancellationToken>,
142 ) -> Result<Vec<LegalServiceOrder>> {
143 self.commerce_get_list("/casehall/me/orders", signal).await
144 }
145
146 pub async fn list_legal_skus(
151 &self,
152 region: Option<&str>,
153 signal: Option<CancellationToken>,
154 ) -> Result<Vec<LegalServiceSku>> {
155 let path = match region {
156 Some(r) => format!(
157 "/casehall/app/legal-skus?region={}&benefitType=LEGAL_SERVICE",
158 urlencoding(r)
159 ),
160 None => "/casehall/app/legal-skus?benefitType=LEGAL_SERVICE".to_string(),
161 };
162 self.commerce_get_list(&path, signal).await
163 }
164
165 pub async fn get_my_lawyer_credential_status(
174 &self,
175 signal: Option<CancellationToken>,
176 ) -> Result<Vec<LawyerCredentialMyView>> {
177 self.commerce_get_list("/api/casehall/lawyer-credentials/my", signal)
179 .await
180 }
181}