ows-preference-center
=====================

The Orchard Web Service for Preference Center.


## 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

SECRET_KEY={secret_key}

# Snowflake credentials
SNOWFLAKE_ROLE=FANSIFTER_ENGINEERING
SNOWFLAKE_ACCOUNT=delphi.us-east-1
SNOWFLAKE_USER={username}@sonymusic-pde.com
SNOWFLAKE_DATABASE=PREFERENCE_CENTER
SNOWFLAKE_WAREHOUSE=DEV_OWS_WH
SNOWFLAKE_KEY_PASSPHRASE=
SNOWFLAKE_PRIVATE_KEY="{inlined private key here}"
SNOWFLAKE_SCHEMA={DEV_USERNAME}

# 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=
```

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

```bash
uv run uvicorn prefrerence_center.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://127.0.0.1:8001/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.
