use super::UserPagerQuery; use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use session::Session; #[derive(serde::Serialize, utoipa::ToSchema)] pub struct IsWatchResponse { pub is_watching: bool, } #[utoipa::path( post, path = "/api/projects/{project_name}/watch", params(("project_name" = String, Path)), responses( (status = 200, description = "Watch project"), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Project" )] pub async fn project_watch( service: web::Data, session: Session, path: web::Path, ) -> Result { let project_name = path.into_inner(); service.project_watch(&session, project_name).await?; Ok(ApiResponse::ok(serde_json::json!({ "success": true })).to_response()) } #[utoipa::path( delete, path = "/api/projects/{project_name}/watch", params(("project_name" = String, Path)), responses( (status = 200, description = "Unwatch project"), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Project" )] pub async fn project_unwatch( service: web::Data, session: Session, path: web::Path, ) -> Result { let project_name = path.into_inner(); service.project_unwatch(&session, project_name).await?; Ok(ApiResponse::ok(serde_json::json!({ "success": true })).to_response()) } #[utoipa::path( get, path = "/api/projects/{project_name}/watch", params(("project_name" = String, Path)), responses( (status = 200, description = "Check if user watches project", body = ApiResponse), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Project" )] pub async fn project_is_watch( service: web::Data, session: Session, path: web::Path, ) -> Result { let project_name = path.into_inner(); let resp = service.project_is_watch(&session, project_name).await?; Ok(ApiResponse::ok(IsWatchResponse { is_watching: resp }).to_response()) } #[utoipa::path( get, path = "/api/projects/{project_name}/watches/count", params(("project_name" = String, Path)), responses( (status = 200, description = "Get watch count"), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Project" )] pub async fn project_watches_count( service: web::Data, path: web::Path, ) -> Result { let project_name = path.into_inner(); let resp = service.project_watches(project_name).await?; Ok(ApiResponse::ok(serde_json::json!({ "count": resp })).to_response()) } #[utoipa::path( get, path = "/api/projects/{project_name}/watches/users", params(("project_name" = String, Path)), responses( (status = 200, description = "List users watching project", body = ApiResponse>), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Project" )] pub async fn project_watch_users( service: web::Data, path: web::Path, query: web::Query, ) -> Result { let project_name = path.into_inner(); let resp = service .project_watch_user_list(project_name, query.into_inner().into()) .await?; Ok(ApiResponse::ok(resp).to_response()) }