Function create_message

Source
pub async fn create_message(
    __arg0: Path<(i64, i64, i64)>,
    __arg1: State<AppState>,
    __arg2: Extension<AuthUser>,
    __arg3: Json<Value>,
) -> impl IntoResponse
Expand description

POST /api/modules/{module_id}/assignments/{assignment_id}/tickets/{ticket_id}/messages

Create a new message in a ticket and broadcast a WebSocket event on: ws/tickets/{ticket_id}

§Path Parameters

  • module_id (i64)
  • assignment_id (i64)
  • ticket_id (i64)

§Request Body (JSON)

{ “content”: “Can someone review my latest attempt?” }

§Responses

  • 200 OK → Message created successfully
{
  "success": true,
  "data": {
      "id": 123,
      "ticket_id": 456,
      "content": "Message content here",
      "created_at": "2025-08-18T10:00:00Z",
      "updated_at": "2025-08-18T10:00:00Z",
      "user": { "id": 789, "username": "john_doe" }
  },
  "message": "Message created successfully"
}
  • 400 Bad Request → Content missing or empty
{
  "success": false,
  "data": null,
  "message": "Content is required"
}
  • 403 Forbidden → User not authorized to create a message for this ticket
{
  "success": false,
  "data": null,
  "message": "Forbidden"
}
  • 404 Not Found → User not found
{
  "success": false,
  "data": null,
  "message": "User not found"
}
  • 500 Internal Server Error → Failed to create the message
{
  "success": false,
  "data": null,
  "message": "Failed to create message"
}