bda1ef251a
calling this v0.4.0
36 lines
1017 B
Rust
36 lines
1017 B
Rust
use crate::error::ApiResult;
|
|
use crate::model::space::{Space, SpaceDto};
|
|
use crate::model::space::Channel;
|
|
use crate::repo::{SpaceRepo, ChannelRepo};
|
|
use rocket::serde::json::Json;
|
|
use rocket::State;
|
|
use std::sync::Arc;
|
|
use crate::api::auth::Session;
|
|
use crate::svc::chat_svc::ChatService;
|
|
|
|
#[get("/spaces")]
|
|
pub async fn list_spaces(
|
|
space_repo: &State<Arc<dyn SpaceRepo>>
|
|
) -> ApiResult<Json<Vec<Space>>> {
|
|
let spaces = space_repo.get_all().await?;
|
|
Ok(Json(spaces))
|
|
}
|
|
|
|
#[get("/spaces/<space_id>/channels")]
|
|
pub async fn list_channels(
|
|
space_id: i64,
|
|
channel_repo: &State<Arc<dyn ChannelRepo>>
|
|
) -> ApiResult<Json<Vec<Channel>>> {
|
|
let channels = channel_repo.get_by_space_id(space_id).await?;
|
|
Ok(Json(channels))
|
|
}
|
|
|
|
#[get("/accessible_channels")]
|
|
pub async fn get_accessible_channels(
|
|
session: Session,
|
|
svc: &State<ChatService>
|
|
) -> ApiResult<Json<Vec<SpaceDto>>> {
|
|
let space = svc.get_accessible_channels(session.uid).await?;
|
|
println!("{:?}", space);
|
|
Ok(Json(space))
|
|
} |