use actix_web::{HttpResponse, web}; use serde::Deserialize; use utoipa::IntoParams; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::users::UserDevice; use crate::service::AppService; use crate::session::Session; #[derive(Debug, Deserialize, IntoParams)] pub struct QueryParams { pub limit: Option, pub offset: Option, } /// List user devices /// /// Returns all registered devices for the authenticated user. /// Devices are sorted by last seen time (most recent first). /// Includes device metadata such as name, type, fingerprint, and trust status. /// Requires authentication. #[utoipa::path( get, path = "/api/v1/user/security/devices", tag = "User", operation_id = "userListDevices", params(QueryParams), responses( (status = 200, description = "Devices listed successfully. Returns array of device objects with metadata.", body = ApiResponse>), (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_devices( service: web::Data, session: Session, query: web::Query, ) -> Result { let devices = service .user .user_devices( &session, query.limit.unwrap_or(50), query.offset.unwrap_or(0), ) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(devices))) }