Skip to content
Clone
5f84089
38 lines 1.2 KB Rust
use ::session::Session;
use export::http::{Json, State};
use export::rest::AppResponseData;
use time::OffsetDateTime;
use crate::errors::{ApiError, GitApiError};
use crate::handler;
use crate::service::GitService;
use crate::service::content::SignatureDto;
#[derive(Debug, Clone, serde::Deserialize, utoipa::ToSchema)]
pub struct CallerSignatureBody {
#[serde(default)]
pub when: Option<String>,
}
#[utoipa::path(
post,
path = "/repos/utils/commit-signature",
tag = "content",
description = "返回当前用户用于创建 Git 提交的姓名、邮箱和服务器时间。",
request_body = CallerSignatureBody,
responses(
(status = 200, description = "caller git signature", body = AppResponseData<SignatureDto>)
)
)]
pub async fn caller_signature(
State(service): State<GitService>,
session: Session,
Json(_body): Json<CallerSignatureBody>,
) -> Result<AppResponseData<SignatureDto>, ApiError> {
let caller = handler::ensure_caller(&session)?;
let out = service
.caller_signature(caller, OffsetDateTime::now_utc())
.await
.map_err(GitApiError::from)?;
Ok(AppResponseData::ok(out))
}