
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" }
- @version 1.0.0
- @author [JuanPGutiDev]
- @email [[email protected]]
Solid MVVM User Story API