generated from phundrak/rust-poem-openapi-template
aac70e4131
This commit separates the core features of GéJDR from the backend as these will also be used by the bot in the future. This commit also updates the dependencies of the project. It also removes the dependency lettre as well as the mailpit docker service for developers as it appears clearer this project won’t send emails anytime soon. The publication of a docker image is also postponed until later.
47 lines
1.3 KiB
Rust
47 lines
1.3 KiB
Rust
use poem::Result;
|
|
use poem_openapi::{payload::Json, ApiResponse, Object, OpenApi};
|
|
|
|
use crate::settings::Settings;
|
|
|
|
use super::ApiCategory;
|
|
|
|
#[derive(Object, Debug, Clone, serde::Serialize, serde::Deserialize)]
|
|
struct Meta {
|
|
version: String,
|
|
}
|
|
|
|
impl From<poem::web::Data<&Settings>> for Meta {
|
|
fn from(value: poem::web::Data<&Settings>) -> Self {
|
|
let version = value.application.version.clone();
|
|
Self { version }
|
|
}
|
|
}
|
|
|
|
#[derive(ApiResponse)]
|
|
enum VersionResponse {
|
|
#[oai(status = 200)]
|
|
Version(Json<Meta>),
|
|
}
|
|
|
|
pub struct VersionApi;
|
|
|
|
#[OpenApi(prefix_path = "/v1/api/version", tag = "ApiCategory::Version")]
|
|
impl VersionApi {
|
|
#[oai(path = "/", method = "get")]
|
|
async fn version(&self, settings: poem::web::Data<&Settings>) -> Result<VersionResponse> {
|
|
tracing::event!(target: "gege-jdr-backend", tracing::Level::DEBUG, "Accessing version endpoint.");
|
|
Ok(VersionResponse::Version(Json(settings.into())))
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn version_works() {
|
|
let app = crate::get_test_app(None).await;
|
|
let cli = poem::test::TestClient::new(app);
|
|
let resp = cli.get("/v1/api/version").send().await;
|
|
resp.assert_status_is_ok();
|
|
let json = resp.json().await;
|
|
let json_value = json.value();
|
|
json_value.object().get("version").assert_not_null();
|
|
}
|