项目作者: k2madureira

项目描述 :
API for registering IMDb scores 🚀
高级语言: TypeScript
项目地址: git://github.com/k2madureira/ioasys_IMDb.git
创建时间: 2020-12-18T12:47:19Z
项目社区:https://github.com/k2madureira/ioasys_IMDb

开源协议:

下载


Ioasys 🎞

imdb100

Structure:

  1. ioasys_IMDb
  2. |_ public
  3. |_ coverage
  4. |_ Postman
  5. |_ src
  6. |_ modules
  7. |_ User
  8. |_ __tests__
  9. |_> User.spec.ts
  10. |_ controllers
  11. |_> UserController.ts
  12. |_ dtos
  13. |_> ICreateUserDTO.ts
  14. |_ models
  15. |_> User.ts
  16. |_ repositories
  17. |_> IUserRepository.ts
  18. |_ Movie
  19. |_ __tests__
  20. |_ controllers
  21. |_ dtos
  22. |_ models
  23. |_ repositories
  24. |_ shared
  25. |_ database
  26. |_> app.ts
  27. |_> bootstrap.ts
  28. |_> routes.ts
  29. |_> server.ts

Data schema files JSON:

  1. _____________ ____________________ _______________
  2. | Users | | Movies | | scores |
  3. |_____________| |-------------------| |_______________|
  4. | (1) id | | (2) id | | id |
  5. | name | | title | | (1) id_user |
  6. | password | | director | | (2) id_movie |
  7. | nickname | | genre | | score |
  8. | admin | | actors | | created_at |
  9. | disabled | | year | | updated_at |
  10. | created_at | | created_at | |_______________|
  11. | updated_at | | updated_at |
  12. |_____________| |___________________|

Docs 💾:

  1. PostMan (https://documenter.getpostman.com/view/9357385/TVsuBSjU )
  2. PostMan Collection ( public/Postman/ioasys.postman_collection.json )
  3. docs
  4. Code Coverage ( ioasys_IMDb/public/coverage/lcov-report/index.html )
  5. Insominia.json

Run in Postman

Setting up local environment 🏡:

  1. Install Yarn;
  2. Using terminal, navigate to the folder where the project was cloned and run:
    git clone https://github.com/k2madureira/ioasys_IMDb.git
  3. Using terminal, access the ioasys_IMDb folder and Run yarn install, to download all necessary dependencies;
  4. Using terminal run yarn dev:server, to start the server on port 3333; (Typescript)
  5. For testing, the insomnia software is recommended;
  6. To perform the unit test yarn test
  7. Database used PostgreSQL, with configuration in the .env file

.ENV File 🛠:

  • [ ] APP_SECRET (Using some MD5 generation service, create a key that only you know.)

  • [ ] DB_HOST (Your database host)

  • DB_USER (Your database user)
  • DB_PASS (Your database password)
  • DB_NAME (Your database name)
  • [ ] DB_PORT (Your database port, for PostgreSQL it is usually used at 5432)

  • [ ] DB_HOST_JEST (Your test database host)

  • DB_USER_JEST (Your test database User)
  • DB_PASS_JEST (Your test database Password)
  • DB_NAME_JEST (Your test database Name)
  • DB_PORT_JEST (port of your test database, for PostgreSQL it is usually used at 5432)

Tests 🎯:

  • Jest
  • Code coverage

code formatter / Extensions 🔧:

  • Eslint (Airbnb)
  • Eslint (Visual Studio Code - Extension)
  • Prettier
  • EditorConfig (Visual Studio Code - Extension)

Future improvements 🧱:

  • Creation of actors, directors and genres tables
  • change of inputs in the insertion of new films, relating to three n * n tables, between actors, directors and genres.

Endpoints 📌:

Number Type Route Definition
1 Post /login Login
2 Post /user Create an user
3 Put /user/id Update an user
4 Delete /user/:id Disabled user
5 Post /movie Register new movie
6 Get /movie List all movies
7 Put /movie/:id Update an movie using id
8 Get /movie/:id Detail an movie using id
9 Post /movie/:id/vote score a movie using user id

Exemples:

  1. http://localhost:3333/login (POST)
Request [ body: JSON]
  1. {
  2. "email":"admin@gmail.com",
  3. "password": "123"
  4. }
Response [JSON]
  1. {
  2. "user": {
  3. "name": "Lenilson Madureira",
  4. "email": "admin@gmail.com"
  5. },
  6. "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2MDg1MDM1NTgsImV4cCI6MTYwODU4OTk1OCwic3ViIjoiMSJ9.bEu0P1Xqtcz9U4aonou-3Ejyr_DvX1l1Y5CdFO9plKw"
  7. }

  1. http://localhost:3333/user (POST)
Request [ body: JSON]
  1. {
  2. "name": "USER",
  3. "nickname": "USER",
  4. "email":"user1@user.com",
  5. "password": "123",
  6. "admin": false
  7. }
Response [JSON]
  1. {
  2. "message": "User successfully registered",
  3. "infos": {
  4. "id": 2,
  5. "name": "USER",
  6. "nickname": "USER",
  7. "email":"user1@user.com"
  8. }
  9. }

  1. http://localhost:3333/user/2 (PUT)
Request [ body: JSON]
  1. {
  2. "name": "USER_UPDATED"
  3. }
Response [JSON]
  1. {
  2. "User": {
  3. "id": 2,
  4. "name": "USER_UPDATED",
  5. "nickname": "USER",
  6. "email":"user1@user.com"
  7. }
  8. }

  1. http://localhost:3333/user/2 (DELETE)
Response [JSON]
  1. {
  2. "success": "disabled"
  3. }

  1. http://localhost:3333/movie (POST)
Request [ body: JSON]
  1. {
  2. "tt": "1414",
  3. "title": "Gladiator",
  4. "director":"Ridley Scott",
  5. "genre": "Action | Adventure | Drama",
  6. "actors": "Russell Crowe, Joaquin Phoenix, Connie Nielsen"
  7. }
Response [JSON]
  1. {
  2. "message": "Movie successfully registered ✅",
  3. "infos": {
  4. "id": 4,
  5. "tt": "1414",
  6. "title": "Gladiator",
  7. "year": null,
  8. "director": "Ridley Scott",
  9. "genre": "Action | Adventure | Drama",
  10. "actors": "Russell Crowe, Joaquin Phoenix, Connie Nielsen"
  11. }
  12. }

  1. http://localhost:3333/movie (GET)
Response [JSON]
  1. [
  2. {
  3. "id": 1,
  4. "tt": "4154796",
  5. "title": "Avengers: Endgame (Vingadores: Ultimato)",
  6. "year": "2019",
  7. "director": "Anthony Russo, Joe Russo",
  8. "genre": "Action, Adventure, Drama",
  9. "actors": "Robert Downey Jr., Chris Evans, Mark Ruffalo",
  10. "scores": [
  11. {
  12. "id": 1,
  13. "user_id": 1,
  14. "movie_id": 1,
  15. "score": 4,
  16. "createdAt": "2020-12-19T12:15:54.654Z",
  17. "updatedAt": "2020-12-19T12:15:54.654Z"
  18. },
  19. {
  20. "id": 2,
  21. "user_id": 4,
  22. "movie_id": 1,
  23. "score": 2,
  24. "createdAt": "2020-12-19T12:30:45.202Z",
  25. "updatedAt": "2020-12-19T12:30:45.202Z"
  26. },
  27. {
  28. "id": 3,
  29. "user_id": 4,
  30. "movie_id": 1,
  31. "score": 2,
  32. "createdAt": "2020-12-20T15:35:48.667Z",
  33. "updatedAt": "2020-12-20T15:35:48.667Z"
  34. }
  35. ]
  36. },
  37. {
  38. "id": 2,
  39. "tt": "0120815",
  40. "title": "Saving Private Ryan",
  41. "year": null,
  42. "director": " Steven Spielberg",
  43. "genre": "Drama | War",
  44. "actors": " Tom Hanks, Matt Damon, Tom Sizemore",
  45. "scores": []
  46. },
  47. {
  48. "id": 4,
  49. "tt": "55",
  50. "title": "Avengers: Endgame (Vingadores: Ultimato)",
  51. "year": "2019",
  52. "director": "Anthony Russo, Joe Russo",
  53. "genre": "Action, Adventure, Drama",
  54. "actors": "Robert Downey Jr., Chris Evans, Mark Ruffalo",
  55. "scores": []
  56. },
  57. {
  58. "id": 3,
  59. "tt": "0172495",
  60. "title": "Gladiator",
  61. "year": null,
  62. "director": "Ridley Scott",
  63. "genre": "Action | Adventure | Drama",
  64. "actors": "Russell Crowe, Joaquin Phoenix, Connie Nielsen",
  65. "scores": []
  66. }
  67. ]

  1. http://localhost:3333/movie/4 (PUT)
Request [ body: JSON]
  1. {
  2. "tt": "1414",
  3. "title": "Gladiator",
  4. "director":"Ridley Scott",
  5. "genre": "Action | Adventure | Drama",
  6. "actors": "Russell Crowe, Joaquin Phoenix, Connie Nielsen"
  7. }
Response [JSON]
  1. {
  2. "Movie": {
  3. "id": "4",
  4. "tt": "1414",
  5. "title": "Gladiator",
  6. "director":"Ridley Scott",
  7. "genre": "Action | Adventure | Drama",
  8. "actors": "Russell Crowe, Joaquin Phoenix, Connie Nielsen"
  9. }
  10. }

  1. http://localhost:3333/movie/4 (GET)
Response [JSON]
  1. {{
  2. "id": 4,
  3. "tt": "1414",
  4. "title": "Gladiator",
  5. "director":"Ridley Scott",
  6. "genre": "Action | Adventure | Drama",
  7. "actors": "Russell Crowe, Joaquin Phoenix, Connie Nielsen"
  8. "genre": "Action | Adventure | Drama",
  9. "total_votes": 3,
  10. "average_votes": 2.6666666666666665
  11. }

  1. http://localhost:3333/movie/4/vote (POST)
Request [ body: JSON]
  1. {
  2. "score": 2
  3. }
Response [JSON]
  1. {
  2. "success": "vote successfully registered"
  3. }