Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

root v2 at this point #38

Merged
merged 38 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
e6224dd
remove soon-to-be outdated information in readme
ivinjabraham Jan 12, 2025
4f4ee27
remove shuttle dependency
ivinjabraham Jan 12, 2025
3c01c3a
reduce codebase to basic working web server template
ivinjabraham Jan 12, 2025
c3c58d1
remove migrations
ivinjabraham Jan 12, 2025
4f12588
add database backup to gitignore
ivinjabraham Jan 14, 2025
cec9d58
remove unused state from router
ivinjabraham Jan 14, 2025
d09e6a5
ignore .env files
ivinjabraham Jan 14, 2025
ec44d94
add migration to create initial tables for member, streaks and attend…
ivinjabraham Jan 14, 2025
bd5cd88
remove shuttle workflows
ivinjabraham Jan 14, 2025
522ded8
rename db module to models in order to better reflect its contents
ivinjabraham Jan 15, 2025
a16c83b
add graphql interface back to the server
ivinjabraham Jan 15, 2025
e8d341a
minor refinements to loading env variables, db pool configuration and…
ivinjabraham Jan 15, 2025
e7f43c7
uncomment scheduled task
ivinjabraham Jan 15, 2025
7ca67ea
rename scheduled_task to daily_task
ivinjabraham Jan 15, 2025
b3f1842
rename reference to db module to models, was left out earlier
ivinjabraham Jan 15, 2025
6201d06
use kolkata timezone instead of local time
ivinjabraham Jan 15, 2025
0ba8c00
rewrite midnight attendance records insertion and required models
ivinjabraham Jan 15, 2025
86ec4e0
rewrite attendance record insertion and updation logic
ivinjabraham Jan 15, 2025
7a9a6ee
remove leaderboard and active projects feature
ivinjabraham Jan 15, 2025
867ac2d
documentation changes and additions
ivinjabraham Jan 15, 2025
7762c85
ignore .log files
ivinjabraham Jan 17, 2025
3518e18
rewrite graphql interface
ivinjabraham Jan 17, 2025
ba21373
remove tests
ivinjabraham Jan 17, 2025
e6657da
add re-exports for less verbose imports
ivinjabraham Jan 17, 2025
76ac325
add BIND_ADDRESS env variable to avoid hardcoding address
ivinjabraham Jan 17, 2025
3ba685d
improve documentation in main.rs
ivinjabraham Jan 17, 2025
e2207f7
refactor main.rs to be more high-level by abstracing away its processes
ivinjabraham Jan 17, 2025
2d3c497
rename endpoints for more clarity
ivinjabraham Jan 17, 2025
3be56a5
complete todo to handle error when failing to fetch members
ivinjabraham Jan 17, 2025
3512e6c
add documentation to models
ivinjabraham Jan 17, 2025
127cb5e
fix graphiql missing graphql schema
ivinjabraham Jan 17, 2025
ffd6879
update documentation for root
ivinjabraham Jan 17, 2025
173b39c
add reset streak mutation
ivinjabraham Jan 17, 2025
7a804dc
add hmac verification to mark attendance
ivinjabraham Jan 17, 2025
8690495
remove shuttle workaround in main.rs
ivinjabraham Jan 17, 2025
7655247
fix incorrect query in mark attendance and remove time fields from it…
ivinjabraham Jan 24, 2025
356e508
run cargo fmt
ivinjabraham Jan 24, 2025
b234700
add projects feature
ivinjabraham Jan 24, 2025
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
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
ivinjabraham marked this conversation as resolved.
Outdated
Show resolved Hide resolved

This file was deleted.

Loading