mirror of
https://git.dirksys.ovh/dirk/bankserver.git
synced 2025-12-20 02:59:20 +01:00
implement motd endpoint
This commit is contained in:
parent
cc5117ff74
commit
6ffe0843d6
@ -8,6 +8,13 @@ pub use schemas::*;
|
||||
mod error;
|
||||
mod util;
|
||||
pub use error::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
pub use util::*;
|
||||
|
||||
make_schemas!((Credentials); (ApiError, TokenResponse), [account::schemas, chat::schemas, transaction::schemas, user::schemas]);
|
||||
make_schemas!((Credentials); (ApiError, TokenResponse, Motd), [account::schemas, chat::schemas, transaction::schemas, user::schemas]);
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "schemas", derive(schemars::JsonSchema))]
|
||||
pub struct Motd {
|
||||
pub text: String,
|
||||
}
|
||||
|
||||
@ -10,6 +10,18 @@ tags:
|
||||
- name: Transactions
|
||||
- name: Chats
|
||||
paths:
|
||||
/motd:
|
||||
get:
|
||||
operationId: motd
|
||||
responses:
|
||||
200:
|
||||
description: Motd
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/Motd'
|
||||
default:
|
||||
$ref: '#/components/responses/Default'
|
||||
/api/login:
|
||||
post:
|
||||
operationId: login
|
||||
|
||||
@ -105,7 +105,7 @@ impl<'a> Claims<'a> {
|
||||
fn invalid_username_or_password() -> ApiError<'static> {
|
||||
ApiError::new(
|
||||
StatusCode::FORBIDDEN,
|
||||
"invalid_username_or_password",
|
||||
"auth.invalid_credentials",
|
||||
"Invalid username or password",
|
||||
)
|
||||
}
|
||||
|
||||
@ -5,9 +5,10 @@ use axum::{
|
||||
extract::{FromRequest, FromRequestParts, Request},
|
||||
http::{StatusCode, request::Parts},
|
||||
response::IntoResponse,
|
||||
routing::get,
|
||||
};
|
||||
|
||||
use bank_core::{ApiError, make_schemas, pagination::RequestPagination};
|
||||
use bank_core::{ApiError, Motd, make_schemas, pagination::RequestPagination};
|
||||
use jsonwebtoken::{DecodingKey, EncodingKey};
|
||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||
use tracing_error::SpanTrace;
|
||||
@ -269,6 +270,7 @@ pub struct AppState {
|
||||
pub decoding_key: DecodingKey,
|
||||
pub sockets: Arc<Sockets>,
|
||||
pub interop: Option<InteropState>,
|
||||
pub motd: Motd,
|
||||
}
|
||||
|
||||
pub struct InteropState {
|
||||
@ -290,6 +292,7 @@ pub type State = axum::extract::State<Arc<AppState>>;
|
||||
pub fn router() -> Router<Arc<AppState>> {
|
||||
Router::new()
|
||||
.merge(auth::router())
|
||||
.route("/motd", get(motd))
|
||||
.nest("/users", user::router())
|
||||
.nest("/docs", docs::router())
|
||||
.nest("/accounts", account::router())
|
||||
@ -298,6 +301,10 @@ pub fn router() -> Router<Arc<AppState>> {
|
||||
.nest("/socket", socket::router())
|
||||
}
|
||||
|
||||
pub async fn motd(EState(state): State) -> Json<Motd> {
|
||||
Json(state.motd.clone())
|
||||
}
|
||||
|
||||
make_schemas!((); (ApiError, _ValidationErrors), [ bank_core::schemas, transactions::schemas]);
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
||||
@ -13,6 +13,8 @@ pub struct Config {
|
||||
pub jwt_key: String,
|
||||
#[serde(default)]
|
||||
pub interop: Option<InteropConfig>,
|
||||
#[serde(default = "default_motd")]
|
||||
pub motd: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@ -22,6 +24,10 @@ pub struct InteropConfig {
|
||||
pub prefix: String,
|
||||
}
|
||||
|
||||
fn default_motd() -> String {
|
||||
"bankserver-rs".into()
|
||||
}
|
||||
|
||||
fn default_host() -> IpAddr {
|
||||
IpAddr::V6(Ipv6Addr::LOCALHOST)
|
||||
}
|
||||
|
||||
@ -59,6 +59,7 @@ async fn main() {
|
||||
decoding_key,
|
||||
sockets: Arc::new(Sockets::new()),
|
||||
interop,
|
||||
motd: bank_core::Motd { text: config.motd },
|
||||
}));
|
||||
|
||||
let listener = TcpListener::bind(socket_addr).await.unwrap();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user