Function edit_module

Source
pub async fn edit_module(
    __arg0: State<AppState>,
    __arg1: Path<i64>,
    __arg2: Json<ModuleRequest>,
) -> impl IntoResponse
Expand description

PUT /api/modules/{module_id}

Update the details of a specific module by its ID.
Only accessible by admin users.

§Request Body

{
  "code": "CS101",
  "year": 2024,
  "description": "Introduction to Computer Science",
  "credits": 15
}

§Validation Rules

  • code: must be in format ABC123 (3 uppercase letters + 3 digits)
  • year: must be current year or later
  • description: must be at most 1000 characters
  • credits: must be a positive number

§Responses

  • 200 OK
{
  "success": true,
  "data": {
    "id": 1,
    "code": "CS101",
    "year": 2024,
    "description": "Introduction to Computer Science",
    "credits": 15,
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z"
  },
  "message": "Module updated successfully"
}
  • 400 Bad Request
{
  "success": false,
  "data": null,
  "message": "Module code must be in format ABC123"
}
  • 403 Forbidden
{
  "success": false,
  "data": null,
  "message": "You do not have permission to perform this action"
}
  • 404 Not Found
{
  "success": false,
  "data": null,
  "message": "Module not found"
}
  • 409 Conflict
{
  "success": false,
  "data": null,
  "message": "Module code already exists"
}