Skip to content

Commit

Permalink
api: add builds endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhb committed Dec 31, 2021
1 parent a2c662a commit f89fa8a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
25 changes: 25 additions & 0 deletions openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,31 @@ paths:
description: App not found
"401":
description: Unauthorized
/builds/{id}:
get:
summary: Fetch a build
tags:
- Builds
parameters:
- in: path
name: id
schema:
type: integer
required: true
example: 7
responses:
"200":
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/Build"
"500":
description: Internal server error
"404":
description: Build not found
"401":
description: Unauthorized
/domains/{id}/verify:
post:
summary: Attempt to verify a domain
Expand Down
31 changes: 31 additions & 0 deletions src/api/builds.rs
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
}
1 change: 1 addition & 0 deletions src/api/mod.rs
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;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ async fn rocket() -> _ {
api::apps::create,
api::apps::domains,
api::apps::deploy, // experimental - please do not use
api::builds::build,
api::dev::login,
api::domains::create,
api::domains::verify,
Expand Down

0 comments on commit f89fa8a

Please sign in to comment.