Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containerization, Docker #2

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cdd1fe5
Initial commit
mserykh Jul 12, 2022
e2b0af7
feat: add an in-memory database, implement getting all users and a us…
mserykh Jul 12, 2022
029831f
refactor: add test entries, adjust user methods
mserykh Jul 12, 2022
63bfdc0
docs: update db
mserykh Jul 12, 2022
da4c7bf
feat: implement updating user's password
mserykh Jul 12, 2022
23cee20
feat: implement deleting a user
mserykh Jul 12, 2022
9b29bb8
feat: implement request validation
mserykh Jul 12, 2022
a511689
feat: implement creating a new user
mserykh Jul 12, 2022
fdb0c33
docs: define env variables loading
mserykh Jul 12, 2022
a42ed3f
refactor: clean code
mserykh Jul 12, 2022
f518968
feat: implement CRUD operations for artists
mserykh Jul 12, 2022
6ec62f1
refactor: clean code
mserykh Jul 12, 2022
2c10f68
feat: implement CRUD operations for albums
mserykh Jul 12, 2022
e78756f
feat: implement CRUD oparetions for tracks
mserykh Jul 13, 2022
d93d2ca
refactor: refactor user
mserykh Jul 13, 2022
f1d4947
refactor: clean code
mserykh Jul 13, 2022
c7d1db1
refactor: refactor uuid validation
mserykh Jul 13, 2022
943d3ef
feat: implement getting all favorites and adding artist to favorites
mserykh Jul 13, 2022
6945d76
refactor: refactor favorites
mserykh Jul 14, 2022
8833c47
fix: hotfix for update artist test
AlreadyBored Jul 13, 2022
aa86927
feat: implement adding and deleting favorites
AlreadyBored Jul 13, 2022
5592153
feat: implement handling adding items to favorites that do not exist …
mserykh Jul 14, 2022
9acd984
fix: fix deleting albums, artists, tracks
mserykh Jul 15, 2022
a1dcf51
refactor: clean code
mserykh Jul 15, 2022
f7add50
refactor: clean code
mserykh Jul 15, 2022
58dd9a5
feat: implement deleting references in entities
mserykh Jul 15, 2022
c9046bb
feat: generate swagger docs and adjust docs
mserykh Jul 17, 2022
b52891f
refactor: refactor album, artist and track validationand entities cre…
mserykh Jul 17, 2022
8812023
docs: update `README.md`
mserykh Jul 17, 2022
54d5c08
docs: update `README.md`
mserykh Jul 17, 2022
684ec5c
feat: add `Dockerfile`
mserykh Jul 23, 2022
c7de8a1
feat: add `.dockerignore`
mserykh Jul 23, 2022
c611cf0
feat: add `Dockerfile` for database
mserykh Jul 23, 2022
9c03723
feat: start with `docker-compose`
mserykh Jul 24, 2022
bd8944d
chore: refactor the file
mserykh Jul 24, 2022
b38d828
feat: add db to a container and variables
mserykh Aug 1, 2022
681345b
refactor: refactor images
mserykh Aug 3, 2022
8c0eaa7
docs: update `README.md`
mserykh Aug 3, 2022
dd6c281
fix: add network to `app`
mserykh Aug 6, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
node_modules
Dockerfile
.dockerignore
.git
.gitignore
dist
test
pgdata
6 changes: 6 additions & 0 deletions .env.example → .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
PORT=4000

POSTGRES_PORT=5432

POSTGRES_USER=admin
POSTGRES_PASSWORD=postgresadmin
POSTGRES_DB=postgresdb

CRYPT_SALT=10
JWT_SECRET_KEY=secret123123
JWT_SECRET_REFRESH_KEY=secret123123
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# compiled output
/dist
/node_modules
/pgdata

# Logs
logs
Expand Down
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:16-alpine
WORKDIR /usr/app
COPY package*.json .
RUN npm ci
COPY . ./
ENV PORT 4000
EXPOSE $PORT
CMD ["npm", "run", "start:dev"]
101 changes: 73 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,117 @@
# Home Library Service

Home Library Service is REST API offering Create, Read, Update, and Delete (CRUD) handlers.

## Prerequisites

- Git - [Download & Install Git](https://git-scm.com/downloads).
- Node.js - [Download & Install Node.js](https://nodejs.org/en/download/) and the npm package manager.
- Docker - [Download & Install Docker](https://www.docker.com/get-started/).

## Installation

## Downloading
- Clone this repository

```
git clone {repository URL}
git clone {repository}
```

## Installing NPM modules
- Go to `nodejs2022Q2-service`

```
npm install
cd nodejs2022Q2-service
```

## Running application
- Install all dependencies

```
npm start
npm install
```

After starting the app on port (4000 as default) you can open
in your browser OpenAPI documentation by typing http://localhost:4000/doc/.
For more information about OpenAPI/Swagger please visit https://swagger.io/.
- Start application in production mode

## Testing
```
npm run start:prod
```

After application running open new terminal and enter:
- After starting the app on port (4000 as default) you can open
in your browser OpenAPI documentation by typing http://localhost:4000/doc/.

To run all tests without authorization
### Run App with Docker

```
npm run test
docker-compose up
```

To run only one of all test suites
### Download Docker Images

[See on Docker hub](https://hub.docker.com/repository/docker/marieserykh/nodejs2022q2_service)

```
npm run test -- <path to suite>
docker pull marieserykh/nodejs2022q2_service:app
```

To run all test with authorization

```
npm run test:auth
docker pull marieserykh/nodejs2022q2_service:postgres
```

To run only specific test suite with authorization

### Vulnarability scanning

```
npm run test:auth -- <path to suite>
npm run scan:app
```

### Auto-fix and format

```
npm run lint
npm run scan:db
```


## Usage

### Routing

Collections are: `user`, `album`, `artist`, `track`, `favs`

- `GET` `/{collection}`: Returns all resources of this collestion

- `POST` `/{collection}`: Creates a resource of the collection, then returns with ID

- `POST` `/favs/album/:id`: Adds an album to favourites
- `POST` `/favs/artist/:id`: Adds an artist to favourites
- `POST` `/favs/track/:id`: Adds a track to favourites

- `PUT` `/{collection}/:id`: Updates the resource of the collection with that ID

- `DELETE` `/{collection}/:id`: Deletes the resource of the collection with that ID

- `DELETE` `/favs/album/:id`: Deletes the album from favourites
- `DELETE` `/favs/artist/:id`: Deletes the artist from favourites
- `DELETE` `/favs/track/:id`: Deletes the track from favourites

### HTTP status codes

- `201` when creating
- `200` when getting and updating
- `204` when deleting
- `400` when trying to get a non-existant resource (id)
- `400` when providing invalid id (not uuid) or invalid request body
- `403` when providing incorrect old password
- `404` if either the collection of data you are POSTing to (e.g. genre in the URLs) is unknown or you are trying to get a non-existant resource (id)
- `422` when providing a reference in request body to a non-existant resource

## Testing

After application running open new terminal and enter:

- to run all tests without authorization

```
npm run format
npm run test
```

### Debugging in VSCode
- to run only one of all test suites

Press <kbd>F5</kbd> to debug.

For more information, visit: https://code.visualstudio.com/docs/editor/debugging
```
npm run test -- <path to suite>
```
1 change: 1 addition & 0 deletions db/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM postgres:alpine
Loading