ows-email-campaigns
=======

The Orchard Web Service for Audience Development Email Campaigns.

## Getting Started

### Installation

Make sure you have `uv` installed (https://docs.astral.sh/uv/getting-started/installation/).

```bash
curl -LsSf https://astral.sh/uv/install.sh | sh
```

or if `uv` already installed, ensure it is up to date:

```bash
uv self update
```

Prepare environment and install dependencies:

```bash
$ cd ows-email-campaigns
$ make env
```

### Running

Copy environment variables:

```bash
cp .env.shadow .env
```

Here is an example of the `.env` file:

```bash
APP_DEBUG=true
Environment=dev

# Postgres credentials
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_HOST=localhost
POSTGRES_PORT=5432
POSTGRES_NAME=dmp

# Redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_SSL=false

# Cache
CACHE_BACKEND=null
CACHE_REDIS_DB=1

# Auth
JWT_AUTH_ENABLED=false
AUTH_ALLOW_FULL_ACCESS=true

# Logging
LOG_FORMAT=console

# Infra
SENTRY_DSN=
```

When all dependencies have been installed, ensure you have a local instance of `PostgreSQL` is up and running.

```bash
docker compose up -d fansifter-postgres
```

Now you can run the FastAPI application on your local instance by running:

```bash
uv run uvicorn email_campaigns.api.asgi:app --reload --port=8001
```

or

```bash
make dev
```

Navigate to http://127.0.0.1:8001/docs to view Swagger UI.

---

All make commands will automatically install all dependencies in a virtual environment folder called env.

You can activate a virtual environment by running `source .venv/bin/activate`.

By using the development server, you will have access to specific features that
are not necessarily available in production, such as the exception tracer.

### Testing

To run the tests, all you have to do is to run:

```bash
(.venv) $ pytest tests/unit/
(.venv) $ pytest tests/integration/
```

or

To run unit tests: `make test`

To run unit tests with coverage reporting: `make test_unit`

To run integration tests: `make test_integration`

### OpenAPI specification

OpenAPI specification available for dev environment only.

Go to http://localhost:5000/docs to view Swagger UI.

To generate `OpenAPI YAML`:

```bash
$ make openapi
```

### Linting

To lint: `make lint`

To format: `make fmt`

### Third-Party Integrations for Reporting

This boilerplate comes with support for Sentry, and Datadog.

### Generate translation file

```bash
uv run python -m fansifter_common.translation.cli export -p 740930 -t  <POEDITOR_TOKEN>
```
