forked from rust-lang/crates.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathteam.rs
27 lines (25 loc) · 880 Bytes
/
team.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::app::AppState;
use crate::models::Team;
use crate::util::errors::AppResult;
use crate::views::EncodableTeam;
use axum::extract::Path;
use axum_extra::json;
use axum_extra::response::ErasedJson;
use diesel::prelude::*;
use diesel_async::RunQueryDsl;
/// Find team by login.
#[utoipa::path(
get,
path = "/api/v1/teams/{team}",
params(
("team" = String, Path, description = "Name of the team", example = "github:rust-lang:crates-io"),
),
tag = "teams",
responses((status = 200, description = "Successful Response")),
)]
pub async fn find_team(state: AppState, Path(name): Path<String>) -> AppResult<ErasedJson> {
use crate::schema::teams::dsl::{login, teams};
let mut conn = state.db_read().await?;
let team: Team = teams.filter(login.eq(&name)).first(&mut conn).await?;
Ok(json!({ "team": EncodableTeam::from(team) }))
}