Skip to content

List Organizations

Method

REST method is adopted.

HTTP Method

GET: List retrieval of organizations

Naming Convention

To unify naming of query parameters and nodes and improve readability, snake_case is used for URIs and nodes in JSON during requests.

Request and Response

Headers

Meta information is set in HTTP headers rather than in the response body.

Request Headers

  • Authorization: Bearer <access_token>
  • Content-Type: application/json

Response Headers

  • Content-Type: application/json

List Organizations

URI

/api/v1/organizations

Query Parameters

Name Type Default Description
page integer 1 Page number for pagination.
limit integer 10 Number of items per page. Maximum 100.
sort string updated_at:desc Sort field and direction (e.g. updated_at:desc, created_at:asc).

Response (200 OK)

Response is JSON.

{
  "currentPage": 1,
  "totalCount": 5,
  "list": [
    {
      "id": 1,
      "name": "Example Organization",
      "createdAt": 1640995200000,
      "updatedAt": 1640995200000,
      "createdBy": "1111-aaaa-2222-bbbb",
      "updatedBy": "1111-aaaa-2222-bbbb",
      "deletedAt": null,
      "deletedBy": null
    }
  ]
}

Authentication

Authentication is performed using JSON Web Tokens (JWT) issued by Amazon Cognito. A valid Bearer token is required in the Authorization header.

Exception Handling

Exception handling status codes are as follows.

Description Status Code Status Name
Missing or invalid token 401 Unauthorized
Internal server error 500 Internal Server Error

Process Flow

Sequence Diagram

sequenceDiagram
    participant Client
    participant Middleware as Protected Route Middleware
    participant API as Hono Router
    participant Service as Organization Service
    participant Repository as Organization Repository
    participant DB as PostgreSQL Database

    Client->>Middleware: GET /api/v1/organizations
    Middleware->>Middleware: Extract Bearer token
    Middleware->>Middleware: Verify JWT & session

    alt Token Valid
        Middleware-->>API: Auth info (sub, adminId)
        API->>Service: list(query)
        Service->>Repository: findAllPaginated(page, limit, sort)
        Repository->>DB: SELECT with pagination
        DB-->>Repository: Organization rows + count
        Repository-->>Service: Paginated result
        Service-->>API: Formatted list response
        API-->>Client: 200 OK { currentPage, totalCount, list }
    else Token Invalid
        Middleware-->>Client: 401 Unauthorized
    end

Routes Layer

API routing is performed here. The protectedRoute middleware validates the JWT token and session before the handler executes. The handler parses query parameters (page, limit, sort) with defaults and delegates to the organization service.

Source: apps/admin/src/routes/v1/organization.ts

Services Layer

This section describes business logic. It receives parsed query parameters, applies default values, and calls the repository to retrieve a paginated list of organizations. The result is formatted and returned with pagination metadata.

Source: apps/admin/src/services/organization.ts

Repositories Layer

This section describes access to databases and external services. It performs a parameterized SQL query with ORDER BY, LIMIT, and OFFSET clauses to fetch paginated organization records, along with a COUNT query for total items.

Source: apps/admin/src/repositories/organization.ts

Security

  • Token validated by protectedRoute middleware before handler execution
  • Session existence verified via verifySession
  • Query parameter values are sanitized to prevent injection