gitdataai/libs/api/room/member.rs
ZhenYi 14f6e1e500 feat(core): initialize project with access control and AI integration
- Add gitignore and prettier configuration files for project scaffolding
- Implement room access control service with project member verification
- Create user access key management with CRUD operations and activity logging
- Add accordion UI component for frontend expandable sections
- Implement room AI configuration with list, upsert, and delete operations
- Add AI event types for agent join/leave/status change tracking
- Create streaming AI processing services for mode and react patterns
- Build room AI service with model detection and idempotency handling
- Integrate chat service orchestration for AI message processing
- Add typing indicators and stream cancellation for AI interactions
- Implement mention parsing and context extraction for AI agents
2026-05-03 06:04:31 +08:00

170 lines
5.1 KiB
Rust

use crate::{ApiResponse, error::ApiError};
use actix_web::{HttpResponse, Result, web};
use room::ws_context::WsUserContext;
use service::AppService;
use session::Session;
use uuid::Uuid;
#[utoipa::path(
get,
path = "/api/rooms/{room_id}/participants",
params(
("room_id" = Uuid, Path),
),
responses(
(status = 200, description = "List room participants", body = ApiResponse<room::RoomParticipantListResponse>),
(status = 401, description = "Unauthorized"),
(status = 404, description = "Not found"),
),
tag = "Room"
)]
pub async fn participant_list(
service: web::Data<AppService>,
session: Session,
path: web::Path<Uuid>,
) -> Result<HttpResponse, ApiError> {
let room_id = path.into_inner();
let user_id = session
.user()
.ok_or_else(|| ApiError::from(service::error::AppError::Unauthorized))?;
let ctx = WsUserContext::new(user_id);
let resp = service
.room
.room_participant_list(room_id, &ctx)
.await
.map_err(ApiError::from)?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
post,
path = "/api/rooms/{room_id}/access",
params(
("room_id" = Uuid, Path),
),
request_body = room::RoomAccessGrantRequest,
responses(
(status = 200, description = "Grant room access"),
(status = 401, description = "Unauthorized"),
(status = 403, description = "Forbidden"),
(status = 404, description = "Not found"),
),
tag = "Room"
)]
pub async fn access_grant(
service: web::Data<AppService>,
session: Session,
path: web::Path<Uuid>,
body: web::Json<room::RoomAccessGrantRequest>,
) -> Result<HttpResponse, ApiError> {
let room_id = path.into_inner();
let user_id = session
.user()
.ok_or_else(|| ApiError::from(service::error::AppError::Unauthorized))?;
let ctx = WsUserContext::new(user_id);
service
.room
.room_access_grant(room_id, body.into_inner().user_id, &ctx)
.await
.map_err(ApiError::from)?;
Ok(ApiResponse::ok(true).to_response())
}
#[utoipa::path(
delete,
path = "/api/rooms/{room_id}/access/{user_id}",
params(
("room_id" = Uuid, Path),
("user_id" = Uuid, Path),
),
responses(
(status = 200, description = "Revoke room access"),
(status = 401, description = "Unauthorized"),
(status = 403, description = "Forbidden"),
(status = 404, description = "Not found"),
),
tag = "Room"
)]
pub async fn access_revoke(
service: web::Data<AppService>,
session: Session,
path: web::Path<(Uuid, Uuid)>,
) -> Result<HttpResponse, ApiError> {
let (room_id, target_user_id) = path.into_inner();
let actor_id = session
.user()
.ok_or_else(|| ApiError::from(service::error::AppError::Unauthorized))?;
let ctx = WsUserContext::new(actor_id);
service
.room
.room_access_revoke(room_id, target_user_id, &ctx)
.await
.map_err(ApiError::from)?;
Ok(ApiResponse::ok(true).to_response())
}
#[utoipa::path(
patch,
path = "/api/rooms/{room_id}/state/read-seq",
params(
("room_id" = Uuid, Path),
),
request_body = room::RoomMemberReadSeqRequest,
responses(
(status = 200, description = "Set read sequence", body = ApiResponse<room::RoomUserStateResponse>),
(status = 401, description = "Unauthorized"),
(status = 404, description = "Not found"),
),
tag = "Room"
)]
pub async fn state_set_read_seq(
service: web::Data<AppService>,
session: Session,
path: web::Path<Uuid>,
body: web::Json<room::RoomMemberReadSeqRequest>,
) -> Result<HttpResponse, ApiError> {
let room_id = path.into_inner();
let user_id = session
.user()
.ok_or_else(|| ApiError::from(service::error::AppError::Unauthorized))?;
let ctx = WsUserContext::new(user_id);
let resp = service
.room
.room_user_state_update_read_seq(room_id, body.into_inner().last_read_seq, &ctx)
.await
.map_err(ApiError::from)?;
Ok(ApiResponse::ok(resp).to_response())
}
#[utoipa::path(
patch,
path = "/api/rooms/{room_id}/state/dnd",
params(
("room_id" = Uuid, Path),
),
request_body = room::RoomUserStateUpdateDndRequest,
responses(
(status = 200, description = "Update DND settings", body = ApiResponse<room::RoomUserStateResponse>),
(status = 401, description = "Unauthorized"),
(status = 404, description = "Not found"),
),
tag = "Room"
)]
pub async fn state_update_dnd(
service: web::Data<AppService>,
session: Session,
path: web::Path<Uuid>,
body: web::Json<room::RoomUserStateUpdateDndRequest>,
) -> Result<HttpResponse, ApiError> {
let room_id = path.into_inner();
let user_id = session
.user()
.ok_or_else(|| ApiError::from(service::error::AppError::Unauthorized))?;
let ctx = WsUserContext::new(user_id);
let resp = service
.room
.room_user_state_update_dnd(room_id, body.into_inner(), &ctx)
.await
.map_err(ApiError::from)?;
Ok(ApiResponse::ok(resp).to_response())
}