4028f0d943
- Reordered actix-web imports to standardize import order - Reordered crate module imports to follow alphabetical ordering - Updated function calls to use multi-line formatting for better readability - Standardized blank lines around documentation comments - Applied consistent formatting to response handling methods - Normalized import organization across all repository-related API files - Improved code consistency and maintainability through standardized formatting - Applied formatting updates to all repository endpoint implementations
55 lines
1.8 KiB
Rust
55 lines
1.8 KiB
Rust
use actix_web::{HttpResponse, web};
|
|
use serde::Deserialize;
|
|
use utoipa::IntoParams;
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::service::AppService;
|
|
use crate::service::user::security::UserSessionInfo;
|
|
use crate::session::Session;
|
|
|
|
#[derive(Debug, Deserialize, IntoParams)]
|
|
pub struct QueryParams {
|
|
/// Maximum number of sessions to return (default: 50, max: 100)
|
|
pub limit: Option<i64>,
|
|
/// Number of sessions to skip for pagination (default: 0)
|
|
pub offset: Option<i64>,
|
|
}
|
|
|
|
/// List user sessions
|
|
///
|
|
/// Returns a paginated list of all active and recently-expired sessions for the authenticated user.
|
|
/// Sessions are sorted by last activity (most recent first).
|
|
/// Includes session metadata such as IP address, user agent, and expiration time.
|
|
/// Requires authentication.
|
|
#[utoipa::path(
|
|
get,
|
|
path = "/api/v1/user/security/sessions",
|
|
tag = "User",
|
|
operation_id = "userListSessions",
|
|
params(QueryParams),
|
|
responses(
|
|
(status = 200, description = "Sessions listed successfully. Returns array of session objects with metadata.", body = ApiResponse<Vec<UserSessionInfo>>),
|
|
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error", body = ApiErrorResponse),
|
|
),
|
|
security(
|
|
("session_cookie" = [])
|
|
)
|
|
)]
|
|
pub async fn list_sessions(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
query: web::Query<QueryParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let sessions = service
|
|
.user
|
|
.user_sessions(
|
|
&session,
|
|
query.limit.unwrap_or(50),
|
|
query.offset.unwrap_or(0),
|
|
)
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(sessions)))
|
|
}
|