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