Skip to content

Commit

Permalink
rewrite graphql interface
Browse files Browse the repository at this point in the history
This commit changes a lot more things than just the graphql interface.
Also likely introduces a few extra regressions. ¯\_(ツ)_/¯
  • Loading branch information
ivinjabraham committed Jan 17, 2025
1 parent 7762c85 commit 03324a4
Show file tree
Hide file tree
Showing 23 changed files with 586 additions and 473 deletions.
34 changes: 31 additions & 3 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 @@ -21,5 +21,5 @@ serde_json = "1.0"
reqwest = { version = "0.11.27", features = ["json"] }
config = "0.13"
tracing = "0.1.41"
tracing-subscriber = "0.3.19"
tracing-subscriber = { version = "0.3.19", features = ["env-filter"] }
dotenv = "0.15.0"
4 changes: 2 additions & 2 deletions migrations/20250114180047_create_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CREATE TABLE Attendance (
(is_present = FALSE AND time_in IS NULL AND time_out IS NULL)
),
CHECK (is_present = FALSE OR date <= CURRENT_DATE),
CHECK (time_out IS NULL OR time_out > time_in),
CHECK (time_out IS NULL OR time_out >= time_in),
UNIQUE (member_id, date)
);

Expand All @@ -58,7 +58,7 @@ CREATE TABLE AttendanceSummary (
primary key (member_id, year, month)
);

CREATE TABLE StatusUpdateStreaks (
CREATE TABLE StatusUpdateStreak (
member_id INT REFERENCES Member(member_id) ON DELETE CASCADE,
current_streak int NOT NULL DEFAULT 0,
max_streak INT NOT NULL,
Expand Down
6 changes: 3 additions & 3 deletions src/attendance/daily_task.rs → src/daily_task/daily_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use chrono::{Datelike, Local, NaiveDate, NaiveTime};
use chrono_tz::Asia::Kolkata;
use sqlx::PgPool;
use std::sync::Arc;
use tracing::{debug, error, info, trace};
use tracing::{debug, error};

use crate::models::member::Member;

Expand All @@ -26,7 +26,7 @@ pub async fn execute_daily_task(pool: Arc<PgPool>) {
// We need to add a record for every member because otherwise [`Presense`](https://www.github.com/presense) will only add present members to the DB, and we will have to JOIN Members and Attendance records for the day to get the absent members. In exchange for increased storage use, we get simpler queries for Home which needs the data for every member for every day so far. But as of Jan 2025, there are less than 50 members in the club and thus storage really shouldn't be an issue.
/// Inserts new attendance records everyday for [`presense`](https://www.github.com/amfoss/presense) to update them later in the day and updates the AttendanceSummary table to keep track of monthly streaks.
async fn update_attendance(members: Vec<Member>, pool: &PgPool) {
info!("Updating attendance...");
debug!("Updating attendance...");
let today = Local::now().with_timezone(&Kolkata).date_naive();

for member in members {
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn update_attendance(members: Vec<Member>, pool: &PgPool) {

/// Checks if the member was present yesterday, and if so, increments the `days_attended` value. Otherwise, do nothing.
async fn update_attendance_summary(member_id: i32, pool: &PgPool) {
trace!("Updating summary for member #{}", member_id);
debug!("Updating summary for member #{}", member_id);
let today = chrono::Local::now().with_timezone(&Kolkata).date_naive();
let yesterday = today.checked_sub_signed(chrono::Duration::days(1)).unwrap(); // Get yesterday's date

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/graphql/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
pub mod mutations;
pub mod query;
pub mod queries;
273 changes: 0 additions & 273 deletions src/graphql/mutations.rs

This file was deleted.

Loading

0 comments on commit 03324a4

Please sign in to comment.