pub struct Model {
pub id: i64,
pub assignment_id: i64,
pub user_id: i64,
pub attempt: i64,
pub earned: i64,
pub total: i64,
pub filename: String,
pub file_hash: String,
pub path: String,
pub is_practice: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
Expand description
Represents a user’s submission for a specific assignment.
Each submission is linked to one assignment and one user. Timestamps are included to track when the submission was created and last updated.
Fields§
§id: i64
Primary key of the submission.
assignment_id: i64
ID of the related assignment.
user_id: i64
ID of the user who submitted the assignment.
attempt: i64
Attempt number
earned: i64
The score earned by the user.
total: i64
The total possible score.
filename: String
The original filename uploaded by the user.
file_hash: String
The hash of the submitted files.
path: String
Relative file path from the storage root.
is_practice: bool
Is this submission a practice submission?
created_at: DateTime<Utc>
Timestamp when the submission was created.
updated_at: DateTime<Utc>
Timestamp when the submission was last updated.
Implementations§
Source§impl Model
impl Model
Sourcepub fn storage_root() -> PathBuf
pub fn storage_root() -> PathBuf
Returns the root directory used for storing assignment submissions on disk.
§Returns
PathBuf
pointing to the base directory.
Uses the ASSIGNMENT_STORAGE_ROOT
environment variable if set,
otherwise defaults to data/assignment_files
.
Sourcepub fn full_directory_path(
module_id: i64,
assignment_id: i64,
user_id: i64,
attempt: i64,
) -> PathBuf
pub fn full_directory_path( module_id: i64, assignment_id: i64, user_id: i64, attempt: i64, ) -> PathBuf
Sourcepub fn full_path(&self) -> PathBuf
pub fn full_path(&self) -> PathBuf
Computes the absolute path to the stored file on disk.
§Returns
PathBuf
pointing to the file location.
Sourcepub async fn save_file(
db: &DatabaseConnection,
assignment_id: i64,
user_id: i64,
attempt: i64,
earned: i64,
total: i64,
is_practice: bool,
filename: &str,
file_hash: &str,
bytes: &[u8],
) -> Result<Self, DbErr>
pub async fn save_file( db: &DatabaseConnection, assignment_id: i64, user_id: i64, attempt: i64, earned: i64, total: i64, is_practice: bool, filename: &str, file_hash: &str, bytes: &[u8], ) -> Result<Self, DbErr>
Saves a file to disk and creates or updates its metadata in the database.
This method:
- Creates a temporary DB entry.
- Looks up the associated assignment and module.
- Saves the file with a generated name on disk.
- Updates the DB entry with the file path.
§Arguments
db
: Reference to the active database connection.assignment_id
: ID of the assignment this submission is for.user_id
: ID of the user submitting.attempt
: Attempt number,filename
: The original filename as submitted.bytes
: The file content as a byte slice.
§Returns
Ok(Model)
: The complete, updatedModel
representing the saved file.Err(DbErr)
: If any database or filesystem operation fails.
Sourcepub fn load_file(&self) -> Result<Vec<u8>, Error>
pub fn load_file(&self) -> Result<Vec<u8>, Error>
Loads the contents of the stored file from disk.
§Returns
Ok(Vec<u8>)
: The file contents as bytes.Err(std::io::Error)
: If reading the file fails.
Sourcepub fn delete_file_only(&self) -> Result<(), Error>
pub fn delete_file_only(&self) -> Result<(), Error>
Deletes the file from disk without removing the database record.
§Returns
Ok(())
: If the file was successfully deleted.Err(std::io::Error)
: If the file deletion failed.
Sourcepub async fn find_by_assignment(
assignment_id: i64,
db: &DatabaseConnection,
) -> Result<Vec<i64>, DbErr>
pub async fn find_by_assignment( assignment_id: i64, db: &DatabaseConnection, ) -> Result<Vec<i64>, DbErr>
Find all submission IDs for a given assignment
pub async fn get_latest_submissions_for_assignment( db: &DatabaseConnection, assignment_id: i64, ) -> Result<Vec<Self>, DbErr>
Trait Implementations§
Source§impl From<Model> for ActiveModel
impl From<Model> for ActiveModel
Source§impl FromQueryResult for Model
impl FromQueryResult for Model
Source§fn from_query_result(row: &QueryResult, pre: &str) -> Result<Self, DbErr>
fn from_query_result(row: &QueryResult, pre: &str) -> Result<Self, DbErr>
§fn from_query_result_optional(
res: &QueryResult,
pre: &str,
) -> Result<Option<Self>, DbErr>
fn from_query_result_optional( res: &QueryResult, pre: &str, ) -> Result<Option<Self>, DbErr>
§fn from_query_result_nullable(
res: &QueryResult,
pre: &str,
) -> Result<Self, TryGetError>
fn from_query_result_nullable( res: &QueryResult, pre: &str, ) -> Result<Self, TryGetError>
§fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>
fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>
Source§impl IntoActiveModel<ActiveModel> for Model
impl IntoActiveModel<ActiveModel> for Model
Source§fn into_active_model(self) -> ActiveModel
fn into_active_model(self) -> ActiveModel
Source§impl ModelTrait for Model
impl ModelTrait for Model
type Entity = Entity
Source§fn get(&self, c: <Self::Entity as EntityTrait>::Column) -> Value
fn get(&self, c: <Self::Entity as EntityTrait>::Column) -> Value
Source§fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value)
fn set(&mut self, c: <Self::Entity as EntityTrait>::Column, v: Value)
§fn find_linked<L>(&self, l: L) -> Select<<L as Linked>::ToEntity>where
L: Linked<FromEntity = Self::Entity>,
fn find_linked<L>(&self, l: L) -> Select<<L as Linked>::ToEntity>where
L: Linked<FromEntity = Self::Entity>,
§fn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>where
'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait,
fn delete<'a, 'async_trait, A, C>(
self,
db: &'a C,
) -> Pin<Box<dyn Future<Output = Result<DeleteResult, DbErr>> + Send + 'async_trait>>where
'a: 'async_trait,
Self: IntoActiveModel<A> + 'async_trait,
C: ConnectionTrait + 'async_trait,
A: ActiveModelTrait<Entity = Self::Entity> + ActiveModelBehavior + Send + 'a + 'async_trait,
Source§impl TryFrom<ActiveModel> for Model
impl TryFrom<ActiveModel> for Model
Source§impl TryIntoModel<Model> for ActiveModel
impl TryIntoModel<Model> for ActiveModel
Source§fn try_into_model(self) -> Result<Model, DbErr>
fn try_into_model(self) -> Result<Model, DbErr>
impl StructuralPartialEq for Model
Auto Trait Implementations§
impl Freeze for Model
impl RefUnwindSafe for Model
impl Send for Model
impl Sync for Model
impl Unpin for Model
impl UnwindSafe for Model
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