API server powered by Node.js, TypeScript, Prisma, and MySQL, designed for the D3Hiring project.
- Prerequisites
- Installation
- Running the Server
- Deploying to Google Cloud Run
- Running Tests
- Hosted API
- API Documentation
- Authors
- License
Ensure you have the following installed on your system:
- Docker & Docker Compose (for Docker installation)
- MySQL (for local installation)
- Node.js
- Git
-
Clone the Repository:
git clone https://github.com/alexaung/d3hiring.git cd d3hiring
-
Set Up Docker Containers:
docker-compose up -d
This command will start the API server and MySQL database as described in the docker-compose.yml file.
-
Database Migrations:
After the services are up, you can execute migrations with:
docker-compose exec app npx prisma migrate deploy
-
Clone the Repository:
git clone https://github.com/alexaung/d3hiring.git cd d3hiring
-
Install Dependencies:
npm install
-
Generate Prisma Client:
This will generate necessary client files for Prisma.
npx prisma generate
-
Run Database Migrations:
First, ensure your MySQL service is running. Then, run:
npx prisma migrate deploy
With the containers up and running, the API server will be accessible at:
http://localhost:3000
This guide outlines the steps to deploy a Docker containerized application to Google Cloud Run using the Google Cloud SDK (gcloud
) and Docker.
Before you begin, make sure you have the following:
- A Google Cloud Platform (GCP) account
- Docker installed on your local machine
- Google Cloud SDK (
gcloud
) installed on your local machine - Necessary database configurations and credentials for Cloud SQL.
-
Authenticate with Google Cloud:
gcloud auth login
This command will open a browser window and prompt you to log in to your GCP account. Follow the instructions to authenticate.
-
Set Project Configuration:
gcloud config set project <PROJECT_ID>
Replace
<PROJECT_ID>
with your actual GCP project ID. This sets the active project for the `gcloud`` command-line tool. -
Build and Push Docker Image::
Build a Docker image for your application and push it to Google Container Registry (GCR). Run the following commands in your project directory:
docker build -t gcr.io/PROJECT_ID/IMAGE_NAME:latest . docker push gcr.io/PROJECT_ID/IMAGE_NAME:latest
Replace
PROJECT_ID
with your GCP project ID andIMAGE_NAME
with a name for your Docker image. -
Deploy to Google Cloud Run: Deploy your application to Google Cloud Run using the following command:
gcloud run deploy SERVICE_NAME --image gcr.io/PROJECT_ID/IMAGE_NAME:latest --platform managed --region REGION --allow-unauthenticated
Replace
SERVICE_NAME
,PROJECT_ID
,IMAGE_NAME
, andREGION
with appropriate values. The --allow-unauthenticated flag allows public access to the deployed service.
To run the unit tests for the API, use the following command:
npm test
The API is hosted on Google Cloud Run and uses Cloud SQL for the database. Please note that this hosted version is configured with minimum capacity for testing purposes only.
- API Base URL:
https://d3hiring-dwx6gkx3sq-uc.a.run.app/
Please use this link for testing and evaluation purposes. If you intend to deploy the API for production use, make sure to adjust the configuration and capacity accordingly.
Here's a detailed overview of the available endpoints:
-
Register Students to a Teacher* (
POST /api/register
)Description: This endpoint allows a teacher to register one or more students to their class.
Request:
{ "teacher": "[email protected]", "students": [ "[email protected]", "[email protected]" ] }
Response:
- Status Code:
204 No Content
- Description: The request was successful.
- Status Code:
-
Retrieve Common Students* (
GET /api/commonstudents
)Description: This endpoint retrieves a list of students who are common to the given list of teachers.
Request:
- Method: GET
- Query Parameters:
teacher
: Teacher's email (multiple values allowed).
- Example:
GET /api/commonstudents?teacher=teacherken%40gmail.com&teacher=teacherjoe%40gmail.com
Response:
- Status Code:
200 OK
- Body:
{ "students": [ "[email protected]", "[email protected]" ] }
-
Suspend a Student* (
POST /api/suspend
)Description: This endpoint allows a teacher to suspend a specified student.
Request:
{ "student" : "[email protected]" }
Response:
- Status Code:
204 No Content
- Description: The request was successful.
- Status Code:
-
Retrieve Student Recipients for a Notification* (
POST /api/retrievefornotifications
)Description: This endpoint allows a teacher to retrieve a list of students who can receive a given notification.
Request:
{ "teacher": "[email protected]", "notification": "Hello students! @[email protected] @[email protected]" }
Response:
- Status Code:
200 OK
- Body:
{ "recipients": [ "[email protected]", "[email protected]", "[email protected]" ] }
- Status Code:
Alex Aung Myo OO
This project is licensed under the MIT License. See the LICENSE
file for details.