Skip to content

Commit

Permalink
Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
alexaungmyooo committed Aug 8, 2023
0 parents commit f9455d0
Show file tree
Hide file tree
Showing 21 changed files with 1,383 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Environment variables declared in this file are automatically made available to Prisma.
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema

# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

NODE_ENV=development
NODE_PORT=3000
DATABASE_URL=mysql://USER:PASSWORD@HOST:PORT/DATABASE?schema=public
35 changes: 35 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Ignore Node.js build files
node_modules/

# Ignore TypeScript build artifacts
/dist/
*.tsbuildinfo

# Ignore Prisma artifacts
/prisma/client/

# Ignore editor-specific files
.vscode/
*.sublime-project
*.sublime-workspace
*.idea/

# Ignore log files
*.log

# Ignore environment-specific files
.env

# Ignore package lock files
package-lock.json
yarn.lock

# Ignore OS-specific files
.DS_Store
Thumbs.db

# Ignore coverage reports (if you have tests and generate coverage reports)
/coverage/

# Ignore build artifacts from CI/CD
/build/
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use the specified image as the base
FROM node:18-alpine

# Set the working directory in the container
WORKDIR /app

# Install Prisma CLI
RUN npm install -g prisma

# Copy the package.json and package-lock.json first to leverage Docker cache
COPY package.json package-lock.json ./

# Install the dependencies
RUN npm install

# Copy the rest of the application
COPY . .

# Generate Prisma client for this environment
RUN npx prisma generate

# Expose port 8080 for the app
EXPOSE 8080

# Run the app when the container launches
CMD [ "npm", "start" ]
206 changes: 206 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
# D3Hiring API Server

API server powered by Node.js, TypeScript, Prisma, and MySQL, designed for the D3Hiring project.

## Table of Contents

- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Using Docker](#using-docker)
- [Locally Without Docker](#locally-without-docker)
- [Running the Server](#running-the-server)
- [Running Tests](#running-tests)
- [Hosted API](#hosted-api)
- [API Documentation](#api-documentation)
- [Authors](#authors)
- [License](#license)

## Prerequisites

Ensure you have the following installed on your system:

- Docker & Docker Compose (for Docker installation)
- MySQL (for local installation)
- Node.js
- Git

## Installation

### Using Docker

**1. Clone the Repository:**

```bash
git clone https://github.com/alexaung/d3hiring.git
cd d3hiring
```

**2. Set Up Docker Containers:**

```bash
docker-compose up -d
```

This command will start the API server and MySQL database as described in the docker-compose.yml file.

**3. Database Migrations:**

After the services are up, you can execute migrations with:

```bash
docker-compose exec app npx prisma migrate deploy
```

### Locally Without Docker

**1. Clone the Repository:**

```bash
git clone https://github.com/alexaung/d3hiring.git
cd d3hiring
```

**2. Install Dependencies:**

```bash
npm install
```

**3. Generate Prisma Client:**

This will generate necessary client files for Prisma.

```bash
npx prisma generate
```

**4. Run Database Migrations:**

First, ensure your MySQL service is running. Then, run:

```bash
npx prisma migrate deploy
```

## Running the Server

With the containers up and running, the API server will be accessible at:

```bash
http://localhost:3000
```
## Running Tests

To run the unit tests for the API, use the following command:

```bash
npm test
```

## Hosted API

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.

## API Documentation

Here's a detailed overview of the available endpoints:

***1. Register Students to a Teacher*** (`POST /api/register`)

**Description**: This endpoint allows a teacher to register one or more students to their class.

**Request:**

```json
{
"teacher": "[email protected]",
"students": [
"[email protected]",
"[email protected]"
]
}
```

**Response:**

- Status Code: `204 No Content`
- Description: The request was successful.

***2. 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:

```json
{
"students": [
"[email protected]",
"[email protected]"
]
}
```

***3. Suspend a Student*** (`POST /api/suspend`)

**Description**: This endpoint allows a teacher to suspend a specified student.

**Request:**

```json
{
"student" : "[email protected]"
}
```

**Response:**
- Status Code: `204 No Content`
- Description: The request was successful.

***4. 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:**

```json
{
"teacher": "[email protected]",
"notification": "Hello students! @[email protected] @[email protected]"
}
```

**Response:**
- Status Code: `200 OK`
- Body:

```json
{
"recipients": [
"[email protected]",
"[email protected]",
"[email protected]"
]
}
```

## Authors

Alex Aung Myo OO

## License

This project is licensed under the MIT License. See the `LICENSE` file for details.
Loading

0 comments on commit f9455d0

Please sign in to comment.