# dna-cms
DNA CMS (Managed by Terraform)

## Overwiew.
The main goal of the `dna-cms` service is to allow you to exclude different artists and labels from dna. To do this, you should add the artist or label in the corresponding view. It will save a new field in the `PostgreSQL` database, and after the `ETL` service launches again, it will extract the newly added artists or labels and exclude them from dna.

Additionally, you can find some additional information such as the `signed artist report`, which includes all required information about signed artists, and when they were became signed, and the quantity of `non-signed artists` and `non-signed-tracks` in dna.

## Requirements:
**1.** Python 3.10
**2.** Docker
**3.** Docker-compose
**4.** PostgreSQL

## Local launch.
We are using `proxy` pip index, and if you want to install requirements locally you should use `pip` configuration from `configs` folder.

To launch `dna-cms` on local machine you should:
**-** Install Docker and Docker-compose
**-** Check the `.env` file for all required environment variables, all the  necessary variables are listed in `.env.sample`
**-** Run: `docker-compose up --build`
**-** Go to `0.0.0.0:8000`: and log in. It will redirect you to `atlas` login page, ent er `dna` user and password.

## Migrations.
`dna-cms` uses the `Flask-Migrate` extension for Flask, based on Alembic. To make a migration, you should:
**1.** Create a new migration repository with the following command: python -m flask db init (should be executed only once)
**2.**  Make some changes to the models, then create a migration: `python -m flask db migrate`
**3.**  Apply your migration - `python -m flask db upgrade`

## Endpoints:
**1.** `/login` - login endpoint which redirects you to `atlas` login page
**2.** `/logout` - logout endpoint which redirects you to `atlas` logout page

## Endpoints which is using by `ETL` service:
**1.** excluded artist list:
- `/artist_list` GET - return the list of all artist names to be excluded by `ETL`

            Response: ["name_1", "name_2" ...]

**2.** excluded label list and strict exluded label list:
- `/label_list` GET, full_match=True|False - return the list of all label names to be excluded by `ETL`, full_match = True, by default

            Response: ["name_1", "name_2" ...]

**3.** `data_upload` step:
- `/last_data` GET - endpoint which is returning the last row of `non-signed-artist` and `non-signed-track` tables

            Response: {
                "artist": {
                    "total_nsa": int,
                    "created_at": datetime
                },
                "track": {
                    "new_nst": int,
                    "created_at": datetime
                }
            }

- `last_data` POST - endpoint which is saving data to `non-signed-artist` and `non-signed-track` tables

            Request: {
                "artist": {
                    "total_nsa": int,
                    "new_nsa": int,
                    dropped_nsa": int
                },
                "track": {
                    "total_nst": int,
                    "new_nst": int
                }
            }

            Response: {
                "artist: {"id": int},
                "track: {"id": int}
            }
**4.** `weekly_report` step:
- `/weekly_report_data` GET - returns cretion time of last row

            Response : {"created_at": datetime}

- `/weekly_report_data` POST - save data to `weekly_report` table

            Request: {
                "artist_name": str,
                "drop_off_date": datetime,
                "release_date": date,
                "label": str
                "album_type": str
                "tiktok_verified": bool
                "tiktok_followers": int
                "popularity_score": int
                "spotify_followers": int
                "spotify_link": str
                "dna_link": str
                "chartmetric_link": str
            }

            Response: {"id": int}

## Views:
**1.** `/` - Home page
**2.** `/artist` - view to exculde artist
**3.** `/label` - view to exculde label
**4.** `/signed_artist_report` - view to get info about signed artists for dev and qa envs only
**5.** `/upload` - upload basic excluded artists and labels to database
**6.** `/sync` - remove all rows from `Artist` and `Label` tables, and uploads data from `Artist` and `Label` tables from `PROD` env
