Solid MVVM User Story API


Β 

πŸ“¦ Require Software πŸš€

1. Node.js

2. MongoDB

3.Docker coming soon!!!


Β 

πŸ’‘API Documentation

API for user registration with JWT authentication for route protection, entering user stories. Managing MongoDB database
Β 

Usage:


  • First, create a folder for your project and navigate to it:
mkdir solid-mvvm-api cd solid-mvvm-api
  • Initialize the project node.js
npm init -y

Installs required dependencies


$ npm install express mongoose body-parser $ npm install --save-dev typescript ts-node @types/node @types/express $ npm install express mongoose bcryptjs jsonwebtoken $ npm install

Star Server


ts-node src/app.ts

TsConfig.json


{ "compilerOptions": { "target": "ES6", "module": "commonjs", "outDir": "./dist", "rootDir": "./src", "strict": true, "esModuleInterop": true } }

MVVM


Model: Representa los datos y la lΓ³gica de negocio.

View: Representa la interfaz de usuario.

ViewModel: ActΓΊa como un intermediario entre el Model y la View.
Β 

Structure


solid-mvvm-api/ β”œβ”€β”€ src/ β”‚ β”œβ”€β”€ controllers/ β”‚ β”‚ β”œβ”€β”€ authController.ts β”‚ β”‚ β”œβ”€β”€ storyController.ts β”‚ β”‚ └── userController.ts β”‚ β”œβ”€β”€ models/ β”‚ β”‚ β”œβ”€β”€ story.ts β”‚ β”‚ └── user.ts β”‚ β”œβ”€β”€ repositories/ β”‚ β”‚ β”œβ”€β”€ storyRepository.ts β”‚ β”‚ └── userRepository.ts β”‚ β”œβ”€β”€ services/ β”‚ β”‚ β”œβ”€β”€ authService.ts β”‚ β”‚ β”œβ”€β”€ storyService.ts β”‚ β”‚ └── userService.ts β”‚ β”œβ”€β”€ views/ β”‚ β”‚ └── viewModel.ts β”‚ β”œβ”€β”€ middlewares/ β”‚ β”‚ └── authMiddleware.ts β”‚ β”œβ”€β”€ app.ts β”‚ └── routes.ts β”œβ”€β”€ tsconfig.json └── package.json

πŸ’‘Principios SOLIDπŸ’‘


Β 

S: Responsabilidad Única

O: Abierto/Cerrado

L: SustituciΓ³n de Liskov

I: SegregaciΓ³n de Interfaces

D: InversiΓ³n de Dependencias
Β 

Endpoints:



Β 

Users


New User

  • URL: /api/register
  • Method: POST
- Body: { "name":"Juan", "username":"Pablo", "email":"[email protected]", "password":"1234567" }


Β 

Login User

  • URL: /api/login
  • Method: POST
-Body: { "username":"Pgutisga", "password":"1234567" } return { "token":"######" }


Β 

Get User List

  • URL: /api/users

  • Method: GET

- Header: Authorization: token; return { "_id":"66ba5501c6a5290a737ddce4", "name":"Juan P\u00e9rez", "email":"[email protected]", "__v":0 }

Id user

  • URL: /api/userst
  • Method: POST
- Header: Authorization: token; - Body: userId: userId; { "_id":"66ba77aa55dc1f6f3b62eb48", "name":"JuanPaga", "username":"Pgutisga", "email":"[email protected]", "password":"####", "__v":0 }

Story


New Story

  • URL: /api/stories
  • Method: POST
- Header: Authorization: token; - Body: { "title": "My First Story", "content": "New Story Node.js.", "userId": "_id" }

Get Stories by User ID

  • URL: /stories/user
  • Method: POST
- Header: Authorization: token; - Body: { "userId": "_id" }

Get Stories by Story ID

  • URL: /api/stories/story
  • MΓ©todo: POST
- Header: Authorization: token; - Body: { "_id":"66bb557fde17b55cc4862df1", "userId":"66ba77aa55dc1f6f3b62eb48" }

Edit Story by ID

  • URL: /api/stories/story/edit
  • MΓ©todo: POST
- Header: Authorization: token; - Body: { "title":"Julio", "content":"Domingos", "userId":"66ba77aa55dc1f6f3b62eb48", "_id":"66bb557fde17b55cc4862df1" }

Delete Story by ID

  • URL: /api/stories/story/delete

  • MΓ©todo: POST

- Header: Authorization: token; - Body: { "_id":"idStory" }
Solid MVVM User Story API