api/routes/modules/assignments/submissions/
common.rs

1//! Submission utilities and response types.
2//!
3//! This module provides types and helpers for submissions-related endpoints.
4//!
5//! It includes:
6//! - `ListSubmissionsQuery` → query parameters for paginated submission listings
7//! - `UserResponse` → represents a user associated with a submission
8//! - `Mark` → represents earned/total marks for a submission
9//! - `SubmissionListItem` → single item in a submissions list
10//! - `SubmissionsListResponse` → paginated submissions list
11//! - `SubmissionResponse` → minimal response for a single submission
12//! - `MarkSummary` → summary of earned vs total marks
13//! - `CodeComplexitySummary` → summary of code complexity metrics
14//! - `CodeComplexity` → detailed code complexity information
15//! - `SubmissionDetailResponse` → detailed response after grading a submission
16
17use serde::{Deserialize, Serialize};
18
19/// Query parameters for submissions listing endpoints.
20#[derive(Debug, Deserialize)]
21pub struct ListSubmissionsQuery {
22    pub page: Option<u32>,
23    pub per_page: Option<u32>,
24    pub sort: Option<String>,
25    pub query: Option<String>,
26    pub username: Option<String>,
27    pub late: Option<bool>,
28}
29
30/// Represents a user associated with a submission.
31#[derive(Debug, Serialize, Clone)]
32pub struct UserResponse {
33    pub id: i64,
34    pub username: String,
35    pub email: String,
36}
37
38/// Represents the mark of a submission.
39#[derive(Debug, Serialize, Deserialize, Clone)]
40pub struct Mark {
41    pub earned: i64,
42    pub total: i64,
43}
44
45/// Single item in a submissions list response.
46#[derive(Debug, Serialize)]
47pub struct SubmissionListItem {
48    pub id: i64,
49    pub user: UserResponse,
50    pub attempt: i64,
51    pub filename: String,
52    pub created_at: String,
53    pub updated_at: String,
54    pub is_practice: bool,
55    pub is_late: bool,
56    pub mark: Option<Mark>,
57}
58
59/// Paginated response of submissions list.
60#[derive(Debug, Serialize)]
61pub struct SubmissionsListResponse {
62    pub submissions: Vec<SubmissionListItem>,
63    pub page: u32,
64    pub per_page: u32,
65    pub total: u64,
66}
67
68/// Minimal submission response for single submission detail.
69#[derive(Debug, Serialize)]
70pub struct SubmissionResponse {
71    pub id: i64,
72    pub attempt: i64,
73    pub filename: String,
74    pub created_at: String,
75    pub updated_at: String,
76    pub is_late: bool,
77    pub is_practice: bool,
78    pub mark: Option<Mark>,
79}
80
81/// Represents a summary of earned vs total marks.
82#[derive(Debug, Serialize, Deserialize)]
83pub struct MarkSummary {
84    pub earned: i64,
85    pub total: i64,
86}
87
88/// Represents a summary of code complexity metrics.
89#[derive(Debug, Serialize, Deserialize)]
90pub struct CodeComplexitySummary {
91    pub earned: i64,
92    pub total: i64,
93}
94
95/// Represents code complexity details, including per-metric results.
96#[derive(Debug, Serialize, Deserialize)]
97pub struct CodeComplexity {
98    pub summary: CodeComplexitySummary,
99    pub metrics: Vec<serde_json::Value>,
100}
101
102/// Detailed response returned after grading a submission.
103#[derive(Debug, Serialize, Deserialize)]
104pub struct SubmissionDetailResponse {
105    pub id: i64,
106    pub attempt: i64,
107    pub filename: String,
108    pub hash: String,
109    pub created_at: String,
110    pub updated_at: String,
111    pub mark: MarkSummary,
112    pub is_practice: bool,
113    pub is_late: bool,
114    pub tasks: Vec<serde_json::Value>,
115    #[serde(skip_serializing_if = "Option::is_none")]
116    pub code_coverage: Option<Vec<serde_json::Value>>,
117    #[serde(skip_serializing_if = "Option::is_none")]
118    pub code_complexity: Option<CodeComplexity>,
119}