Skip to content

Commit 5136634

Browse files
authored
Merge pull request #19 from topcoder-platform/develop
syncing dev to master
2 parents 7fd6df1 + fc6706c commit 5136634

File tree

96 files changed

+15864
-126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+15864
-126
lines changed

.circleci/config.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
version: 2.1
2+
3+
defaults: &defaults
4+
docker:
5+
- image: cimg/python:3.13.2-browsers
6+
install_dependency: &install_dependency
7+
name: Installation of build and deployment dependencies.
8+
command: |
9+
sudo apt update
10+
sudo apt install -y jq python3-pip
11+
sudo pip3 install awscli --upgrade
12+
install_deploysuite: &install_deploysuite
13+
name: Installation of install_deploysuite.
14+
command: |
15+
git clone --branch v1.4.19 https://github.com/topcoder-platform/tc-deploy-scripts ../buildscript
16+
cp ./../buildscript/master_deploy.sh .
17+
cp ./../buildscript/buildenv.sh .
18+
cp ./../buildscript/awsconfiguration.sh .
19+
cp ./../buildscript/psvar-processor.sh .
20+
21+
builddeploy_steps: &builddeploy_steps
22+
- checkout
23+
- setup_remote_docker
24+
- run: *install_dependency
25+
- run: *install_deploysuite
26+
- run: docker buildx build --no-cache=true -t ${APPNAME}:latest .
27+
- run:
28+
name: Running MasterScript.
29+
command: |
30+
./awsconfiguration.sh $DEPLOY_ENV
31+
source awsenvconf
32+
./psvar-processor.sh -t appenv -p /config/${APPNAME}/deployvar
33+
source deployvar_env
34+
./master_deploy.sh -d ECS -e $DEPLOY_ENV -t latest -j /config/${APPNAME}/appvar,/config/common/global-appvar -i ${APPNAME} -p FARGATE
35+
36+
jobs:
37+
# Build & Deploy against development backend
38+
"build-dev":
39+
!!merge <<: *defaults
40+
environment:
41+
DEPLOY_ENV: "DEV"
42+
LOGICAL_ENV: "dev"
43+
APPNAME: "reports-api-v6"
44+
DEPLOYMENT_ENVIRONMENT: 'dev'
45+
steps: *builddeploy_steps
46+
47+
"build-prod":
48+
!!merge <<: *defaults
49+
environment:
50+
DEPLOY_ENV: "PROD"
51+
LOGICAL_ENV: "prod"
52+
APPNAME: "reports-api-v6"
53+
DEPLOYMENT_ENVIRONMENT: 'prod'
54+
steps: *builddeploy_steps
55+
56+
workflows:
57+
version: 2
58+
build:
59+
jobs:
60+
# Development builds are executed on "develop" branch only.
61+
- "build-dev":
62+
context: org-global
63+
filters:
64+
branches:
65+
only:
66+
- develop
67+
- pm-1127_1
68+
69+
# Production builds are exectuted only on tagged commits to the
70+
# master branch.
71+
- "build-prod":
72+
context: org-global
73+
filters:
74+
branches:
75+
only:
76+
- master

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = true
13+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: AI PR Reviewer
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- synchronize
8+
permissions:
9+
pull-requests: write
10+
jobs:
11+
tc-ai-pr-review:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout Repo
15+
uses: actions/checkout@v3
16+
17+
- name: TC AI PR Reviewer
18+
uses: topcoder-platform/tc-ai-pr-reviewer@master
19+
with:
20+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # The GITHUB_TOKEN is there by default so you just need to keep it like it is and not necessarily need to add it as secret as it will throw an error. [More Details](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret)
21+
LAB45_API_KEY: ${{ secrets.LAB45_API_KEY }}
22+
exclude: '**/*.json, **/*.md, **/*.jpg, **/*.png, **/*.jpeg, **/*.bmp, **/*.webp' # Optional: exclude patterns separated by commas

Dockerfile

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# ---- Base Stage ----
2+
FROM node:20-alpine AS base
3+
WORKDIR /usr/src/app
4+
5+
# ---- Dependencies Stage ----
6+
FROM base AS deps
7+
# Install pnpm
8+
RUN npm install -g pnpm
9+
# Copy dependency-defining files
10+
COPY package.json pnpm-lock.yaml ./
11+
# Install dependencies
12+
RUN pnpm install --frozen-lockfile --prod
13+
14+
# ---- Build Stage ----
15+
FROM base AS build
16+
RUN npm install -g pnpm
17+
COPY --from=deps /usr/src/app/node_modules ./node_modules
18+
COPY . .
19+
# Build the application
20+
RUN pnpm build
21+
22+
# ---- Production Stage ----
23+
FROM base AS production
24+
ENV NODE_ENV production
25+
# Copy built application from the build stage
26+
COPY --from=build /usr/src/app/dist ./dist
27+
COPY --from=build /usr/src/app/sql ./sql
28+
COPY --from=build /usr/src/app/data ./data
29+
# Copy production dependencies from the deps stage
30+
COPY --from=deps /usr/src/app/node_modules ./node_modules
31+
32+
# Expose the application port
33+
EXPOSE 3000
34+
35+
# The command to run the application
36+
CMD ["node", "dist/main.js"]

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
## Description
2+
3+
This repository houses the reports API for all Topcoder and Topgear reports on the Topcoder platform. The reports are pulled directly from live data, not a data warehouse, so they should be up-to-date when they are generated and the response is returned.
4+
5+
All reports will return JSON data with the expected fields for the individual report
6+
7+
## Security
8+
9+
Currently, an M2M token is required to pull any report, and each report has its own scope associated with it that must be applied to the M2M token client ID
10+
11+
## Layout
12+
13+
Each report will be a separate SQL query, potentially with a few parameters (like a start and an end date, for example). The individual SQL queries can be found in the `sql` folder and should be able to be run against the `topcoder-services` RDS database in dev or prod, with minimal changes to replace the parameters.
14+
15+
## Technology Stack
16+
17+
- **Framework**: NestJS
18+
- **Language**: TypeScript
19+
- **Database**: PostgreSQL
20+
- **ORM**: Prisma
21+
- **Package Manager**: pnpm
22+
23+
## Prerequisites
24+
25+
- Node.js (v22 or later recommended)
26+
- pnpm
27+
28+
## Getting Started
29+
30+
### 1. Clone the Repository
31+
32+
```bash
33+
git clone <repository-url>
34+
cd reports-api-v6
35+
```
36+
37+
### 2. Install Dependencies
38+
39+
This project uses pnpm as the package manager. Ensure you have it installed, then run:
40+
41+
```bash
42+
pnpm install
43+
```
44+
### 4. Configure Environment Variables
45+
46+
Create a `.env` file in the root of the project. You can copy the example structure below. The default values are configured to work with the local Docker setup.
47+
48+
```bash
49+
# .env
50+
51+
# PostgreSQL Database URL for Prisma
52+
# This is used by Prisma to connect to your local PostgreSQL instance.
53+
DATABASE_URL="postgresql://user:password@localhost:5432/lookups?schema=public"
54+
55+
# ---------------------------------------------------
56+
# JWT Authentication Secrets
57+
# These are used by tc-core-library-js for validating JWTs.
58+
# ---------------------------------------------------
59+
60+
# The secret key used to sign and verify JWTs.
61+
AUTH_SECRET="mysecret"
62+
63+
# A JSON array string of valid token issuers.
64+
VALID_ISSUERS='["https://topcoder-dev.auth0.com/","https://api.topcoder.com"]'
65+
66+
## Running the Application
67+
68+
### Development Mode
69+
70+
To run the application in development mode with hot-reloading:
71+
72+
```bash
73+
pnpm run dev
74+
```
75+
76+
The application will be available at http://localhost:3000.
77+
78+
## Public Statistics Endpoints
79+
80+
The following read-only endpoints are available without authentication to support the Community Statistics page.
81+
82+
- `GET /v6/reports/statistics/srm/top-rated` — Highest rated SRM data (static JSON)
83+
- `GET /v6/reports/statistics/srm/country-ratings` — SRM country ratings (static JSON)
84+
- `GET /v6/reports/statistics/srm/competitions-count` — SRM number of competitions (static JSON)
85+
- `GET /v6/reports/statistics/mm/top-rated` — Highest rated Marathon Match data (static JSON)
86+
- `GET /v6/reports/statistics/mm/country-ratings` — Marathon Match country ratings (static JSON)
87+
- `GET /v6/reports/statistics/mm/top-10-finishes` — Marathon Match Top 10 finishes (static JSON)
88+
- `GET /v6/reports/statistics/mm/competitions-count` — Marathon Match number of competitions (static JSON)
89+
90+
Static datasets are stored under `data/statistics/srm` and `data/statistics/mm` and are packaged into the ECS image in the Dockerfile.

0 commit comments

Comments
 (0)