Skip to content

Commit

Permalink
fix: fixed stupid mistake in similar papers endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
harshkhandeparkar committed Nov 11, 2024
1 parent 796b327 commit 04c3e93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
10 changes: 2 additions & 8 deletions backend/src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,14 @@ impl Database {
&self,
course_code: &str,
year: Option<i32>,
course_name: Option<&String>,
semester: Option<&String>,
exam: Option<&String>,
) -> Result<Vec<AdminDashboardQP>, sqlx::Error> {
let query_sql = queries::get_similar_papers_query(
year.is_some(),
course_name.is_some(),
semester.is_some(),
exam.is_some(),
);
let query_sql =
queries::get_similar_papers_query(year.is_some(), semester.is_some(), exam.is_some());
let query = sqlx::query_as(&query_sql).bind(course_code);

let query = query.bind(year);
let query = query.bind(course_name);
let query = query.bind(semester);
let query = query.bind(exam);

Expand Down
21 changes: 8 additions & 13 deletions backend/src/db/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,24 @@
use crate::qp::Exam;

/// Query to get similar papers. Matches `course_code` ($1) always. Other parameters are optional and can be enabled or disabled using the arguments to this function.
pub fn get_similar_papers_query(
year: bool,
course_name: bool,
semester: bool,
exam: bool,
) -> String {
///
/// Query parameters:
/// `$1` - `course_code``
/// `$2` - `year`
/// `$3` - `semester`
/// `$3` - `exam`
pub fn get_similar_papers_query(year: bool, semester: bool, exam: bool) -> String {
let mut param_num = 1;

format!(
"SELECT {} from iqps where is_deleted=false and course_code = $1 {} {} {} {}",
"SELECT {} from iqps where is_deleted=false and course_code = $1 {} {} {}",
ADMIN_DASHBOARD_QP_FIELDS,
if year {
param_num += 1;
format!("AND year=${}", param_num)
} else {
"".to_string()
},
if course_name {
param_num += 1;
format!("AND course_name=${}", param_num)
} else {
"".to_string()
},
if semester {
param_num += 1;
format!("AND semester=${}", param_num)
Expand Down
1 change: 0 additions & 1 deletion backend/src/routing/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ pub async fn similar(
body.get("year")
.map(|year| year.parse::<i32>())
.transpose()?,
body.get("course_name"),
body.get("semester"),
body.get("exam"),
)
Expand Down

0 comments on commit 04c3e93

Please sign in to comment.