Struct Model

Source
pub struct Model {
    pub id: i64,
    pub module_id: i64,
    pub name: String,
    pub description: Option<String>,
    pub assignment_type: AssignmentType,
    pub status: Status,
    pub available_from: DateTime<Utc>,
    pub due_date: DateTime<Utc>,
    pub config: Option<JsonValue>,
    pub created_at: DateTime<Utc>,
    pub updated_at: DateTime<Utc>,
}
Expand description

Assignment model representing the assignments table in the database.

Fields§

§id: i64§module_id: i64§name: String§description: Option<String>§assignment_type: AssignmentType§status: Status§available_from: DateTime<Utc>§due_date: DateTime<Utc>§config: Option<JsonValue>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>

Implementations§

Source§

impl Model

Source

pub async fn create( db: &DatabaseConnection, module_id: i64, name: &str, description: Option<&str>, assignment_type: AssignmentType, available_from: DateTime<Utc>, due_date: DateTime<Utc>, ) -> Result<Self, DbErr>

Source

pub async fn edit( db: &DatabaseConnection, id: i64, module_id: i64, name: &str, description: Option<&str>, assignment_type: AssignmentType, available_from: DateTime<Utc>, due_date: DateTime<Utc>, ) -> Result<Self, DbErr>

Source

pub async fn delete( db: &DatabaseConnection, id: i32, module_id: i32, ) -> Result<(), DbErr>

Source

pub async fn filter( db: &DatabaseConnection, page: u64, per_page: u64, sort_by: Option<String>, query: Option<String>, ) -> Result<Vec<Self>, DbErr>

Source

pub async fn compute_readiness_report( db: &DatabaseConnection, module_id: i64, assignment_id: i64, ) -> Result<ReadinessReport, DbErr>

Computes a detailed readiness report for an assignment by checking if all required components are present.

This function verifies the presence of all expected resources for an assignment:

  • At least one task is defined in the database.
  • A configuration file exists.
  • A main file exists.
  • A memo file exists.
  • A makefile exists.
  • A memo output file exists.
  • A JSON mark allocator file exists.

The returned ReadinessReport (or [AssignmentReadiness]) contains boolean flags for each component and an is_ready field indicating whether the assignment is fully ready (i.e., suitable to transition from Setup to Ready state).

This function only checks readiness — it does not modify the assignment’s status in the database.

§Arguments
  • db - A reference to the database connection.
  • module_id - The ID of the module to which the assignment belongs.
  • assignment_id - The ID of the assignment to check.
§Returns
  • Ok(ReadinessReport) with per-component readiness details.
  • Err(DbErr) if a database error occurs while checking tasks.
§Notes

File presence is checked on the file system under the expected directories for each file type. Missing directories or I/O errors are treated as absence of the respective component.

Source

pub async fn try_transition_to_ready( db: &DatabaseConnection, module_id: i64, assignment_id: i64, ) -> Result<bool, DbErr>

Attempts to transition an assignment to Ready state if all readiness conditions are met.

This function:

  • Computes a full readiness report for the assignment.
  • If all components are present (is_ready == true), it checks the current status.
  • If the current status is Setup, it updates the status to Ready and updates updated_at.
  • If already in Ready, Open, etc., it does not change the status.
§Arguments
  • db - A reference to the database connection.
  • module_id - The ID of the module to which the assignment belongs.
  • assignment_id - The ID of the assignment.
§Returns
  • Ok(true) if the assignment is fully ready (regardless of whether the status was updated).
  • Ok(false) if the assignment is not ready.
  • Err(DbErr) if a database error occurs.

Trait Implementations§

Source§

impl Clone for Model

Source§

fn clone(&self) -> Model

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Model

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Model> for ActiveModel

Source§

fn from(m: Model) -> Self

Converts to this type from the input type.
Source§

impl FromQueryResult for Model

Source§

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>

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>

Transform the error from instantiating a Model from a [QueryResult] and converting it to an Option Read more
§

fn find_by_statement(stmt: Statement) -> SelectorRaw<SelectModel<Self>>

Source§

impl IntoActiveModel<ActiveModel> for Model

Source§

fn into_active_model(self) -> ActiveModel

Method to call to perform the conversion
Source§

impl ModelTrait for Model

Source§

type Entity = Entity

Source§

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)

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>,

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,

Delete a model
Source§

impl PartialEq for Model

Source§

fn eq(&self, other: &Model) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<ActiveModel> for Model

Source§

type Error = DbErr

The type returned in the event of a conversion error.
Source§

fn try_from(a: ActiveModel) -> Result<Self, DbErr>

Performs the conversion.
Source§

impl TryIntoModel<Model> for ActiveModel

Source§

fn try_into_model(self) -> Result<Model, DbErr>

Method to call to perform the conversion
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<M> TryIntoModel<M> for M
where M: ModelTrait,

§

fn try_into_model(self) -> Result<M, DbErr>

Method to call to perform the conversion
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,