Function get_announcement

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

GET /api/modules/{module_id}/announcements/{announcement_id}

Retrieves a single announcement by ID for the specified module, including the authoring user.

§Path Parameters

  • module_id: The module the announcement belongs to.
  • announcement_id: The announcement ID to fetch.

§Behavior

  • Verifies the announcement belongs to the given module_id.
  • Eager-loads the related user (author) via the belongs_to User relation.
  • Returns 404 NOT FOUND if no matching announcement is found.

§Returns

  • 200 OK with { announcement, user } on success (user is { id, username } only).
  • 404 NOT FOUND if the announcement does not exist (or doesn’t belong to the module).
  • 500 INTERNAL SERVER ERROR on database errors.

§Example Responses

200 OK

{
  "success": true,
  "data": {
    "announcement": {
      "id": 42,
      "module_id": 101,
      "user_id": 5,
      "title": "Important update",
      "body": "Please note the following changes...",
      "pinned": true,
      "created_at": "2025-08-16T12:00:00Z",
      "updated_at": "2025-08-16T12:15:00Z"
    },
    "user": { "id": 5, "username": "lecturer" }
  },
  "message": "Announcement retrieved successfully"
}

404 NOT FOUND

{ "success": false, "message": "Announcement not found" }

500 INTERNAL SERVER ERROR

{ "success": false, "message": "Failed to retrieve announcement" }