-
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.
Orca: applications listing apis (#91)
- Loading branch information
1 parent
64cc002
commit a931251
Showing
13 changed files
with
158 additions
and
20 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,5 @@ | ||
ALTER TABLE registration_requests | ||
ALTER COLUMN registration_local SET NOT NULL; | ||
|
||
-- Fix typo | ||
ALTER VIEW registration_requests_procession RENAME TO registration_requests_processing; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,20 +1,73 @@ | ||
use chrono::{DateTime, Utc}; | ||
use rocket::serde::json::Json; | ||
use rocket::{Route, State}; | ||
use serde::Serialize; | ||
|
||
use super::Response; | ||
use crate::api::Response; | ||
use crate::data::{Id, RegistrationRequest}; | ||
use crate::db::DbPool; | ||
use crate::server::keycloak::{JwtToken, Keycloak}; | ||
use crate::server::keycloak::{JwtToken, Keycloak, Role}; | ||
|
||
#[get("/test", format = "json")] | ||
async fn test_api<'r>( | ||
_db_pool: &State<DbPool>, | ||
mod query; | ||
|
||
#[derive(Debug, Serialize, sqlx::FromRow)] | ||
pub struct UnverifiedSummary { | ||
id: Id<RegistrationRequest>, | ||
email: Option<String>, | ||
first_name: Option<String>, | ||
last_name: Option<String>, | ||
phone_number: Option<String>, | ||
city: Option<String>, | ||
company_name: Option<String>, | ||
registration_local: String, | ||
created_at: DateTime<Utc>, | ||
verification_sent_at: Option<DateTime<Utc>>, | ||
} | ||
|
||
#[get("/unverified")] | ||
async fn list_unverified<'r>( | ||
db_pool: &State<DbPool>, | ||
keycloak: &State<Keycloak>, | ||
token: JwtToken<'r>, | ||
) -> Response<Json<Vec<UnverifiedSummary>>> { | ||
keycloak.require_role(token, Role::ListApplications)?; | ||
|
||
let summaries = query::get_unverified_summaries() | ||
.fetch_all(db_pool.inner()) | ||
.await?; | ||
|
||
Ok(Json(summaries)) | ||
} | ||
|
||
#[derive(Debug, Serialize, sqlx::FromRow)] | ||
pub struct ProcessingSummary { | ||
id: Id<RegistrationRequest>, | ||
email: Option<String>, | ||
first_name: Option<String>, | ||
last_name: Option<String>, | ||
phone_number: Option<String>, | ||
city: Option<String>, | ||
company_name: Option<String>, | ||
registration_local: String, | ||
created_at: DateTime<Utc>, | ||
confirmed_at: DateTime<Utc>, | ||
} | ||
|
||
#[get("/processing")] | ||
async fn list_processing<'r>( | ||
db_pool: &State<DbPool>, | ||
keycloak: &State<Keycloak>, | ||
token: JwtToken<'r>, | ||
) -> Response<String> { | ||
let res = keycloak.inner().decode_jwt(token); | ||
) -> Response<Json<Vec<ProcessingSummary>>> { | ||
keycloak.require_role(token, Role::ListApplications)?; | ||
|
||
let summaries = query::get_processing_summaries() | ||
.fetch_all(db_pool.inner()) | ||
.await?; | ||
|
||
Ok(format!("{:?}", res)) | ||
Ok(Json(summaries)) | ||
} | ||
|
||
pub fn routes() -> Vec<Route> { | ||
routes![test_api] | ||
routes![list_unverified, list_processing] | ||
} |
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,23 @@ | ||
use crate::db::QueryAs; | ||
|
||
use super::{ProcessingSummary, UnverifiedSummary}; | ||
|
||
pub fn get_unverified_summaries<'a>() -> QueryAs<'a, UnverifiedSummary> { | ||
sqlx::query_as( | ||
" | ||
SELECT id, email, first_name, last_name, phone_number, city, company_name, registration_local, created_at, verification_sent_at | ||
FROM registration_requests_unverified | ||
ORDER BY created_at DESC | ||
", | ||
) | ||
} | ||
|
||
pub fn get_processing_summaries<'a>() -> QueryAs<'a, ProcessingSummary> { | ||
sqlx::query_as( | ||
" | ||
SELECT id, email, first_name, last_name, phone_number, city, company_name, registration_local, created_at, confirmed_at | ||
FROM registration_requests_processing | ||
ORDER BY confirmed_at DESC | ||
", | ||
) | ||
} |
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