lexoffice_cli/resources/
contact.rs

1use crate::actions::*;
2use crate::ReturnType;
3use lexoffice::model::contacts::*;
4use lexoffice::model::Contact;
5use lexoffice::Client;
6use lexoffice::Result;
7use structopt::StructOpt;
8
9/// contact endpoint
10#[derive(Debug, StructOpt)]
11pub enum ContactOpt {
12    /// retrieves a paginated list of all contacts
13    List(PaginatedOpt),
14    /// creates new contact and opens it in an editor
15    New(StorableOpt),
16    /// modifies a contact
17    Edit(UpdatableOpt),
18    /// queries a specific contact by its id
19    Get(ByIdOpt),
20}
21
22fn default() -> Contact {
23    Contact::builder()
24        .roles(
25            Roles::builder()
26                .customer(Customer::builder().build())
27                .build(),
28        )
29        .build()
30}
31
32impl ContactOpt {
33    pub async fn exec(&self, client: Client) -> Result<ReturnType<Contact>> {
34        let request = client.request::<Contact>();
35        let result = match self {
36            Self::List(x) => ReturnType::Paged(x.exec(request).await?),
37            Self::Get(x) => ReturnType::Obj(x.exec(request).await?),
38            Self::New(x) => {
39                ReturnType::ResultInfo(x.exec(request, default()).await?)
40            }
41            Self::Edit(x) => ReturnType::ResultInfo(x.exec(request).await?),
42        };
43        Ok(result)
44    }
45}