Mini project for "Database systems" laboratory classes at AGH UST, Poland.
- Mateusz Benecki, @beneckimateusz
- Dominik Kawalec, @dkawalecc
The main goal of this project is to learn how to create data models and connections between them. Since we have chosen MongoDB as a database system and Node.js as a backend engine for this particular application, the wisest option was to go for mongoose as the primary object modeling library rather than using low-level MongoDB Node.js Driver API methods.
- Node.js
- Express.js
- MongoDB
- Angular
cd frontend
ng serve
Now you can visit http://localhost:4200
cd backend
npm run dev
Now you can make requests to http://localhost:3000/api
However, in order for npm run dev
to run you have to create backend/config
folder with dev.env
file. Such file contains your local environment variables used in the application.
Required env variables:
MONGODB_URI=mongodb://127.0.0.1:27017/fut-browser
FRONTEND_ORIGIN=http://localhost:4200
COOKIE_PARSER_SECRET=<your_secret>
JWT_SECRET=<your_secret>
PORT=3000
cd backend
npm run-script seed <selected-seed-number>
Script allows to fill local database with realistic data using faker API. In order to get the same results every time, you can pass specific seed number as an argument.
Most of the routes are protected by the auth
middleware which uses JSON Web Tokens
to identify the user making the request. A token is stored in the browser as a signed cookie when a new user registers or an existing user logs in. After accessing the logout route, such token is removed form the previously mentioned place.
Such routes are properly marked in the Rest API section of this README
file.
Database stores information about local users and their actions.
User can :
- create/edit players
- create/edit teams
- add players only to his team
- scroll all players and teams
Player model was created in a similar way to actual FIFA player. It has multiple complex fields storing values of specific attributes that we are using to calculate team statistics. After adding specific player to the user team (you have to input player ID) app displays overall stats of the team from players overalls and certain more profound stats. Each team has his creator and can only be updated by this user.
Implementation of:
Even though the schemas in the request examples are pretty basic at the moment, we decided to create the README
file step by step.
POST /api/users
Request body:
{
"name": "<required>",
"email": "<required, unique>",
"password": "<required, minlength=7>"
}
Possible responses:
201 Created
- User created, returns new user object in response400 Bad Request
- Validation error
POST /api/users/login
Request body:
{
"email": "<required>",
"password": "<required>"
}
Possible responses:
200 OK
- Successfully logged in400 Bad Request
- Invalid credentials
Requires being authenticated.
POST /api/users/logout
Possible responses:
200 OK
- Successfully logged out401 Unauthorized
- User must be logged in in order to log out400 Bad Request
Requires being authenticated.
GET /api/users/me
Possible responses:
200 OK
- Returns authenticated user's object401 Unauthorized
- User must be logged in in order to see his profile500 Internal Server Error
Requires being authenticated.
PATCH /api/users/me
Valid updates:
{
"name": "<optional>",
"email": "<optional, unique>",
"password": "<optional, minlength=7>"
}
Possible responses:
200 OK
- Returns updated user's object400 Bad Request
- Invalid updates / Validation error401 Unauthorized
- User must be logged in in order to update his profile
Requires being authenticated.
DELETE /api/users/me
Possible responses:
200 OK
- Returns deleted user's object401 Unauthorized
- User must be logged in in order to delete his profile404 Not Found
- User not found500 Internal Server Error
Requires being authenticated.
POST /api/users/me/avatar
Requirements:
- Max file size - 1 MB
- Accepted file extensions - .jpg, .jpeg or .png
The avatar is stripped down to 250x250 dimensions and converted to .png format behind the scenes.
Usage example from multer
documentation:
<form action="/api/users/avatar" method="post" enctype="multipart/form-data">
<input type="file" name="avatar" />
</form>
Don't forget the enctype="multipart/form-data"
in your form.
Possible responses:
201 Created
- User's avatar was created successfully401 Unauthorized
- User must be logged in in order to upload his avatar400 Bad Request
- Requirements regarding the file were not met
Requires being authenticated.
GET /api/users/me/avatar
Possible responses:
200 OK
- Returns user's avatar withres.set('Content-Type', 'image/png')
401 Unauthorized
- User must be logged in in order to get his avatar404 Not Found
- User have not created his avatar yet
Requires being authenticated.
DELETE /api/users/me/avatar
Possible responses:
200 OK
- User's avatar was successfully deleted401 Unauthorized
- User must be logged in in order to delete his avatar400 Bad Request
POST /api/players
Request body:
{
"firstName": "<required>",
"lastName": "<required>",
"age": "<optional, gte 0>"
}
Possible responses:
201 Created
- Player created, returns new player object in response400 Bad Request
- Validation error
GET /api/players
Possible responses:
200 OK
- Returns players array500 Internal Server Error
GET /api/players/:id
Possible responses:
200 OK
- Returns required player's object404 Not Found
- Player was not found500 Internal Server Error
PATCH /api/players/:id
Valid updates:
{
"firstName": "<optional>",
"lastName": "<optional>",
"age": "<optional, gte 0>"
}
Possible responses:
200 OK
- Returns updated player's object400 Bad Request
- Invalid updates / Validation error
DELETE /api/players/:id
Possible responses:
200 OK
- Returns deleted player's object404 Not Found
- Player not found500 Internal Server Error