use axum::{
body::Bytes,
http::{header, HeaderMap, StatusCode},
response::IntoResponse,
};
use super::{write_error_phase, HandlerEngineState, HttpWriteTrace};
use crate::{
engine_types::{AccessTier, ValidatedWorldPath},
http_semantics as hs, Phase, TraceCtx,
};
pub(crate) async fn execute_post<S: HandlerEngineState>(
headers: HeaderMap,
body: Bytes,
tier: impl Into<AccessTier>,
world: ValidatedWorldPath,
state: S,
trace: &TraceCtx,
) -> Phase {
let tier = tier.into();
let outcome = match state
.engine()
.append_traced(
&world,
body,
hs::request_preconditions(&headers),
tier,
&HttpWriteTrace { trace },
)
.await
{
Ok(outcome) => outcome,
Err(err) => return write_error_phase(err),
};
let resp_headers = [(header::ETAG, hs::etag_header(&outcome.etag))];
Phase::CommittedWrite((StatusCode::OK, resp_headers, "").into_response())
}