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

Authentication & Authorization #4

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 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
3a4cccb
feat: establish the connection with the database
mserykh Aug 3, 2022
2813d65
feat: add entities
mserykh Aug 3, 2022
09bb52a
feat: add relations between entities
mserykh Aug 3, 2022
44dbb77
feat: implement request to the database
mserykh Aug 3, 2022
2c22f3c
refactor: adjust entities import
mserykh Aug 3, 2022
cd2a527
feat: adjust album quesries
mserykh Aug 3, 2022
0263405
refactor: add handling errors and incorrect data
mserykh Aug 3, 2022
282eaf5
fix: fix date output for user entity
mserykh Aug 3, 2022
c9f5fde
feat: add queries to the database for favorites
mserykh Aug 3, 2022
c799354
refactor: clean code
mserykh Aug 3, 2022
2e06ffe
refactor: clean code
mserykh Aug 3, 2022
3b60691
fix: fix queries to the db for artist entity
mserykh Aug 3, 2022
571a713
refactor: adjust code status for favorites
mserykh Aug 3, 2022
3bd5cd5
fix: fix updating a user
mserykh Aug 3, 2022
15d982e
fix: fix artist queries
mserykh Aug 3, 2022
cb1a5e4
feat: create configs for db
mserykh Aug 6, 2022
c294b91
feat: add scipts for migrations
mserykh Aug 6, 2022
b29220d
refactor: adjust queries for favorites
mserykh Aug 6, 2022
e0f2d14
refactor: adjust types, imports
mserykh Aug 6, 2022
2ee1cc3
fix: add network to `app`
mserykh Aug 6, 2022
a2c5932
feat: add migrations
mserykh Aug 7, 2022
9229c25
feat: add basic structure for authentication, implement basic signing up
mserykh Aug 7, 2022
5c37637
refactor: adjust `signup` method
mserykh Aug 8, 2022
d80bb9c
feat: implement basic logging
mserykh Aug 8, 2022
2133ea2
fix: fix errors
mserykh Aug 8, 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
15 changes: 15 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PORT=4000

POSTGRES_PORT=5432

TYPEORM_CONNECTION=postgres
POSTGRES_USER=admin
POSTGRES_PASSWORD=postgresadmin
POSTGRES_DB=postgresdb
DATABASE_URL: postgres://admin:postgresadmin@db:5432/postgresdb

CRYPT_SALT=10
JWT_SECRET_KEY=secret123123
JWT_SECRET_REFRESH_KEY=secret123123
TOKEN_EXPIRE_TIME=1h
TOKEN_REFRESH_EXPIRE_TIME=24h
7 changes: 0 additions & 7 deletions .env.example

This file was deleted.

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