Skip to content

Commit

Permalink
Merge pull request #51 from LRZ-BADW/project-endpoint
Browse files Browse the repository at this point in the history
Add Rudimentary Project Endpoint to API
  • Loading branch information
gierens authored Sep 18, 2024
2 parents 92525e8 + d7017ef commit 036266d
Show file tree
Hide file tree
Showing 21 changed files with 1,119 additions and 112 deletions.
19 changes: 19 additions & 0 deletions .spellcheck.dic
Original file line number Diff line number Diff line change
@@ -1 +1,20 @@
1
=
MariaDB
OpenStack
ProjectDetailed
Rc
TODO
UUIDv4
Url
UserDetailed
enum
http
is_none
map_err
query_as
serde
skip_serializing_if
structs
thiserror
url
2 changes: 1 addition & 1 deletion .spellcheck.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ${CARGO_MANIFEST_DIR}/.config/spellcheck.toml

# Also take into account developer comments
dev_comments = false
dev_comments = true

# Skip the README.md file as defined in the cargo manifest
skip_readme = false
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ This is the combined changelog of all contained `lrzcc` crates.
- add test crate for shared test helpers and cross-crate testing
- move api/tests/helpers to test crate
- add test/tests with two library e2e tests for hello endpoint
- move endpoint scope creation to respective modules
- add not_found(_error) and default_service
- add rudimentary project endpoint
- add move e2e tests

## [lrzcc-cli-v1.1.1] - 2024-09-15

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# lrzcc
API bindings, CLI application and partial API-backend written in Rust for
LRZ-specific features of the Openstack-based LRZ Compute Cloud,
LRZ-specific features of the Openstack-based LRZ Compute Cloud,
[https://cc.lrz.de](https://cc.lrz.de), first and foremost the budgeting system.

## Crates
Expand Down
14 changes: 14 additions & 0 deletions api/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,17 @@ pub fn bad_request_error(message: &str) -> actix_web::Error {
)
.into()
}

pub fn not_found_error(message: &str) -> actix_web::Error {
InternalError::from_response(
anyhow::anyhow!(message.to_string()),
HttpResponse::BadRequest().json(ErrorResponse {
detail: message.to_string(),
}),
)
.into()
}

pub async fn not_found() -> Result<HttpResponse, actix_web::Error> {
Err(not_found_error("This route does not exist."))
}
17 changes: 14 additions & 3 deletions api/src/routes/hello.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
use crate::authentication::require_admin_user;
use actix_web::middleware::from_fn;
use actix_web::web::ReqData;
use actix_web::HttpResponse;
use actix_web::web::{get, scope};
use actix_web::{HttpResponse, Scope};
use lrzcc_wire::hello::Hello;
use lrzcc_wire::user::{Project, User};

pub fn hello_scope() -> Scope {
scope("/hello").route("", get().to(hello_user)).service(
scope("")
.wrap(from_fn(require_admin_user))
.route("/admin", get().to(hello_admin)),
)
}

#[tracing::instrument(name = "hello_user")]
pub async fn hello_user(
async fn hello_user(
user: ReqData<User>,
project: ReqData<Project>,
) -> Result<HttpResponse, actix_web::Error> {
Expand All @@ -19,7 +30,7 @@ pub async fn hello_user(
}

#[tracing::instrument(name = "hello_admin")]
pub async fn hello_admin(
async fn hello_admin(
user: ReqData<User>,
project: ReqData<Project>,
) -> Result<HttpResponse, actix_web::Error> {
Expand Down
2 changes: 2 additions & 0 deletions api/src/routes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod health_check;
mod hello;
pub mod user;

pub use health_check::*;
pub use hello::*;
pub use user::*;
9 changes: 9 additions & 0 deletions api/src/routes/user/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use actix_web::web::scope;
use actix_web::Scope;

mod project;
use project::projects_scope;

pub fn user_scope() -> Scope {
scope("/user").service(projects_scope())
}
Loading

0 comments on commit 036266d

Please sign in to comment.