diff options
| author | Daniel Hader <[email protected]> | 2026-06-04 18:29:34 -0500 |
|---|---|---|
| committer | Daniel Hader <[email protected]> | 2026-06-04 18:29:34 -0500 |
| commit | 3ac68b8b59f150e08731a62026ce3ac825655614 (patch) | |
| tree | b493b1668721caf705aaeb7f700b14e21933ae25 /src/database | |
| parent | 9122911ca8a8be68d30194a3765a2d4cddaff1a1 (diff) | |
viewing submissions logic
Diffstat (limited to 'src/database')
| -rw-r--r-- | src/database/database.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/database/database.rs b/src/database/database.rs index 961c39c..95c8bf6 100644 --- a/src/database/database.rs +++ b/src/database/database.rs @@ -244,6 +244,29 @@ impl Database { .map_err(|e| DatabaseError::Query(e.to_string()))? ) } + + pub fn fetch_display_submission(&self, submission_id: i64) -> Result<Option<DisplaySubmission>, DatabaseError> { + static QUERY: &str = include_str!("sql/fetch_display_submissions.sql"); + let conn = self.pool + .get() + .map_err(|e| DatabaseError::Connection(e.to_string()))?; + let mut statement = conn.prepare(QUERY) + .map_err(|e| DatabaseError::Query(e.to_string()))?; + + Ok(statement + .query_one([submission_id], |row| { + Ok(DisplaySubmission { + id: row.get("id")?, + username: row.get("username")?, + language: row.get("language")?, + details: row.get("details")?, + code: row.get("code")?, + }) + }) + .optional() + .map_err(|e| DatabaseError::Query(e.to_string()))? + ) + } pub fn initialize(&self) -> Result<(), DatabaseError> { static QUERY: &str = include_str!("sql/initialize.sql"); |
