odoo_api/jsonrpc/request/
web.rs

1use serde::Serialize;
2use std::fmt::Debug;
3
4use super::{JsonRpcId, JsonRpcMethod, JsonRpcParams, JsonRpcRequest, JsonRpcVersion};
5
6/// The container type for an Odoo "Web" request
7///
8/// This type covers (almost) any request whose endpoint starts with `/web`,
9/// for example:
10///  - `/web/session/authenticate`
11///  - `/web/session/destroy`
12///  - `/web/dataset/call`
13///  - And many more
14///
15/// For more info, see [`super::JsonRpcParams`]
16#[derive(Debug, Serialize)]
17#[serde(transparent)]
18pub struct OdooWebContainer<T>
19where
20    T: OdooWebMethod + JsonRpcParams<Container<T> = Self>,
21{
22    pub(crate) inner: T,
23}
24
25/// An Odoo "Web" request type
26pub trait OdooWebMethod
27where
28    Self: Sized + Debug + Serialize + JsonRpcParams<Container<Self> = OdooWebContainer<Self>>,
29    Self::Container<Self>: Debug + Serialize,
30{
31    /// Describe method endpoint (e.g., "/web/session/authenticate")
32    fn endpoint(&self) -> &'static str;
33
34    /// Build `self` into a full [`JsonRpcRequest`]
35    fn _build(self, id: JsonRpcId) -> JsonRpcRequest<Self> {
36        JsonRpcRequest {
37            jsonrpc: JsonRpcVersion::V2,
38            method: JsonRpcMethod::Call,
39            id,
40            params: OdooWebContainer { inner: self },
41        }
42    }
43}