Skip to main content

gonzalo_proto/
http.rs

1//! JSON DTOs shared by the HTTP/JSON transport (server handlers and the
2//! reqwest client). The gRPC transport carries the same `gonzalo-core` types
3//! as JSON bytes, so both transports agree on serialization.
4
5use gonzalo_core::{Conflict, Record, Revision};
6use serde::{Deserialize, Serialize};
7
8/// Body of `PUT /v1/records/{ns}/{col}/{id}`.
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct PutBody {
11    pub record: Record,
12    pub expected: Option<Revision>,
13}
14
15/// Response of a PUT: mirrors `gonzalo_core::PutResult` on the wire.
16#[derive(Debug, Clone, Serialize, Deserialize)]
17#[serde(tag = "outcome", rename_all = "snake_case")]
18pub enum PutOutcome {
19    Committed { revision: Revision },
20    Conflict { conflict: Box<Conflict> },
21}
22
23/// Body of `DELETE /v1/records/{ns}/{col}/{id}`. The key is addressed by the
24/// URL path; the body carries only the OCC precondition.
25#[derive(Debug, Clone, Default, Serialize, Deserialize)]
26pub struct DeleteBody {
27    pub expected: Option<Revision>,
28}
29
30/// Response of a DELETE: mirrors `gonzalo_core::DeleteResult` on the wire.
31#[derive(Debug, Clone, Serialize, Deserialize)]
32#[serde(tag = "outcome", rename_all = "snake_case")]
33pub enum DeleteOutcome {
34    Deleted,
35    Conflict { conflict: Box<Conflict> },
36}