# `LightningWeb.API.ProjectController`
[🔗](https://github.com/OpenFn/lightning/blob/main/lib/lightning_web/controllers/api/project_controller.ex#L1)

The projects resource, for listing, showing, and creating or replacing
projects.

`GET /api/projects` is paginated. It takes `page` (default 1) and `page_size`
(default 10, at most 100).

`PUT /api/projects/:id` takes `name`, which is required, `description`,
`members` and `notify`, plus an optional `id` that must match the path. It
refuses any other key with a 422 `unknown_key` entry at that key.

`members` is a list of `{"email", "role"}` objects, where `role` is `viewer`,
`editor`, `admin` or `owner`. Exactly one member is the `owner`, and each
email must belong to an existing user.

`members` and `notify` apply only when the `PUT` creates the project.
`notify` defaults to `true` and emails each member added.

The `PUT` answers 201 when it creates the project and 200 when it replaces
one.

# `index`

```elixir
@spec index(Plug.Conn.t(), map()) :: Plug.Conn.t()
```

Lists all projects accessible to the authenticated user.

Returns a paginated list of projects that the current user or API token
has access to.

## Parameters

- `conn` - The Plug connection struct with the current resource assigned
- `params` - Map of query parameters for pagination

## Returns

- Renders JSON with paginated list of projects

## Examples

    GET /api/projects
    GET /api/projects?page=2&page_size=50

# `show`

```elixir
@spec show(Plug.Conn.t(), map()) :: Plug.Conn.t()
```

Shows a project to a caller who may access it.

A caller who isn't a member, a member who hasn't met its MFA requirement, and
a token without `projects:write` get 403. So does an id that names no
project, unless the caller is a superuser or the service account, who get
404 `not_found`. A project scheduled for deletion answers 409
`scheduled_for_deletion` to a caller who may see it.

## Examples

    GET /api/projects/a1b2c3d4-5e6f-7a8b-9c0d-1e2f3a4b5c6d

# `update`

```elixir
@spec update(Plug.Conn.t(), map()) :: Plug.Conn.t() | {:error, term()}
```

Creates the project under the path's id, or replaces the name and description
of the one that has it.

A refused body answers one 422 with every error in it, the body's keys, its
members and the project's own fields together.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
