Skip to content

Commit

Permalink
Progress towards services
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonkle committed Nov 6, 2021
1 parent b8f15bb commit fae337d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[target.'cfg(all())']
rustflags = [
"-Dunsafe_code",
"-Funsafe_code",
"-Dclippy::all",
"-Wclippy::await_holding_lock",
"-Wclippy::char_lit_as_u8",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion apps/api/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::env;

pub async fn init() -> Result<Pool<Postgres>, Error> {
let database_url = env::var("DATABASE_URL")
.unwrap_or_else(|_| "postgresql://caster:caster@localhost:1701/caster".into());
.unwrap_or_else(|_| "postgresql://caster:caster@localhost:1701/caster".to_string());

let pool = PgPoolOptions::new()
.max_connections(5)
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ mod db;
async fn main() -> Result<(), Error> {
dotenv().ok();

let port = env::var("PORT").unwrap_or_else(|_| "3000".into());
let port = env::var("PORT").unwrap_or_else(|_| "3000".to_string());
let addr = format!("http://localhost:{port}", port = port);

let pg_pool = db::init().await?;
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn main() -> Result<(), Error> {

let socket_addr: SocketAddr = match addr.parse() {
Ok(file) => file,
Err(_) => ([0, 0, 0, 0], 3000).into(),
Err(_) => ([0, 0, 0, 0], 3000).to_string(),
};

warp::serve(routes).run(socket_addr).await;
Expand Down
3 changes: 3 additions & 0 deletions libs/shows/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@

/// The GraphQL resolver
pub mod shows_resolver;

/// The Shows entity service
pub mod shows_service;
6 changes: 5 additions & 1 deletion libs/shows/src/shows_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
use async_graphql::{Context, Object};
use sqlx::{Pool, Postgres};

use crate::shows_service::ShowsService;

/// The Query segment owned by the Shows library
#[derive(Default)]
pub struct ShowsQuery;
pub struct ShowsQuery {
service: ShowsService,
}

#[Object]
impl ShowsQuery {
Expand Down
24 changes: 24 additions & 0 deletions libs/shows/src/shows_service.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use sqlx::{Pool, Postgres};

/// The Shows entity servicea
#[derive(Default)]
pub struct ShowsService {
pg_pool: Pool<Postgres>,
}

impl ShowsService {
async fn get(&self, id: &str) -> Result<&str, sqlx::Error> {
let countries = sqlx::query!(
"
SELECT *
FROM \"User\"
WHERE id = $1
",
id
)
.fetch_optional(&self.pg_pool)
.await?;

Ok("Test")
}
}

0 comments on commit fae337d

Please sign in to comment.