Added system/info endpoint, implement tagging

This commit is contained in:
2025-04-13 09:11:52 -04:00
parent c354ea6d78
commit d5bc4cafb8
17 changed files with 143 additions and 22 deletions

2
api/Cargo.lock generated
View File

@@ -366,7 +366,7 @@ dependencies = [
[[package]]
name = "api"
version = "0.1.1"
version = "0.1.2"
dependencies = [
"actix-cors",
"actix-multipart",

View File

@@ -1,6 +1,6 @@
[package]
name = "api"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["Ben Sherriff <hello@bensherriff.com>"]
repository = "https://github.com/bensherriff/aviation-weather"

View File

@@ -6,11 +6,11 @@ use rand::distr::Alphanumeric;
use rand::prelude::*;
use rand_chacha::ChaCha20Rng;
mod model;
mod auth;
mod routes;
mod session;
pub use model::*;
pub use auth::*;
pub use session::*;
pub use routes::init_routes;

View File

@@ -1,11 +1,11 @@
use actix_web::{post, web, HttpResponse, ResponseError, HttpRequest, put, get};
use crate::{
auth::{verify_hash, Session, SESSION_COOKIE_NAME},
account::{verify_hash, Session, SESSION_COOKIE_NAME},
error::Error,
users::{LoginRequest, RegisterRequest, User, UserResponse},
};
use crate::auth::Auth;
use crate::account::Auth;
use crate::users::UpdateUser;
#[post("/register")]

View File

@@ -3,7 +3,7 @@ use futures_util::stream::StreamExt as _;
use crate::{
airports::Airport,
db::Paged,
auth::{Auth, verify_role},
account::{Auth, verify_role},
AppState,
};
use actix_multipart::Multipart;

View File

@@ -4,15 +4,16 @@ use actix_cors::Cors;
use actix_web::{App, HttpServer, middleware::Logger, web};
use dotenv::from_filename;
use reqwest::Certificate;
use crate::auth::hash;
use crate::account::hash;
use crate::users::{User, ADMIN_ROLE};
mod account;
mod airports;
mod auth;
mod db;
mod error;
mod metars;
mod scheduler;
mod system;
mod users;
#[derive(Debug, Clone)]
@@ -71,7 +72,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let state = AppState { client };
let host = "0.0.0.0";
let port = env::var("API_PORT").unwrap_or("5000".to_string());
let port = "5000";
let server = match HttpServer::new(move || {
let cors = Cors::default()
@@ -88,8 +89,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
web::scope("api")
.configure(airports::init_routes)
.configure(metars::init_routes)
.configure(auth::init_routes)
.configure(users::init_routes),
.configure(account::init_routes)
.configure(users::init_routes)
.configure(system::init_routes),
)
})
.bind(format!("{}:{}", host, port))

31
api/src/system/mod.rs Normal file
View File

@@ -0,0 +1,31 @@
use std::env;
use actix_web::{get, web, HttpResponse};
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct SystemInfo {
version: String,
healthy: bool,
}
#[get("/info")]
async fn info() -> HttpResponse {
let mut healthy = true;
let version = match env::var("API_VERSION") {
Ok(v) => v,
Err(_) => {
healthy = false;
String::from("unknown")
}
};
dbg!(&version);
let info = SystemInfo { version, healthy };
HttpResponse::Ok().json(info)
}
pub fn init_routes(config: &mut web::ServiceConfig) {
config.service(web::scope("/system").service(info));
}

View File

@@ -1,7 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use sqlx::{Postgres, QueryBuilder};
use crate::{auth::hash, error::ApiResult};
use crate::{account::hash, error::ApiResult};
use crate::db;
pub const ADMIN_ROLE: &str = "ADMIN";