Revision control

Copy as Markdown

Other Tools

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// EDITS TO THIS FILE WILL BE OVERWRITTEN
#![doc = "Provides operations to manage the collection of user entities.\n\nAuto-generated from [Microsoft OpenAPI metadata](https://github.com/microsoftgraph/msgraph-metadata/blob/master/openapi/v1.0/openapi.yaml) via `ms_graph_tb_extract openapi.yaml ms_graph_tb/`."]
pub mod calendars;
pub mod mail_folders;
pub mod messages;
use crate::odata::{ExpansionList, Selection};
use crate::types::user::{User, UserExpand, UserSelection};
use crate::{Error, Expand, Operation, OperationBody, Select};
use form_urlencoded::Serializer;
use http::method::Method;
#[derive(Debug)]
struct TemplateExpressions {
endpoint: String,
user_id: String,
}
fn format_path(template_expressions: &TemplateExpressions) -> String {
let TemplateExpressions { endpoint, user_id } = template_expressions;
let endpoint = endpoint.trim_end_matches('/');
format!("{endpoint}/users/{user_id}")
}
#[doc = "Get a user\n\nRetrieve the properties and relationships of user object. This operation returns by default only a subset of the more commonly used properties for each user. These default properties are noted in the Properties section. To get properties that are not returned by default, do a GET operation for the user and specify the properties in a `$select` OData query option. Because the user resource supports extensions, you can also use the GET operation to get custom properties and extension data in a user instance. Customers through Microsoft Entra ID for customers can also use this API operation to retrieve their details.\n\nMore information available via [Microsoft documentation](https://learn.microsoft.com/graph/api/user-get?view=graph-rest-1.0)."]
#[derive(Debug)]
pub struct Get {
template_expressions: TemplateExpressions,
selection: Selection<UserSelection>,
expansion: ExpansionList<UserExpand>,
}
impl Get {
#[must_use]
pub fn new(endpoint: String, user_id: String) -> Self {
Self {
template_expressions: TemplateExpressions { endpoint, user_id },
selection: Selection::default(),
expansion: ExpansionList::default(),
}
}
}
impl Operation for Get {
const METHOD: Method = Method::GET;
type Response = User;
fn build_request(self) -> Result<http::Request<Vec<u8>>, Error> {
let mut params = Serializer::new(String::new());
if let Some((select, selection)) = self.selection.pair() {
params.append_pair(select, &selection);
}
if let Some((expand, expansion)) = self.expansion.pair() {
params.append_pair(expand, &expansion);
}
let params = params.finish();
let path = format_path(&self.template_expressions);
let uri = if params.is_empty() {
path.parse::<http::uri::Uri>().unwrap()
} else {
format!("{path}?{params}")
.parse::<http::uri::Uri>()
.unwrap()
};
let request = http::Request::builder().uri(uri).method(Self::METHOD);
let request = request.body(vec![])?;
Ok(request)
}
}
impl Select for Get {
type Properties = UserSelection;
fn select<P: IntoIterator<Item = Self::Properties>>(&mut self, properties: P) {
self.selection.select(properties);
}
fn extend_selection<P: IntoIterator<Item = Self::Properties>>(&mut self, properties: P) {
self.selection.extend(properties);
}
}
impl Expand for Get {
type Properties = UserExpand;
fn expand<P: IntoIterator<Item = Self::Properties>>(&mut self, properties: P) {
self.expansion.expand(properties);
}
fn extend_expand<P: IntoIterator<Item = Self::Properties>>(&mut self, properties: P) {
self.expansion.extend(properties);
}
}
#[doc = "Update user\n\nUpdate the properties of a user object. To use this API to update an agentUser, specify an @odata.type property with a value of #microsoft.graph.agentUser in the request body.\n\nMore information available via [Microsoft documentation](https://learn.microsoft.com/graph/api/user-update?view=graph-rest-1.0)."]
#[derive(Debug)]
pub struct Patch {
template_expressions: TemplateExpressions,
body: OperationBody<User>,
selection: Selection<UserSelection>,
}
impl Patch {
#[must_use]
pub fn new(endpoint: String, user_id: String, body: OperationBody<User>) -> Self {
Self {
template_expressions: TemplateExpressions { endpoint, user_id },
body,
selection: Selection::default(),
}
}
}
impl Operation for Patch {
const METHOD: Method = Method::PATCH;
type Response = User;
fn build_request(self) -> Result<http::Request<Vec<u8>>, Error> {
let mut params = Serializer::new(String::new());
if let Some((select, selection)) = self.selection.pair() {
params.append_pair(select, &selection);
}
let params = params.finish();
let path = format_path(&self.template_expressions);
let uri = if params.is_empty() {
path.parse::<http::uri::Uri>().unwrap()
} else {
format!("{path}?{params}")
.parse::<http::uri::Uri>()
.unwrap()
};
let (body, content_type) = match self.body {
OperationBody::JSON(body) => {
(serde_json::to_vec(&body)?, String::from("application/json"))
}
OperationBody::Other { body, content_type } => (body, content_type),
};
let request = http::Request::builder()
.uri(uri)
.method(Self::METHOD)
.header("Content-Type", content_type);
let request = request.body(body)?;
Ok(request)
}
}
impl Select for Patch {
type Properties = UserSelection;
fn select<P: IntoIterator<Item = Self::Properties>>(&mut self, properties: P) {
self.selection.select(properties);
}
fn extend_selection<P: IntoIterator<Item = Self::Properties>>(&mut self, properties: P) {
self.selection.extend(properties);
}
}
#[doc = "Delete a user\n\nDelete a user object. When deleted, user resources, including their mailbox and license assignments, are moved to a temporary container and if the user is restored within 30 days, these objects are restored to them. The user is also restored to any groups they were a member of. After 30 days and if not restored, the user object is permanently deleted and their assigned resources freed. To manage the deleted user object, see deletedItems.\n\nMore information available via [Microsoft documentation](https://learn.microsoft.com/graph/api/user-delete?view=graph-rest-1.0)."]
#[derive(Debug)]
pub struct Delete {
template_expressions: TemplateExpressions,
}
impl Delete {
#[must_use]
pub fn new(endpoint: String, user_id: String) -> Self {
Self {
template_expressions: TemplateExpressions { endpoint, user_id },
}
}
}
impl Operation for Delete {
const METHOD: Method = Method::DELETE;
type Response = ();
fn build_request(self) -> Result<http::Request<Vec<u8>>, Error> {
let uri = format_path(&self.template_expressions)
.parse::<http::uri::Uri>()
.unwrap();
let request = http::Request::builder().uri(uri).method(Self::METHOD);
let request = request.body(vec![])?;
Ok(request)
}
}