Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Shuttle Deploy

on:
push:
branches:
- master
workflow_dispatch:

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: shuttle-hq/deploy-action@main
with:
deploy-key: ${{ secrets.SHUTTLE_API_KEY }}
name: "root"
14 changes: 14 additions & 0 deletions .github/workflows/shuttle-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: shuttle-run
on:
pull_request:
branches: [ "master", "develop" ]

jobs:
run-project:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Run shuttle project locally.
uses: ivinjabraham/shuttle-run@v1.1
4 changes: 4 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ serde = { version = "1.0.188", features = ["derive"] }
shuttle-axum = "0.46.0"
shuttle-runtime = "0.46.0"
shuttle-shared-db = { version = "0.46.0", features = ["postgres", "sqlx"] }
sqlx = "0.7.1"
sqlx = { version = "0.7.1", features = ["chrono"] }
tokio = "1.28.2"
7 changes: 4 additions & 3 deletions src/db/attendance.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use chrono::{NaiveDate, NaiveTime};
use sqlx::FromRow;
use async_graphql::SimpleObject;

//Struct for the Attendance table
#[derive(FromRow, SimpleObject)]
pub struct Attendance {
pub id: i32,
pub date: String,
pub timein: String,
pub timeout: String,
pub date: NaiveDate,
pub timein: NaiveTime,
pub timeout: NaiveTime,
}
27 changes: 26 additions & 1 deletion src/graphql/mutations.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use async_graphql::{Context, Object};
use chrono::{NaiveDate, NaiveTime};
use sqlx::PgPool;
use sqlx::types::chrono;
use std::sync::Arc;

use crate::db::member::Member;
use crate::db::{member::Member, attendance::Attendance};

pub struct MutationRoot;

Expand Down Expand Up @@ -34,4 +36,27 @@ impl MutationRoot {

Ok(member)
}

async fn add_attendance(
&self,
ctx: &Context<'_>,
id: i32,
date: NaiveDate,
timein: NaiveTime,
timeout: NaiveTime,
) -> Result<Attendance, sqlx::Error> {
let pool = ctx.data::<Arc<PgPool>>().expect("Pool not found in context");

let attendance = sqlx::query_as::<_, Attendance>(
"INSERT INTO Attendance (id, date, timein, timeout) VALUES ($1, $2, $3, $4) RETURNING *"
)
.bind(id)
.bind(date)
.bind(timein)
.bind(timeout)
.fetch_one(pool.as_ref())
.await?;

Ok(attendance)
}
}
24 changes: 17 additions & 7 deletions src/graphql/query.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use async_graphql::{Context, Object};
use sqlx::PgPool;
use std::sync::Arc;
use chrono::NaiveDate;


use crate::db::{member::Member, attendance::Attendance};

Expand All @@ -16,12 +18,20 @@ impl QueryRoot {
Ok(users)
}

async fn get_attendance(&self, ctx: &Context<'_>, date: String) -> Result<Vec<Attendance>, sqlx::Error> {
let pool = ctx.data::<Arc<PgPool>>().expect("Pool not found in context");
let attendance_list = sqlx::query_as::<_, Attendance>("SELECT id, date, timein, timeout FROM Attendance WHERE date = $1")
.bind(date)
.fetch_all(pool.as_ref())
.await?;
Ok(attendance_list)
async fn get_attendance(
&self,
ctx: &Context<'_>,
date: NaiveDate,
) -> Result<Vec<Attendance>, sqlx::Error> {
let pool = ctx.data::<Arc<PgPool>>().expect("Pool not found in context");

let attendance_list = sqlx::query_as::<_, Attendance>(
"SELECT id, date, timein, timeout FROM Attendance WHERE date = $1"
)
.bind(date)
.fetch_all(pool.as_ref())
.await?;

Ok(attendance_list)
}
}
1 change: 0 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::graphql::mutations::MutationRoot;
use crate::graphql::query::QueryRoot;
use crate::routes::graphiql;


mod db;
mod graphql;
mod routes;
Expand Down