api/routes/modules/assignments/
common.rs

1//! Assignment request and response models.
2//!
3//! Provides data structures for creating, reading, and managing assignments, including bulk operations.
4//!
5//! - `AssignmentRequest` – payload for creating/updating a single assignment.
6//! - `AssignmentResponse` – returned assignment details.
7//! - `File` – metadata for assignment-associated files.
8//! - `BulkDeleteRequest` – payload for deleting multiple assignments.
9//! - `BulkUpdateRequest` – payload for updating multiple assignments.
10//! - `BulkUpdateResult` and `FailedUpdate` – results of bulk update operations.
11
12use serde::{Serialize, Deserialize};
13use db::models::assignment::Model as AssignmentModel;
14
15#[derive(Debug, Serialize, Deserialize)]
16pub struct File {
17    pub id: String,
18    pub filename: String,
19    pub path: String,
20    pub file_type: String,
21    pub created_at: String,
22    pub updated_at: String,
23}
24
25#[derive(Debug, Serialize, Deserialize)]
26pub struct AssignmentResponse {
27    pub id: i64,
28    pub module_id: i64,
29    pub name: String,
30    pub description: Option<String>,
31    pub assignment_type: String,
32    pub status: String,
33    pub available_from: String,
34    pub due_date: String,
35    pub created_at: String,
36    pub updated_at: String,
37}
38
39impl From<AssignmentModel> for AssignmentResponse {
40    fn from(a: AssignmentModel) -> Self {
41        Self {
42            id: a.id,
43            module_id: a.module_id,
44            name: a.name,
45            description: a.description,
46            assignment_type: a.assignment_type.to_string(),
47            status: a.status.to_string(),
48            available_from: a.available_from.to_rfc3339(),
49            due_date: a.due_date.to_rfc3339(),
50            created_at: a.created_at.to_rfc3339(),
51            updated_at: a.updated_at.to_rfc3339(),
52        }
53    }
54}
55
56#[derive(Debug, Deserialize)]
57pub struct AssignmentRequest {
58    pub name: String,
59    pub description: Option<String>,
60    pub assignment_type: String,
61    pub available_from: String,
62    pub due_date: String,
63}
64
65#[derive(Deserialize)]
66pub struct BulkDeleteRequest {
67    pub assignment_ids: Vec<i64>,
68}
69
70#[derive(Debug, Deserialize)]
71pub struct BulkUpdateRequest {
72    pub assignment_ids: Vec<i64>,
73
74    // Optional fields to apply
75    pub status: Option<String>,
76    pub available_from: Option<String>,
77    pub due_date: Option<String>,
78}
79
80#[derive(Serialize)]
81pub struct BulkUpdateResult {
82    pub updated: usize,
83    pub failed: Vec<FailedUpdate>,
84}
85
86#[derive(Serialize)]
87pub struct FailedUpdate {
88    pub id: i64,
89    pub error: String,
90}