Table of Contents
Labeddit is a social network with the goal of connecting and interacting between posts from its users. Anyone who signs up for the app can create, like, and comment on posts.
- NodeJS
- Typescript
- Express
- SQL e SQLite
- Knex
- POO
- Layered architecture
- UUID
- Password hashed
- Autentication and autozrization
- Router
- Postman
Ducumentation of the API with instrutions on how to use the endpoints avalible for the Labeddit aplication
-
Endpoints
- Users
- Signup
- Login
- Delete user
- Posts
- Get Posts
- Edit Post
- Reaction Post
- Create new Post
- Delete Post
- Comments
- Get Comments of a Post
- Edit Comment
- Reaction Comment
- Create new comment
- Delete Comment
- Users
-
Authentication and authorization
- UUID
- Hashed passwords with Bcrypt.
- tokens JWT
-
Code
- POO
- Layered architecture
- Router in Express
- SOLID
- Clean code
Requests for the API must follow HTTP RESTful patterns.
Methods | Description |
---|---|
GET |
Returns information for one or more records. |
POST |
Used to create a new record or login access. |
PUT |
Updates data for a record or changes its status. |
PATCH |
Partially updates data for a record. |
DELETE |
Removes a record from the system. |
Código | Descrição |
---|---|
200 |
Request successfully executed (success). |
201 |
Data created successfully (success). |
400 |
Validation errors or fields provided do not exist in the system. |
404 |
Searched record not found (Not found). |
409 |
The user already exists in the system. (Conflict). |
500 |
Unexpected error. |
Here is an example of instructions on how to set up the project locally. To have a local copy, follow the steps below:
- Clone repository
git clone https://github.com/Afmjuniors/labeddit-back.git
- Install NPM TypeScript packages
npm init -y (create package.json)
npm i -g typescript (just once)
npm i typescript -D (install typescript in the project)
npx tsc -init (create tsconfig.json)
- Install NPM Express packages
npm install express
npm install @types/express -D
- Install NPM Cors packages
npm install cors
npm install @types/cors -D
- Install NPM Node packages
npm install ts-node-dev -D
- Run NPM Universally Unique Identifier (UUID)
npm install uuid
npm install -D @types/uuid
- Run NPM Environment variables (ENV, see .env.exemple)
npm install dotenv
- Run NPM JWT(Token)
npm install jsonwebtoken
npm install -D @types/jsonwebtoken
- Run NPM Bcrypt
npm i bcryptjs
npm i -D @types/bcryptjs
- Run NPM Jest
npm i -D jest @types/jest ts-jest
- Run NPM developer
npm run dev
This application is a Fullstack development of a working social media plataform. Using a blog format the user can view posts by others users, Like or Dislike them and even comment in a specific post. To see the application online deployed visti the vercel('https://labeddit-front.vercel.app/')
To see repository of this application Front-end
It isnt necessary to use the email, name, and password in the exemples. However remember to respect th basic struture.
Public endpoint for create new user.
// request POST /users/signup
// body JSON
{
"name":"junior",
"email":"junior@email.com",
"password":"123456@Aa"
}
// response
// status 201 CREATED
{
"message": "Usuario adicionado com sucesso",
"user": {
"id": "UUID",
"name": "junior",
"email": "junior@email.com",
"role": "NORMAL",
"createdAt": Date.now(),
"updatedAt": Date.now()"
},
"token": "token jwt"
}
Public endpoint for login user.
// request POST /users/login
// body JSON
{
"email": "junior@email.com",
"password": "123456@Aa"
}
// response
// status 200 OK
"message": "Login feito com sucesso",
"user": {
"id": "UUID",
"name": "junior"
},
"token": "token jwt"
}
Protected endpoint for deleted logged user.
// request DELETE /users
// headers.authorization = "token jwt"
// response
// status 200 OK
{
"message": "Usuario deletado com sucesso"
}
Protected endpoint get all posts. required a jwt token.
// request GET /posts
// headers.authorization = "token jwt"
// response
// status 200 OK
[
{
"id": "UUID",
"content": "Conten of post made in the postman",
"likes": 0,
"dislikes": 0,
"comments": 1,
"creator": {
"id": "UUID",
"name": "Alexandre Machado"
},
"userReaction": [
null
],
"createdAt": "2023-03-11T20:58:49.263Z",
"updatedAt": "2023-03-11T20:58:49.263Z"
},
{
"id": "UUID",
"content": "Content as a test made in the postman",
"likes": 0,
"dislikes": 0,
"comments": 0,
"creator": {
"id": "UUID",
"name": "junior"
},
"userReaction": [
null
],
"createdAt": "2023-03-11T20:58:49.263Z",
"updatedAt": "2023-03-11T20:58:49.263Z"
}
]
Protected endpoint create a new post. required a jwt token.
// request POST /posts
// headers.authorization = "token jwt"
// body JSON
{
"content": "New Post!"
}
// response
// status 201 CREATED
{
"message": "Post adicionado com sucesso",
"post": {
"id": "UUID",
"content": "New Post!",
"likes": 0,
"dislikes": 0,
"comments": 0,
"creator": {
"id": "UUID",
"name": "junior"
},
"userReaction": [
null
],
"createdAt": Date.now(),
"updatedAt": Date.now()
}
}
Protected endpoint edit a post. required a jwt token.
Only the creator can edit its content
// request PATCH /posts/:id
// headers.authorization = "token jwt"
// body JSON
{
"content": "New content, of the post created by junior"
}
// response
// status 200 OK
{
"message": "Post adicionado com sucesso",
"post": {
"id": "UUID",
"content": "New content, of the post created by junior",
"likes": 0,
"dislikes": 0,
"comments": 0,
"creator": {
"id": "UUID",
"name": "junior"
},
"userReaction": [
null
],
"createdAt": "2023-03-11T21:05:56.708Z",
"updatedAt": Date.now()
}
}
Protected endpoint delete a post. required a jwt token.
Only the creator can delete it. ADMIN can delete all posts.
// request DELETE /posts/:id
// headers.authorization = "token jwt"
// response
// status 200 OK
{
"message": "Post deletado com sucesso"
}
Protected endpoint create a new post. required a jwt token.
Case the user had liked the post and do it again, the reaction will be neutral.
Case the user had liked the post and disliked it now, the reaction will be inverse.
// request PUT /posts/:id/reaction
// headers.authorization = "token jwt"
// body JSON
{
"like": true
}
// response
// status 200 OK
{
"message": "O usuario deu like no post"
}
// request PUT /posts/:id/reaction
// headers.authorization = "token jwt"
// body JSON
{
"like": false
}
// response
// status 200 OK
{
"message": "O usuario trocou para dislike"
}
// request PUT /posts/:id/reaction
// headers.authorization = "token jwt"
// body JSON
{
"like": false
}
// response
// status 200 OK
{
"message": "O usuario desfez o dislike"
}
Protected endpoint get all comments of an post. required a jwt token.
// request GET /comments/:id
// headers.authorization = "token jwt"
// response
// status 200 OK
[
{
"id": "UUID",
"postId": "UUID",
"content": "New content",
"likes": 0,
"dislikes": 1,
"createdAt": Date.now(),
"updatedAt": Date.now(),
"creator": {
"id": "UUID",
"name": "Alexandre Machado"
},
"userReaction": [
null
]
}
]
Protected endpoint create a new comment of a post. required a jwt token.
// request POST /comments/:id
// headers.authorization = "token jwt"
// body JSON
{
"content": "New content!"
}
// response
// status 201 CREATED
{
"message": "Post adicionado com sucesso",
"post": {
"id": "UUID",
"content": "New content!",
"likes": 0,
"dislikes": 0,
"comments": 0,
"creator": {
"id": "UUID",
"name": "Alexandre Machado"
},
"userReaction": [
null
],
"createdAt": Date.now(),
"updatedAt": Date.now()
}
}
Protected endpoint create a post. required a jwt token.
Only the creator can edit its content
// request PATCH /comments/:id
// headers.authorization = "token jwt"
// body JSON
{
"content": "New content, of the post created by junior"
}
// response
// status 200 OK
{
"message": "Post adicionado com sucesso",
"post": {
"id": "UUID",
"content": "New content, of the post created by junior",
"likes": 0,
"dislikes": 0,
"comments": 0,
"creator": {
"id": "UUID",
"name": "junior"
},
"userReaction": [
null
],
"createdAt": "2023-03-11T21:05:56.708Z",
"updatedAt": Date.now()
}
}
Protected endpoint delete a comment. required a jwt token.
Only the creator can delete it. ADMIN can delete all posts.
// request DELETE /comments/:id
// headers.authorization = "token jwt"
// response
// status 200 OK
{
"message": "Post deletado com sucesso"
}
Protected endpoint create a new comment. required a jwt token.
Case the user had liked the comment and do it again, the reaction will be neutral.
Case the user had liked the comment and disliked it now, the reaction will be inverse.
// request PUT /comments/:id/reaction
// headers.authorization = "token jwt"
// body JSON
{
"like": true
}
// response
// status 200 OK
{
"message": "O usuario deu like no post"
}
// request PUT /comments/:id/reaction
// headers.authorization = "token jwt"
// body JSON
{
"like": false
}
// response
// status 200 OK
{
"message": "O usuario trocou para dislike"
}
// request PUT /comments/:id/reaction
// headers.authorization = "token jwt"
// body JSON
{
"like": false
}
// response
// status 200 OK
{
"message": "O usuario desfez o dislike"
}
Alexandre Machado - afmjuniors@gmail.com
- As my last project made by the bootcamp Labenu I would like to thanks them, every single teacher was critical to my learning experience, and the support staff was wornderful.
- Also as the last project by the bootcamp I would like to thanks my colegues form Ammal-A, they were a very unite commuty and I hope that we continue to do so.