added swagget-ui
Continuous integration / Check (push) Successful in 42s
Continuous integration / Rustfmt (push) Successful in 34s
Continuous integration / build (push) Successful in 43s
Continuous integration / build-release (push) Successful in 1m12s

This commit is contained in:
wt committed 2026-02-15 18:04:11 +07:00
1 parent 78ca22e1b7
commit 9f0681563e
17 files changed
+544 -19

No files matched your search

+9
View File
@@ -6,6 +6,15 @@ use sqlx::Row;
use std::sync::Arc;
// УПРОЩЕННАЯ версия получения чатов
#[utoipa::path(
get,
path = "/api/chats",
responses(
(status = 200, description = "List of chat partners", body = Vec<ChatPartner>),
(status = 401, description = "Unauthorized", body = Vec<ChatPartner>)
),
security(("bearerAuth" = []))
)]
pub async fn get_chats_handler(
State(state): State<Arc<state::AppState>>,
headers: axum::http::HeaderMap,
+9
View File
@@ -7,6 +7,15 @@ use chrono::{Duration, Utc};
use sqlx::Row;
use std::sync::Arc;
#[utoipa::path(
post,
path = "/api/login",
request_body = LoginRequest,
responses(
(status = 200, description = "Login successful", body = AuthResponse),
(status = 400, description = "Invalid credentials", body = AuthResponse)
)
)]
pub async fn login_handler(
State(state): State<Arc<state::AppState>>,
Json(payload): Json<model::LoginRequest>,
+10
View File
@@ -6,6 +6,16 @@ use axum::extract::{Json, State};
use std::sync::Arc;
// Mark messages as read endpoint
#[utoipa::path(
post,
path = "/api/mark-read",
request_body = MarkReadRequest,
responses(
(status = 200, description = "Messages marked as read", body = serde_json::Value),
(status = 401, description = "Unauthorized", body = serde_json::Value)
),
security(("bearerAuth" = []))
)]
pub async fn mark_read_handler(
State(state): State<Arc<state::AppState>>,
headers: axum::http::HeaderMap,
+10
View File
@@ -7,6 +7,16 @@ use std::sync::Arc;
use tokio::fs;
// Delete message endpoint
#[utoipa::path(
post,
path = "/api/delete-message",
request_body = DeleteMessageRequest,
responses(
(status = 200, description = "Message deletion result", body = DeleteMessageResponse),
(status = 401, description = "Unauthorized", body = DeleteMessageResponse)
),
security(("bearerAuth" = []))
)]
pub async fn delete_message_handler(
State(state): State<Arc<state::AppState>>,
headers: axum::http::HeaderMap,
+10
View File
@@ -6,6 +6,16 @@ use std::sync::Arc;
use uuid::Uuid;
// Upload avatar endpoint
#[utoipa::path(
post,
path = "/api/upload-avatar",
request_body(content = Vec<u8>, description = "Avatar image file", content_type = "multipart/form-data"),
responses(
(status = 200, description = "Avatar upload result", body = UploadAvatarResponse),
(status = 401, description = "Unauthorized", body = UploadAvatarResponse)
),
security(("bearerAuth" = []))
)]
pub async fn upload_avatar_handler(
State(state): State<Arc<state::AppState>>,
headers: axum::http::HeaderMap,
+9
View File
@@ -5,6 +5,15 @@ use axum::extract::{Json, State};
use sqlx::Row;
use std::sync::Arc;
#[utoipa::path(
get,
path = "/api/profile",
responses(
(status = 200, description = "User profile information", body = UserProfile),
(status = 401, description = "Unauthorized", body = UserProfile)
),
security(("bearerAuth" = []))
)]
pub async fn profile_handler(
State(state): State<Arc<state::AppState>>,
headers: axum::http::HeaderMap,
+9
View File
@@ -6,6 +6,15 @@ use bcrypt::{DEFAULT_COST, hash};
use chrono::{Duration, Utc};
use std::sync::Arc;
#[utoipa::path(
post,
path = "/api/register",
request_body = RegisterRequest,
responses(
(status = 200, description = "Registration successful", body = AuthResponse),
(status = 400, description = "Registration failed", body = AuthResponse)
)
)]
pub async fn register_handler(
State(state): State<Arc<state::AppState>>,
Json(payload): Json<model::RegisterRequest>,
+10
View File
@@ -5,6 +5,16 @@ use sqlx::Row;
use std::sync::Arc;
// New endpoint to search users
#[utoipa::path(
get,
path = "/api/search-users",
params(
("q" = String, Query, description = "Search query string")
),
responses(
(status = 200, description = "List of matching users", body = Vec<ChatPartner>)
)
)]
pub async fn search_users_handler(
State(state): State<Arc<state::AppState>>,
Query(params): Query<model::SearchQuery>,
+9
View File
@@ -5,6 +5,15 @@ use axum::extract::{Json, State};
use sqlx::Row;
use std::sync::Arc;
#[utoipa::path(
post,
path = "/api/validate-token",
request_body = ValidateTokenRequest,
responses(
(status = 200, description = "Token validation result", body = ValidateTokenResponse),
(status = 400, description = "Invalid token", body = ValidateTokenResponse)
)
)]
pub async fn validate_token_handler(
State(state): State<Arc<state::AppState>>,
Json(payload): Json<model::ValidateTokenRequest>,
+10
View File
@@ -12,6 +12,16 @@ use symphonia::core::probe::Hint;
use tokio::fs;
use tokio::io::AsyncWriteExt;
#[utoipa::path(
post,
path = "/api/upload",
request_body(content = Vec<u8>, description = "File to upload", content_type = "multipart/form-data"),
responses(
(status = 200, description = "File upload result", body = serde_json::Value),
(status = 401, description = "Unauthorized", body = serde_json::Value)
),
security(("bearerAuth" = []))
)]
pub async fn upload_file_handler(
State(state): State<Arc<state::AppState>>,
headers: axum::http::HeaderMap,
+21 -1
View File
@@ -12,7 +12,27 @@ use futures_util::{SinkExt, StreamExt};
use std::sync::Arc;
use tokio::sync::mpsc;
// WebSocket handlers
/// WebSocket endpoint for real-time chat messaging
///
/// ## Connection Flow
/// 1. Client connects to `/ws`
/// 2. Client sends authentication message: `{"type": "auth", "token": "your_token"}`
/// 3. Server responds with system message on success or error message on failure
/// 4. After successful authentication, client can send/receive chat messages
///
/// ## Message Types
/// - Authentication: `{"type": "auth", "token": "jwt_token"}`
/// - Chat message: `{"id": "...", "from_user": "...", "to_user": "...", "content": "...", "timestamp": 12345, "message_type": "text"}`
/// - System message: `{"type": "system", "content": "Connected successfully"}`
/// - Error message: `{"type": "error", "content": "Invalid token"}`
#[utoipa::path(
get,
path = "/ws",
responses(
(status = 101, description = "WebSocket upgrade successful")
),
tag = "WebSocket"
)]
pub async fn websocket_handler(
ws: WebSocketUpgrade,
State(state): State<Arc<state::AppState>>,