Skip to content

Commit

Permalink
remove leaderboard and active projects feature
Browse files Browse the repository at this point in the history
  • Loading branch information
ivinjabraham committed Jan 15, 2025
1 parent 86ec4e0 commit 774383c
Show file tree
Hide file tree
Showing 9 changed files with 0 additions and 568 deletions.
104 changes: 0 additions & 104 deletions src/graphql/mutations.rs
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)
}
}
56 changes: 0 additions & 56 deletions src/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,62 +27,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
180 changes: 0 additions & 180 deletions src/leaderboard/fetch_stats.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/leaderboard/mod.rs

This file was deleted.

Loading

0 comments on commit 774383c

Please sign in to comment.