Initial commit
Publish Docker image / publish (push) Failing after 2m1s
CI / tests (push) Has been cancelled

This commit is contained in:
2024-08-10 09:33:15 +00:00
commit 2013d04cf7
34 changed files with 5958 additions and 0 deletions
+46
View File
@@ -0,0 +1,46 @@
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/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/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();
}