pub struct Database { /* private fields */ }Expand description
The database
Implementations§
Source§impl Database
impl Database
Sourcepub async fn new(env_vars: &EnvVars) -> Result<Self, Error>
pub async fn new(env_vars: &EnvVars) -> Result<Self, Error>
Creates a new database connection given the environment variables.
Sourcepub async fn get_unapproved_papers(
&self,
) -> Result<Vec<AdminDashboardQP>, Error>
pub async fn get_unapproved_papers( &self, ) -> Result<Vec<AdminDashboardQP>, Error>
Fetches the list of all unapproved papers
Sourcepub async fn get_unapproved_papers_count(&self) -> Result<i64, Error>
pub async fn get_unapproved_papers_count(&self) -> Result<i64, Error>
Returns the number of unapproved papers
Sourcepub async fn search_papers(
&self,
query: &str,
exam_filter: Vec<Exam>,
) -> Result<Vec<BaseQP>, Error>
pub async fn search_papers( &self, query: &str, exam_filter: Vec<Exam>, ) -> Result<Vec<BaseQP>, Error>
Searches for papers from a given query. Uses some voodoo black magic by @rajivharlalka
pub async fn get_paper_by_id(&self, id: i32) -> Result<AdminDashboardQP, Error>
Sourcepub async fn edit_paper<'c>(
&self,
edit_req: EditReq,
username: &str,
env_vars: &EnvVars,
) -> Result<(Transaction<'c, Postgres>, String, AdminDashboardQP), Error>
pub async fn edit_paper<'c>( &self, edit_req: EditReq, username: &str, env_vars: &EnvVars, ) -> Result<(Transaction<'c, Postgres>, String, AdminDashboardQP), Error>
Edit’s a paper’s details.
- Sets the
approved_byfield to the username if approved. - Sets the
filelinkto:- For library papers, remains unchanged
- For uploaded papers, approved papers are moved to the approved directory and renamed
id_coursecode_coursename_year_semester_exam.pdfand unapproved papers are moved to the unapproved directory and namedid.pdf
- Deletes
replacepapers from the database.
Returns the database transaction, the old filelink and the new paper details (crate::qp::AdminDashboardQP)
Sourcepub async fn soft_delete(&self, id: i32) -> Result<bool, Error>
pub async fn soft_delete(&self, id: i32) -> Result<bool, Error>
Sets the is_deleted field to true and approve_status to false. Only deletes uploaded papers.
Returns a boolean that represents whether a db entry was affected or not. If more than one entry was affected, an error will be thrown and the transaction will be rolled back.
Sourcepub async fn get_soft_deleted_papers(
&self,
) -> Result<Vec<AdminDashboardQP>, Error>
pub async fn get_soft_deleted_papers( &self, ) -> Result<Vec<AdminDashboardQP>, Error>
Gets all soft-deleted papers from the database
Sourcepub async fn hard_delete(
&self,
id: i32,
) -> Result<Transaction<'_, Postgres>, Error>
pub async fn hard_delete( &self, id: i32, ) -> Result<Transaction<'_, Postgres>, Error>
Permanently deletes a paper from the database
Sourcepub async fn get_similar_papers(
&self,
course_code: &str,
year: Option<i32>,
semester: Option<&String>,
exam: Option<&String>,
) -> Result<Vec<AdminDashboardQP>, Error>
pub async fn get_similar_papers( &self, course_code: &str, year: Option<i32>, semester: Option<&String>, exam: Option<&String>, ) -> Result<Vec<AdminDashboardQP>, Error>
Returns all papers that match one or more of the specified properties exactly. course_name is required, other properties are optional.
Sourcepub async fn insert_new_uploaded_qp<'c>(
&self,
file_details: &FileDetails,
) -> Result<(Transaction<'c, Postgres>, i32), Error>
pub async fn insert_new_uploaded_qp<'c>( &self, file_details: &FileDetails, ) -> Result<(Transaction<'c, Postgres>, i32), Error>
Inserts a new uploaded question paper into the database. Uses a placeholder for the filelink which should be replaced once the id is known using the crate::db::Database::update_filelink function.
Returns a tuple with the transaction and the id of the inserted paper.
Sourcepub async fn insert_new_library_qp<'c>(
&self,
paper: &LibraryQP,
) -> Result<(Transaction<'c, Postgres>, i32), Error>
pub async fn insert_new_library_qp<'c>( &self, paper: &LibraryQP, ) -> Result<(Transaction<'c, Postgres>, i32), Error>
Inserts a new library question paper into the database. Uses a placeholder for the filelink which should be replaced once the id is known using the crate::db::Database::update_filelink function.
Returns a tuple with the transaction and the id of the inserted paper.
Sourcepub async fn update_filelink(
&self,
tx: &mut Transaction<'_, Postgres>,
id: i32,
file_link: &str,
) -> Result<(), Error>
pub async fn update_filelink( &self, tx: &mut Transaction<'_, Postgres>, id: i32, file_link: &str, ) -> Result<(), Error>
Updates filelink for an uploaded question paper uploaded using the crate::db::Database::insert_new_uploaded_qp or crate::db::Database::insert_new_library_qp function. Takes the same transaction that the previous function used.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Database
impl !RefUnwindSafe for Database
impl Send for Database
impl Sync for Database
impl Unpin for Database
impl !UnwindSafe for Database
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more