cima_rs/endpoints/
master_data.rs1use crate::api_client::CimaClient;
2use crate::models::{MasterDataType, MasterItem};
3use anyhow::{Context, Result};
4
5#[derive(Debug, Default, Clone)]
7pub struct MasterDataParams {
8 pub name: Option<String>,
10 pub id: Option<i32>,
12 pub code: Option<String>,
14 pub narcotic: Option<u8>,
16 pub psychotropic: Option<u8>,
18 pub narcotic_or_psychotropic: Option<u8>,
20 pub in_use: Option<u8>,
22 pub page: Option<u32>,
24}
25
26impl MasterDataParams {
27 pub fn new() -> Self {
28 Self::default()
29 }
30
31 pub(crate) fn to_query_params(&self, data_type: MasterDataType) -> Vec<(&str, String)> {
32 let mut params = vec![("maestra", data_type.as_u8().to_string())];
33
34 if let Some(ref v) = self.name {
35 params.push(("nombre", v.clone()));
36 }
37 if let Some(v) = self.id {
38 params.push(("id", v.to_string()));
39 }
40 if let Some(ref v) = self.code {
41 params.push(("codigo", v.clone()));
42 }
43 if let Some(v) = self.narcotic {
44 params.push(("estupefaciente", v.to_string()));
45 }
46 if let Some(v) = self.psychotropic {
47 params.push(("psicotropo", v.to_string()));
48 }
49 if let Some(v) = self.narcotic_or_psychotropic {
50 params.push(("estuopsico", v.to_string()));
51 }
52 if let Some(v) = self.in_use {
53 params.push(("enuso", v.to_string()));
54 }
55 if let Some(v) = self.page {
56 params.push(("pagina", v.to_string()));
57 }
58
59 params
60 }
61}
62
63impl CimaClient {
64 pub async fn get_master_data(
72 &self,
73 data_type: MasterDataType,
74 params: &MasterDataParams,
75 ) -> Result<crate::models::PaginatedResponse<MasterItem>> {
76 let query_params = params.to_query_params(data_type);
77
78 self.get_with_params("maestras", &query_params)
79 .await
80 .context("Failed to get master data")
81 }
82}