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

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 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
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
104 changes: 0 additions & 104 deletions src/graphql/mutations.rs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here, imo it should be rewritten before a possible merge. @swayam-agrahari whats your thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can merge the pr first then later we can work on the leaderboard, I haven't had time to complete the frontend so it will be done in the mean time and others are busy with gsoc so don't thing its a urgency right now!

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use root::models::{
attendance::Attendance,
leaderboard::{CodeforcesStats, LeetCodeStats},
member::Member,
member::StreakUpdate,
projects::ActiveProjects,
};

Expand Down Expand Up @@ -205,61 +204,6 @@ impl MutationRoot {
Ok(attendance)
}

//here when user changes the handle, it just updates the handle in the database without updating the other values till midnight

async fn add_or_update_leetcode_username(
&self,
ctx: &Context<'_>,
member_id: i32,
username: String,
) -> Result<LeetCodeStats, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");

let result = sqlx::query_as::<_, LeetCodeStats>(
"
INSERT INTO leetcode_stats (member_id, leetcode_username, problems_solved, easy_solved, medium_solved, hard_solved, contests_participated, best_rank, total_contests)
VALUES ($1, $2, 0, 0, 0, 0, 0, 0, 0)
ON CONFLICT (member_id) DO UPDATE
SET leetcode_username = $2
RETURNING *
"
)
.bind(member_id)
.bind(username)
.fetch_one(pool.as_ref())
.await?;

Ok(result)
}

async fn add_or_update_codeforces_handle(
&self,
ctx: &Context<'_>,
member_id: i32,
handle: String,
) -> Result<CodeforcesStats, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");

let result = sqlx::query_as::<_, CodeforcesStats>(
"
INSERT INTO codeforces_stats (member_id, codeforces_handle, codeforces_rating, max_rating, contests_participated)
VALUES ($1, $2, 0, 0, 0)
ON CONFLICT (member_id) DO UPDATE
SET codeforces_handle = $2
RETURNING *
"
)
.bind(member_id)
.bind(handle)
.fetch_one(pool.as_ref())
.await?;

Ok(result)
}
async fn update_streak(
&self,
ctx: &Context<'_>,
Expand Down Expand Up @@ -326,52 +270,4 @@ impl MutationRoot {
}
}
}

async fn set_active_project(
&self,
ctx: &Context<'_>,
id: i32,
project_name: String,
) -> Result<ActiveProjects, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");

let active_project = sqlx::query_as::<_, ActiveProjects>(
"
INSERT INTO ActiveProjects (member_id,project_title)
VALUES ($1,$2)
RETURNING *
",
)
.bind(id)
.bind(project_name)
.fetch_one(pool.as_ref())
.await?;

Ok(active_project)
}

async fn remove_active_project(
&self,
ctx: &Context<'_>,
project_id: i32,
) -> Result<ActiveProjects, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");

let active_project = sqlx::query_as::<_, ActiveProjects>(
"
DELETE FROM ActiveProjects
WHERE id = $1
RETURNING *
",
)
.bind(project_id)
.fetch_one(pool.as_ref())
.await?;

Ok(active_project)
}
}
79 changes: 1 addition & 78 deletions src/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@ use async_graphql::{Context, Object};
use chrono::NaiveDate;
use root::models::{
attendance::Attendance,
leaderboard::{CodeforcesStatsWithName, LeaderboardWithMember, LeetCodeStatsWithName},
member::{Member, StreakUpdate},
};
use root::models::{
attendance::{AttendanceStreak, AttendanceSummary, DailyCount, MemberAttendance},
projects::ActiveProjects,
member::Member,
};
use sqlx::PgPool;
use std::sync::Arc;
Expand All @@ -16,7 +11,6 @@ pub struct QueryRoot;

#[Object]
impl QueryRoot {
//Query for retrieving the members
async fn get_member(&self, ctx: &Context<'_>) -> Result<Vec<Member>, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
Expand All @@ -27,62 +21,6 @@ impl QueryRoot {
Ok(users)
}

async fn get_unified_leaderboard(
&self,
ctx: &Context<'_>,
) -> Result<Vec<LeaderboardWithMember>, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");
let leaderboard = sqlx::query_as::<_, LeaderboardWithMember>(
"SELECT l.*, m.name AS member_name
FROM leaderboard l
JOIN member m ON l.member_id = m.id
ORDER BY unified_score DESC",
)
.fetch_all(pool.as_ref())
.await?;
Ok(leaderboard)
}

async fn get_leetcode_stats(
&self,
ctx: &Context<'_>,
) -> Result<Vec<LeetCodeStatsWithName>, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");
let leetcode_stats = sqlx::query_as::<_, LeetCodeStatsWithName>(
"SELECT l.*, m.name AS member_name
FROM leetcode_stats l
JOIN member m ON l.member_id = m.id
ORDER BY best_rank
",
)
.fetch_all(pool.as_ref())
.await?;
Ok(leetcode_stats)
}

async fn get_codeforces_stats(
&self,
ctx: &Context<'_>,
) -> Result<Vec<CodeforcesStatsWithName>, sqlx::Error> {
// let pool = ctx.data::<PgPool>()?;
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");
let codeforces_stats = sqlx::query_as::<_, CodeforcesStatsWithName>(
"SELECT c.*, m.name AS member_name
FROM codeforces_stats c
JOIN member m ON c.member_id = m.id
ORDER BY max_rating DESC",
)
.fetch_all(pool.as_ref())
.await?;
Ok(codeforces_stats)
}

//Query for retrieving the attendance based on date
async fn get_attendance(
&self,
Expand Down Expand Up @@ -227,19 +165,4 @@ impl QueryRoot {

Ok(dates)
}

pub async fn get_projects(
&self,
ctx: &Context<'_>,
) -> Result<Vec<ActiveProjects>, sqlx::Error> {
let pool = ctx
.data::<Arc<PgPool>>()
.expect("Pool not found in context");

let active_projects = sqlx::query_as::<_, ActiveProjects>("SELECT * FROM ActiveProjects")
.fetch_all(pool.as_ref())
.await?;

Ok(active_projects)
}
}
Loading