Function save

Source
pub async fn save(
    __arg0: Path<(i64, i64)>,
    __arg1: Json<Value>,
) -> impl IntoResponse
Expand description

PUT /api/modules/{module_id}/assignments/{assignment_id}/mark_allocator

Save the mark allocator JSON configuration for a specific assignment. Accessible to users with Lecturer roles assigned to the module.

This endpoint saves a mark allocator configuration to the assignment directory. The configuration defines how many points (values) are allocated to each task and its subsections. The saved configuration is used by the grading system to calculate final marks.

§Path Parameters

  • module_id (i64): The ID of the module containing the assignment
  • assignment_id (i64): The ID of the assignment to save the mark allocator for

§Request Body (points-based schema using value)

A JSON object with:

  • tasks: non-empty array of single-key task objects: { "taskN": { ... } }
  • total_value: integer (≥ 0) equal to the sum of all task values
{
  "generated_at": "2025-08-17T22:00:00Z",
  "tasks": [
    {
      "task1": {
        "name": "Task 1",
        "task_number": 1,
        "value": 9,
        "subsections": [
          { "name": "Correctness", "value": 5 },
          { "name": "Style",       "value": 4 }
        ]
      }
    },
    {
      "task2": {
        "name": "Task 2",
        "task_number": 2,
        "value": 6,
        "subsections": [
          { "name": "Docs", "value": 2 },
          { "name": "Tests","value": 4 }
        ]
      }
    }
  ],
  "total_value": 15
}
§Field semantics
  • tasks (required, non-empty array): Each element must be an object with exactly one key "taskN". The value of that key is a task object with:
    • name (required, non-empty string)
    • task_number (required, positive integer). Must match the number N in "taskN".
    • value (required, integer ≥ 0): Total points for the task
    • subsections (required, array; may be empty):
      • Each item: { "name": string (non-empty), "value": integer ≥ 0 }
      • The sum of all subsection values must equal the task value
  • total_value (required, integer ≥ 0): Must equal the sum of all task values

§Success Response (200 OK)

{ "success": true, "message": "Mark allocator successfully saved.", "data": "{}" }

§Error Responses

  • 400 Bad Request – Invalid structure or values
  • 404 Not Found – Module or assignment directory does not exist
  • 500 Internal Server Error – Save failure