use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use session::Session; #[utoipa::path( post, path = "/api/users/me/keys", request_body = service::user::ssh_key::AddSshKeyParams, responses( (status = 200, description = "Add SSH key", body = ApiResponse), (status = 401, description = "Unauthorized"), ), tag = "User" )] pub async fn add_ssh_key( service: web::Data, session: Session, body: web::Json, ) -> Result { let resp = service .user_add_ssh_key(&session, body.into_inner()) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/users/me/keys", responses( (status = 200, description = "List SSH keys", body = ApiResponse), (status = 401, description = "Unauthorized"), ), tag = "User" )] pub async fn list_ssh_keys( service: web::Data, session: Session, ) -> Result { let resp = service.user_list_ssh_keys(&session).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/users/me/keys/{key_id}", params(("key_id" = i64, Path)), responses( (status = 200, description = "Get SSH key", body = ApiResponse), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "User" )] pub async fn get_ssh_key( service: web::Data, session: Session, path: web::Path, ) -> Result { let resp = service .user_get_ssh_key(&session, path.into_inner()) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( patch, path = "/api/users/me/keys/{key_id}", params(("key_id" = i64, Path)), request_body = service::user::ssh_key::UpdateSshKeyParams, responses( (status = 200, description = "Update SSH key", body = ApiResponse), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "User" )] pub async fn update_ssh_key( service: web::Data, session: Session, path: web::Path, body: web::Json, ) -> Result { let resp = service .user_update_ssh_key(&session, path.into_inner(), body.into_inner()) .await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( delete, path = "/api/users/me/keys/{key_id}", params(("key_id" = i64, Path)), responses( (status = 200, description = "Delete SSH key"), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "User" )] pub async fn delete_ssh_key( service: web::Data, session: Session, path: web::Path, ) -> Result { service .user_delete_ssh_key(&session, path.into_inner()) .await?; Ok(ApiResponse::ok(serde_json::json!({ "success": true })).to_response()) }