pub struct Model {
pub id: i64,
pub assignment_id: i64,
pub filename: String,
pub path: String,
pub file_type: FileType,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
Expand description
Represents a file associated with an assignment, such as a spec, main file, memo, or submission.
Fields§
§id: i64
§assignment_id: i64
Foreign key reference to an assignment.
filename: String
Original file name.
path: String
Relative path to the stored file from the storage root.
file_type: FileType
Type of the file (spec, main, memo, submission).
created_at: DateTime<Utc>
§updated_at: DateTime<Utc>
Implementations§
Source§impl Model
impl Model
Sourcepub fn load_execution_config(
&self,
module_id: i64,
) -> Result<ExecutionConfig, String>
pub fn load_execution_config( &self, module_id: i64, ) -> Result<ExecutionConfig, String>
Loads and returns the ExecutionConfig
if the file type is Config
.
Requires module_id
because it’s not stored in the DB.
Sourcepub fn storage_root() -> PathBuf
pub fn storage_root() -> PathBuf
Returns the base directory for assignment file storage from the environment.
Sourcepub fn full_directory_path(
module_id: i64,
assignment_id: i64,
file_type: &FileType,
) -> PathBuf
pub fn full_directory_path( module_id: i64, assignment_id: i64, file_type: &FileType, ) -> PathBuf
Computes the full directory path based on module ID, assignment ID, and file type.
pub fn full_path(&self) -> PathBuf
pub async fn save_file( db: &DatabaseConnection, assignment_id: i64, module_id: i64, file_type: FileType, filename: &str, bytes: &[u8], ) -> Result<Self, DbErr>
Sourcepub fn load_file(&self) -> Result<Vec<u8>, Error>
pub fn load_file(&self) -> Result<Vec<u8>, Error>
Loads the file contents from disk based on the path stored in the model.
Sourcepub fn delete_file_only(&self) -> Result<(), Error>
pub fn delete_file_only(&self) -> Result<(), Error>
Deletes the file from disk (but not the DB record).
pub async fn get_base_files( 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>
Instantiate a Model from a [QueryResult] Read more
§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>
Transform the error from instantiating a Model from a [QueryResult]
and converting it to an Option
§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
Method to call to perform the conversion
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
Get the [Value] of a column from an Entity
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)
Set the [Value] of a column in an Entity
Find related Models
§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>,
Find linked Models
§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,
Delete a model
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>
Method to call to perform the conversion
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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<M> TryIntoModel<M> for Mwhere
M: ModelTrait,
impl<M> TryIntoModel<M> for Mwhere
M: ModelTrait,
§fn try_into_model(self) -> Result<M, DbErr>
fn try_into_model(self) -> Result<M, DbErr>
Method to call to perform the conversion