Skip to content

Instantly share code, notes, and snippets.

View mike820324's full-sized avatar
🎯
Focusing

MicroMike mike820324

🎯
Focusing
View GitHub Profile
#[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()
}
})
async fn index(id: Identity) -> String {
// access request identity
if let Some(id) = id.identity() {
format!("Welcome! {}", id)
} else {
"Welcome Anonymous!".to_owned()
}
}
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
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,
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);
}
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
}
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<()> {
query UserStreamOverview($userId: ID!, $pagingOptions: PagingOptions) {
user(username: $userId) {
name
profileStreamConnection(paging: $pagingOptions) {
...commonStreamConnection
__typename
}
__typename
}
}
const graphql_query = `
query UserStreamOverview($userId: ID!, $pagingOptions: PagingOptions) {
user(username: $userId) {
name
profileStreamConnection(paging: $pagingOptions) {
...commonStreamConnection
__typename
}
__typename
}
...
foreach ($posts as $post) {
if (count($post->categories) == 0) {
continue;
}
...
}