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), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Room" )] pub async fn participant_list( service: web::Data, session: Session, path: web::Path, ) -> Result { 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, session: Session, path: web::Path, body: web::Json, ) -> Result { 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, session: Session, path: web::Path<(Uuid, Uuid)>, ) -> Result { 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), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Room" )] pub async fn state_set_read_seq( service: web::Data, session: Session, path: web::Path, body: web::Json, ) -> Result { 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), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "Room" )] pub async fn state_update_dnd( service: web::Data, session: Session, path: web::Path, body: web::Json, ) -> Result { 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()) }