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
#[actix_web::main] | |
async fn main() { | |
let app = App::new() | |
.wrap_fn(|req, srv| { | |
match authn_authz_check(req) { | |
Ok(_) => srv.call(req), | |
Err(_) => HttpResponse.Unauthorized().finish() | |
} | |
}) |
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
async fn index(id: Identity) -> String { | |
// access request identity | |
if let Some(id) = id.identity() { | |
format!("Welcome! {}", id) | |
} else { | |
"Welcome Anonymous!".to_owned() | |
} | |
} |
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
pub async fn authentication_check(db_conn: &DbPool, request: &HttpRequest) -> Result<(Identity, String, i64)> { | |
let token = request.cookie("token").ok_or(Error::msg("Cookie Not Found"))?; | |
let (identity, expireat) = decode_jwt_session(token.value())?; | |
let db_result: Vec<(Uuid, )> = sqlx::query_as( | |
r#" | |
SELECT | |
id | |
FROM | |
blacklisttoken |
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
use num_enum::IntoPrimitive; | |
#[allow(non_camel_case_types)] | |
#[derive(IntoPrimitive)] | |
#[repr(u32)] | |
pub enum ReservationError { | |
OK = 0, | |
// 0x400 | |
ERR_RESERVATION_CREATE_INVALID_TIME_FORMAT = 0x40000001, | |
ERR_RESERVATION_CREATE_TIME_TOO_OLD = 0x40000002, |
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
pub mod consultant; | |
pub mod patient; | |
pub fn register_urls(cfg: &mut actix_web::web::ServiceConfig) { | |
consultant::urls::register_urls(cfg); | |
patient::urls::register_urls(cfg); | |
} |
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
pub type DbPool = sqlx::postgres::PgPool; | |
pub async fn connection_builder() -> Result<DbPool, sqlx::Error> { | |
let connectspec = dotenv::var("DATABASE_URL").unwrap(); | |
sqlx::postgres::PgPool::connect(&connectspec).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
mod app; | |
mod db; | |
use actix_web::middleware::Logger; | |
use actix_web::{App, HttpServer}; | |
use actix_web::web::Data; | |
use env_logger::Env; | |
#[actix_web::main] | |
async fn main() -> std::io::Result<()> { |
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
query UserStreamOverview($userId: ID!, $pagingOptions: PagingOptions) { | |
user(username: $userId) { | |
name | |
profileStreamConnection(paging: $pagingOptions) { | |
...commonStreamConnection | |
__typename | |
} | |
__typename | |
} | |
} |
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
const graphql_query = ` | |
query UserStreamOverview($userId: ID!, $pagingOptions: PagingOptions) { | |
user(username: $userId) { | |
name | |
profileStreamConnection(paging: $pagingOptions) { | |
...commonStreamConnection | |
__typename | |
} | |
__typename | |
} |
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
... | |
foreach ($posts as $post) { | |
if (count($post->categories) == 0) { | |
continue; | |
} | |
... | |
} |
NewerOlder