Skip to content
Closed
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: 12 additions & 4 deletions src/attendance/scheduled_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub async fn scheduled_task(pool: Arc<PgPool>) {

if let Ok(Some(leetcode_stats)) = leetcode_username {
let username = leetcode_stats.leetcode_username.clone();

// Fetch and update LeetCode stats
match fetch_leetcode_stats(pool.clone(), member.id, &username).await {
Ok(_) => println!("LeetCode stats updated for member ID: {}", member.id),
Expand Down Expand Up @@ -104,8 +104,13 @@ pub async fn scheduled_task(pool: Arc<PgPool>) {

// Function to update attendance streak
async fn update_attendance_streak(member_id: i32, pool: &sqlx::PgPool) {
let today = chrono::Local::now().with_timezone(&chrono_tz::Asia::Kolkata).naive_local();
let yesterday = today.checked_sub_signed(chrono::Duration::hours(12)).unwrap().date();
let today = chrono::Local::now()
.with_timezone(&chrono_tz::Asia::Kolkata)
.naive_local();
let yesterday = today
.checked_sub_signed(chrono::Duration::hours(12))
.unwrap()
.date();

if today.day() == 1 {
let _ = sqlx::query(
Expand Down Expand Up @@ -176,6 +181,9 @@ async fn update_attendance_streak(member_id: i32, pool: &sqlx::PgPool) {
println!("Sreak not incremented for member ID: {}", member_id);
}
Ok(_) => eprintln!("Unexpected attendance value for member ID: {}", member_id),
Err(e) => eprintln!("Error checking attendance for member ID {}: {:?}", member_id, e),
Err(e) => eprintln!(
"Error checking attendance for member ID {}: {:?}",
member_id, e
),
}
}
10 changes: 5 additions & 5 deletions src/db/attendance.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_graphql::SimpleObject;
use chrono::{NaiveDate, NaiveTime};
use sqlx::FromRow;
use async_graphql::SimpleObject;

//Struct for the Attendance table
#[derive(FromRow, SimpleObject)]
Expand All @@ -22,19 +22,19 @@ pub struct AttendanceStreak {

#[derive(FromRow, SimpleObject)]
pub struct AttendanceSummary {
pub max_days:i64,
pub max_days: i64,
pub member_attendance: Vec<MemberAttendance>,
pub daily_count: Vec<DailyCount>,
}

#[derive(FromRow, SimpleObject)]
pub struct MemberAttendance {
pub id:i32,
pub present_days:i64,
pub id: i32,
pub present_days: i64,
}

#[derive(FromRow, SimpleObject)]
pub struct DailyCount {
pub date: NaiveDate,
pub count: i64,
}
}
4 changes: 2 additions & 2 deletions src/db/projects.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use sqlx::FromRow;
use async_graphql::SimpleObject;
use sqlx::FromRow;

#[derive(FromRow, SimpleObject)]
pub struct ActiveProjects {
id: i32,
member_id: i32,
project_title: Option<String>,
}
}
Loading
Loading