-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use diesel::{prelude::*, result::Error::NotFound}; | ||
use rocket::{http::Status, serde::json::Json}; | ||
|
||
use db_models::{App, Build, Team, TeamUser}; | ||
|
||
use crate::{auth::AuthUser, DbConn}; | ||
|
||
#[get("/builds/<build_id>")] | ||
pub async fn build(build_id: i32, user: AuthUser, conn: DbConn) -> Result<Json<Build>, Status> { | ||
conn.run(move |c| { | ||
use db_models::schema::apps::dsl::apps; | ||
use db_models::schema::builds::dsl::{builds, id}; | ||
use db_models::schema::team_users::dsl::{team_users, user_id}; | ||
use db_models::schema::teams::dsl::teams; | ||
|
||
let build = builds | ||
.inner_join(apps.inner_join(teams.inner_join(team_users))) | ||
.filter(user_id.eq(user.id).and(id.eq(build_id))) | ||
.first::<(Build, (App, (Team, TeamUser)))>(c) | ||
.map_err(|e| { | ||
if e == NotFound { | ||
Status::NotFound | ||
} else { | ||
Status::InternalServerError | ||
} | ||
})?; | ||
|
||
Ok(Json(build.0)) | ||
}) | ||
.await | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod apps; | ||
pub mod auth; | ||
pub mod builds; | ||
pub mod dev; | ||
pub mod domains; | ||
pub mod oauth; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters