-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feature: initial routers / methods for favourites - add env documentation / adminer image for easier inspection of db - create / delete favourite entry in database - fetch list of favourites by user * Chore: update formatting, tests * update test methods / logging - * updates * expand tests / logging
- Loading branch information
1 parent
c71ae3a
commit cd47b8d
Showing
26 changed files
with
1,075 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Authentication | ||
TENANT_ID="<microsoft-entra-tenant-id>" | ||
CLIENT_ID="<app-id>" | ||
API_KEY="<strong-password>" # for accessing "public" endpoints | ||
|
||
# Database and Storage | ||
DB_CONNECTION="postgresql://<user>:<password>@<host>:5432/<staging|production>" | ||
SAS_URL="https://<account-name>.blob.core.windows.net/<container-name>?<sas-token>" | ||
|
||
# Azure OpenAI, only required for `/signals/generation` | ||
AZURE_OPENAI_ENDPOINT="https://<subdomain>.openai.azure.com/" | ||
AZURE_OPENAI_API_KEY="<api-key>" | ||
|
||
# Testing, only required to run tests, must be a valid token of a regular user | ||
API_JWT="<json-token>" | ||
|
||
# News API | ||
# https://newsapi.org/account | ||
NEWS_API_KEY="<api-key>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
TENANT_ID= | ||
CLIENT_ID= | ||
API_KEY= | ||
|
||
DB_CONNECTION= | ||
SAS_URL= | ||
|
||
AZURE_OPENAI_ENDPOINT= | ||
AZURE_OPENAI_API_KEY= | ||
|
||
API_JWT= | ||
|
||
NEWS_API_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -140,3 +140,5 @@ cython_debug/ | |
# Manually added for this project | ||
.idea/ | ||
**/.DS_Store | ||
sql/create_test_user.sql | ||
Taskfile.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
FROM python:3.11.7-slim | ||
|
||
# Install system dependencies | ||
RUN apt-get update -y \ | ||
&& apt-get install libpq-dev -y \ | ||
&& apt-get install -y \ | ||
libpq-dev \ | ||
postgresql-client \ | ||
curl \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
WORKDIR /app | ||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir --upgrade -r requirements.txt | ||
|
||
# Install Python dependencies including development dependencies | ||
COPY requirements.txt requirements_dev.txt ./ | ||
RUN pip install --no-cache-dir --upgrade -r requirements.txt -r requirements_dev.txt | ||
|
||
# Copy application code | ||
COPY . . | ||
|
||
EXPOSE 8000 | ||
|
||
# Add healthcheck | ||
HEALTHCHECK --interval=30s --timeout=30s --start-period=5s --retries=3 \ | ||
CMD curl --fail http://localhost:8000/signals/search || exit 1 | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ format: | |
lint: | ||
pylint main.py src/ | ||
test: | ||
python -m pytest tests/ | ||
python -m pytest tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from setuptools import find_packages, setup | ||
|
||
setup( | ||
name="ftss-api", | ||
version="0.1", | ||
packages=find_packages(), | ||
install_requires=[ | ||
"fastapi", | ||
"uvicorn", | ||
"psycopg", | ||
"pydantic", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
The initialisation script to create test data for local development. | ||
This script is automatically executed by docker compose after create_tables.sql | ||
and import_data.sql. | ||
*/ | ||
|
||
-- Create test users | ||
INSERT INTO users ( | ||
id, | ||
created_at, | ||
email, | ||
role, | ||
name, | ||
unit, | ||
acclab, | ||
api_key | ||
) VALUES ( | ||
1, -- This ID is expected by the test suite | ||
NOW(), | ||
'[email protected]', | ||
'ADMIN', | ||
'Test User', | ||
'Data Futures Exchange (DFx)', | ||
false, | ||
'test-key' | ||
); | ||
|
||
-- Reset the sequence to start after our manually inserted IDs | ||
SELECT setval('users_id_seq', (SELECT MAX(id) FROM users)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
CREATE OR REPLACE FUNCTION insert_test_signals() | ||
RETURNS void AS $$ | ||
DECLARE | ||
signals jsonb; | ||
signal_record jsonb; | ||
BEGIN | ||
-- Read the JSON file | ||
signals := (pg_read_file('/docker-entrypoint-initdb.d/test_data.json')::jsonb)->'signals'; | ||
|
||
-- Loop through each signal and insert | ||
FOR signal_record IN SELECT * FROM jsonb_array_elements(signals) LOOP | ||
WITH arrays AS ( | ||
SELECT | ||
array(SELECT * FROM jsonb_array_elements_text(signal_record->'keywords')) as keywords, | ||
array(SELECT * FROM jsonb_array_elements_text(signal_record->'steep_secondary')) as steep_secondary, | ||
array(SELECT * FROM jsonb_array_elements_text(signal_record->'signature_secondary')) as signature_secondary, | ||
array(SELECT * FROM jsonb_array_elements_text(signal_record->'sdgs')) as sdgs | ||
) | ||
INSERT INTO signals ( | ||
status, created_by, modified_by, headline, description, url, | ||
relevance, keywords, location, steep_primary, steep_secondary, | ||
signature_primary, signature_secondary, sdgs, created_unit | ||
) | ||
SELECT | ||
signal_record->>'status', | ||
signal_record->>'created_by', | ||
signal_record->>'modified_by', | ||
signal_record->>'headline', | ||
signal_record->>'description', | ||
signal_record->>'url', | ||
signal_record->>'relevance', | ||
keywords, | ||
signal_record->>'location', | ||
signal_record->>'steep_primary', | ||
steep_secondary, | ||
signal_record->>'signature_primary', | ||
signature_secondary, | ||
sdgs, | ||
signal_record->>'created_unit' | ||
FROM arrays; | ||
END LOOP; | ||
END; | ||
$$ LANGUAGE plpgsql; |
Oops, something went wrong.