forked from project-openubl/xhandler-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
5723bed
commit 5d030f6
Showing
13 changed files
with
133 additions
and
90 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
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
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
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,5 @@ | ||
#[derive(clap::Args, Debug)] | ||
pub struct Oidc { | ||
#[arg(id = "oidc-auth-server-url", long, env = "OIDC_AUTH-SERVER_URL")] | ||
#[arg(id = "oidc-auth-server-url", long, env = "OIDC_AUTH_SERVER_URL")] | ||
pub auth_server_url: String, | ||
} |
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
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,35 +1,57 @@ | ||
use actix_web::{post, web, HttpResponse, Responder}; | ||
use actix_4_jwt_auth::AuthenticatedUser; | ||
use actix_web::{get, post, web, HttpResponse, Responder}; | ||
|
||
use openubl_api::db::Transactional; | ||
use openubl_entity::project; | ||
use openubl_oidc::UserClaims; | ||
|
||
use crate::server::Error; | ||
use crate::AppState; | ||
|
||
#[utoipa::path( | ||
responses( | ||
(status = 200, description = "Create project"), | ||
), | ||
)] | ||
#[post("projects")] | ||
#[utoipa::path(responses((status = 200, description = "List projects")), )] | ||
#[get("/projects")] | ||
pub async fn list_projects( | ||
state: web::Data<AppState>, | ||
user: AuthenticatedUser<UserClaims>, | ||
) -> Result<impl Responder, Error> { | ||
let projects_ctx = state | ||
.system | ||
.get_projects_by_user_id(&user.claims.user_id(), Transactional::None) | ||
.await | ||
.map_err(Error::System)?; | ||
|
||
Ok(HttpResponse::Ok().json( | ||
projects_ctx | ||
.iter() | ||
.map(|ctx| &ctx.project) | ||
.collect::<Vec<_>>(), | ||
)) | ||
} | ||
|
||
#[utoipa::path(responses((status = 200, description = "Create project")))] | ||
#[post("/projects")] | ||
pub async fn create_project( | ||
state: web::Data<AppState>, | ||
json: web::Json<project::Model>, | ||
user: AuthenticatedUser<UserClaims>, | ||
) -> Result<impl Responder, Error> { | ||
let prev = state | ||
.system | ||
.get_project(&json.name, Transactional::None) | ||
.await?; | ||
.get_projects_by_user_id(&user.claims.user_id(), Transactional::None) | ||
.await | ||
.map_err(Error::System)? | ||
.iter() | ||
.any(|ctx| ctx.project.name == json.name); | ||
|
||
match prev { | ||
None => { | ||
let ctx = state | ||
false => { | ||
let project_ctx = state | ||
.system | ||
.create_project(&json, Transactional::None) | ||
.create_project(&json, &user.claims.sub, Transactional::None) | ||
.await | ||
.map_err(Error::System)?; | ||
Ok(HttpResponse::Ok().json(ctx.project)) | ||
Ok(HttpResponse::Ok().json(project_ctx.project)) | ||
} | ||
Some(_) => Ok(HttpResponse::Conflict().body("Project name already exists")), | ||
true => Ok(HttpResponse::Conflict().body("Another project has the same name")), | ||
} | ||
} |
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
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