You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let query = sqlx::query_as(&query_sql).bind(query);
76
76
@@ -80,11 +80,11 @@ impl Database {
80
80
query
81
81
};
82
82
83
-
let papers:Vec<models::DBSearchQP> = query.fetch_all(&self.connection).await?;
83
+
let papers:Vec<models::DBBaseQP> = query.fetch_all(&self.connection).await?;
84
84
85
85
Ok(papers
86
86
.iter()
87
-
.map(|qp| qp::SearchQP::from(qp.clone()))
87
+
.map(|qp| qp::BaseQP::from(qp.clone()))
88
88
.collect())
89
89
}
90
90
@@ -125,24 +125,24 @@ impl Database {
125
125
let current_details = self.get_paper_by_id(id).await?;
126
126
127
127
// Construct the final values to be inserted into the db
128
-
let course_code = course_code.unwrap_or(current_details.course_code);
129
-
let course_name = course_name.unwrap_or(current_details.course_name);
130
-
let year = year.unwrap_or(current_details.year);
128
+
let course_code = course_code.unwrap_or(current_details.qp.course_code);
129
+
let course_name = course_name.unwrap_or(current_details.qp.course_name);
130
+
let year = year.unwrap_or(current_details.qp.year);
131
131
let semester:String = semester
132
132
.map(|sem| Semester::try_from(&sem))
133
133
.transpose()?
134
-
.unwrap_or(current_details.semester)
134
+
.unwrap_or(current_details.qp.semester)
135
135
.into();
136
136
let exam:String = exam
137
137
.map(|exam| Exam::try_from(&exam))
138
138
.transpose()?
139
-
.unwrap_or(current_details.exam)
139
+
.unwrap_or(current_details.qp.exam)
140
140
.into();
141
141
let approve_status = approve_status.unwrap_or(current_details.approve_status);
142
142
143
143
// Set the new filelink
144
-
let old_filelink = current_details.filelink;
145
-
let new_filelink = if current_details.from_library{
144
+
let old_filelink = current_details.qp.filelink;
145
+
let new_filelink = if current_details.qp.from_library{
146
146
old_filelink.clone()
147
147
}elseif approve_status {
148
148
env_vars.paths.get_slug(
@@ -186,9 +186,9 @@ impl Database {
186
186
Ok((tx, old_filelink, new_qp))
187
187
}
188
188
189
-
/// Adds a new upload paper's details to the database. Sets the `from_library` field to false.
190
-
///
191
-
/// Returns the database transaction and the id of the uploaded paper
189
+
// /// Adds a new upload paper's details to the database. Sets the `from_library` field to false.
190
+
// ///
191
+
// /// Returns the database transaction and the id of the uploaded paper
192
192
// pub async fn add_uploaded_paper<'c>(
193
193
// &self,
194
194
// file_details:
@@ -276,9 +276,9 @@ impl Database {
276
276
}
277
277
278
278
// /// Updates filelink for an uploaded question paper uploaded using the [crate::db::Database::update_uploaded_filelink] function. Takes the same transaction that the previous function used.
Copy file name to clipboardExpand all lines: backend/src/qp.rs
+19-17Lines changed: 19 additions & 17 deletions
Original file line number
Diff line number
Diff line change
@@ -118,9 +118,14 @@ impl Serialize for ExamSem {
118
118
}
119
119
}
120
120
121
+
pubtraitWithUrl:Sized{
122
+
/// Returns the question paper with the full static files URL in the `filelink` field instead of just the slug. See the [`crate::pathutils`] module for what a slug is.
/// The fields of a question paper sent from the search endpoint
123
-
pubstructSearchQP{
128
+
pubstructBaseQP{
124
129
pubid:i32,
125
130
pubfilelink:String,
126
131
pubfrom_library:bool,
@@ -136,29 +141,26 @@ pub struct SearchQP {
136
141
///
137
142
/// This includes fields such as `approve_status` and `upload_timestamp` that would only be relevant to the dashboard.
138
143
pubstructAdminDashboardQP{
139
-
pubid:i32,
140
-
pubfilelink:String,
141
-
pubfrom_library:bool,
142
-
pubcourse_code:String,
143
-
pubcourse_name:String,
144
-
pubyear:i32,
145
-
pubsemester:Semester,
146
-
pubexam:Exam,
144
+
#[serde(flatten)]
145
+
pubqp:BaseQP,
147
146
pubupload_timestamp:String,
148
147
pubapprove_status:bool,
149
148
}
150
149
151
-
#[duplicate_item(
152
-
QP;
153
-
[SearchQP];
154
-
[AdminDashboardQP];
155
-
)]
156
-
implQP{
157
-
/// Returns the question paper with the full static files URL in the `filelink` field instead of just the slug. See the [`crate::pathutils`] module for what a slug is.
0 commit comments