Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
aa6b384
Feat: se aplicado, este commit adicionara endpoints createUser create…
byron-smith-nobrega Jan 29, 2023
31f2df3
Feat: se aplicado, este commit add os endPoints createFriendship, del…
byron-smith-nobrega Jan 30, 2023
6a8bc2b
Update README.md
byron-smith-nobrega Jan 30, 2023
8bab786
Update README.md
byron-smith-nobrega Jan 30, 2023
8fde5ce
Refactor: se aplicado, este commit coloca o projeto na arquitetura de…
byron-smith-nobrega Feb 2, 2023
d28574c
Fix: se aplicado, este commit corrigirá o erro de validação do post e…
byron-smith-nobrega Feb 2, 2023
a50b973
Feat: se aplicado, este commit add o endPoint comment
byron-smith-nobrega Feb 3, 2023
2f181a2
Feat: se aplicado, este commit add as Routers
byron-smith-nobrega Feb 3, 2023
8ca29b4
Merge pull request #1 from future4code/byron
byron-smith-nobrega Feb 3, 2023
33cf77c
Update README.md
byron-smith-nobrega Feb 3, 2023
24744be
Update FriendshipController.ts
byron-smith-nobrega Feb 3, 2023
10c800a
Update FriendshipBusiness.ts
byron-smith-nobrega Feb 3, 2023
ca6e4ad
Refactor:se aplicado, este commit corrige nome modal freind
byron-smith-nobrega Feb 3, 2023
95fdb84
Merge pull request #3 from future4code/byron2
byron-smith-nobrega Feb 3, 2023
97969e1
Refactor: se aplicado, este commit refatora todos os endPoints
byron-smith-nobrega Feb 4, 2023
c9aa829
Refactor: se aplicado, este commit corrige bug no request
byron-smith-nobrega Feb 4, 2023
a69c39b
Merge pull request #4 from future4code/byron3
byron-smith-nobrega Feb 4, 2023
a21e394
Update README.md
byron-smith-nobrega Feb 4, 2023
1582a3b
Update README.md
byron-smith-nobrega Feb 4, 2023
4f1608e
Update README.md
byron-smith-nobrega Feb 4, 2023
7320116
Update README.md
byron-smith-nobrega Feb 4, 2023
729d9e4
Refactor: se aplicado, este commit add função idGenerator
byron-smith-nobrega Feb 4, 2023
f41205c
Merge pull request #5 from future4code/byron3
byron-smith-nobrega Feb 4, 2023
90749e1
Update README.md
byron-smith-nobrega Feb 4, 2023
a3248f7
Refactor: se aplicado, este commit corrige bug do postDatabase
byron-smith-nobrega Feb 5, 2023
4492a05
Merge pull request #6 from future4code/byron3
byron-smith-nobrega Feb 5, 2023
fb89c84
Update FriendshipBusiness.ts
byron-smith-nobrega Feb 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
build
.env
66 changes: 64 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# labook-template
Repositório do projeto Labook
## <h1 align="center">📇 Labook </h1>

## :memo: Descrição
Projeto desenvolvido como didática de back-end para as turmas JBL LABENU com conteúdos que englobam o universo da criação de APIs com a temática de um rede social.

## Link Documentação Postman
[Doc_Postman](https://documenter.getpostman.com/view/22363157/2s935mtRKC)

## Link Deploy Render
https://labook4.onrender.com

## 👩🏾Pessoa Desenvolvedora do Projeto

[<img src="https://avatars.githubusercontent.com/u/74737156?v=4" width=115><br><sub>Byron Smith</sub>](https://github.com/byron-smith-nobrega)

## :books: Funcionalidades
* <b>Criar Usuário</b>: Método voltado para a criação de usuários.
* <b>Criar Post</b>: Método voltado para a criação de postagens.
* <b>Buscar Post</b>: Método voltado para a consulta de uma postagem.
* <b>Criar Amizade</b>: Método voltado para a criação de amizade entre usuários.
* <b>Deletar Amizade</b>: Método voltado para a exclusão de uma amizade.
* <b>Criar Curtida</b>: Método voltado para a criação de vínculo entre usuário e postagem.
* <b>Deletar Curtida</b>: Método voltado para a exclusão de vínculo entre usuário e postagem.
* <b>Criar Comentário </b>: Método voltado para a criação de comentário nas postagens.
* <b>Buscar Feeds Amigos </b>: Método voltado para a consulta de postagens dos amigos.
* <b>Buscar Feeds</b>: Método voltado para a consulta de postagens.

## :wrench: Tecnologias utilizadas
* VS Code
* nodeJS
* expressJS
* axios
* cors
* dotenv
* uuid
* MySQL


## :rocket: Rodando o projeto
Para rodar o repositório é necessário clonar o mesmo, dar o seguinte comando para instalar as dependências:
```
npm install
```
Após instaladas as dependências, configure o arquivo .env:
```
DB_HOST =
DB_USER = ""
DB_PASS = ""
DB_NAME = ""
```
Após configuração do .env, dê o comando seguinte para rodar a aplicação:
```
npm run start
```
Após o start, dê o comando seguinte para criar as tabelas no banco de dados:
```
npm run migrations
```

Use o Postman ou o Insomnia para realizar as requisições desejadas.

## :dart: Status do projeto
O projeto está em andamento.

30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "revisao-full-stack",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "tsc && node ./build/index.js",
"dev": "ts-node-dev ./src/index.ts",
"migrations": "tsc && node ./build/data/migrations.js"
},
"author": "Byron",
"license": "ISC",
"dependencies": {
"@types/node": "^18.11.18",
"dotenv": "^16.0.3",
"express": "^4.18.2",
"knex": "^2.4.0",
"mysql": "^2.18.1",
"typescript": "^4.9.4",
"uuid": "^9.0.0"
},
"devDependencies": {
"@types/cors": "^2.8.13",
"@types/express": "^4.17.15",
"@types/knex": "^0.16.1",
"@types/uuid": "^9.0.0",
"cors": "^2.8.5",
"ts-node-dev": "^2.0.0"
}
}
89 changes: 89 additions & 0 deletions request.rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

### Create a new User
POST http://localhost:3003/user/create
Content-Type: application/json

{
"name":"Bianca Smith",
"email":"biancasmith@gmail.com",
"password": "1234567"
}

### Return post
GET http://localhost:3003/post/getpost
Content-Type: application/json

{
"id":"1675379034720"
}

### Create a new Post
POST http://localhost:3003/post/create
Content-Type: application/json
Authorization: 1675001631299

{
"photo" : "Foto",
"description": "foto da viagem",
"type": "normal",
"createdAt": "08/02/2023"
}

### Create a new Friendship
POST http://localhost:3003/friendship/create
Content-Type: application/json
Authorization: 1675001631299

{
"friendId":"1675019596015"
}

### Delete Friendship
DELETE http://localhost:3003/friendship
Content-Type: application/json
Authorization: 1675001631299

{
"friendId":"1675019596015"
}

### Return Feeds freands
GET http://localhost:3003/post/getfeedsfreands
Content-Type: application/json
Authorization: fde08a25-cb5c-4948-bb59-693eb726721d

### return feed by type
GET http://localhost:3003/post/getfeeds
Content-Type: application/json

{
"type":"normal"
}

### Like Post
POST http://localhost:3003/like/create
Content-Type: application/json
Authorization: 1675001631299

{
"postId":"1675379034720"
}

### Delete Like Post
DELETE http://localhost:3003/like
Content-Type: application/json
Authorization: 1675001631299

{
"postId":"1675379034720"
}

### Comment Post
POST http://localhost:3003/comments
Content-Type: application/json
Authorization: 1675001631299

{
"comment":"Linda foto",
"postId":"1675379034720"
}
53 changes: 53 additions & 0 deletions src/business/CommentsBusiness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { CommentDatabase } from "../data/CommentsDatabase";
import { PostDatabase } from "../data/PostDatabase";
import { UserDatabase } from "../data/UserDatabase";
import { InputCommentControllerDTO } from "../model/Comments";
import { IdGenerator } from "../service/IdGenerator";

const commentDatabase = new CommentDatabase();
const userDatabase = new UserDatabase();
const postDatabase = new PostDatabase();
const idGenerator = new IdGenerator();

export class CommentsBusiness {
createComment = async (input: InputCommentControllerDTO): Promise<void> => {
try {
const { comment, postId, authorId } = input;


if (!comment || !postId || !authorId) {
throw new Error(
'Fill in the fields "comment", "postId" and "authorId"'
);
}

const userBase = await userDatabase.findUser();
const existUser = userBase.findIndex((user)=>user.id === authorId);

if(existUser === -1) {
throw new Error("User not exist.");
}
const postBase = await postDatabase.findPost(postId);
const existPost = postBase.findIndex((post)=>post.id === postId);

if(existPost === -1) {
throw new Error("Post not exist.");
}

const id: string = idGenerator.generateId();


await commentDatabase.insertcomment({
id,
comment,
postId,
authorId,
});
} catch (error:any) {
throw new Error(error.message)
}
};

findComment = () => {};
deleteComment = () => {};
}
104 changes: 104 additions & 0 deletions src/business/FriendshipBusiness.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { FriendshipDatabase } from "../data/FriendshipDatabase";
import { UserDatabase } from "../data/UserDatabase";
import { FriendInputDTO } from "../model/friends";
import { DeleteFriendshipInputDTO, FriendshipInputDTO} from "../model/Friendship";
import { IdGenerator } from "../service/IdGenerator";

const friendshipDatabase = new FriendshipDatabase();
const userDatabase = new UserDatabase();
const idGenerator = new IdGenerator();

export class FriendshipBusiness {
createFriendship = async (input: FriendInputDTO): Promise<void> => {
try {
const { friendId, authorId } = input;

if (!friendId || !authorId) {
throw new Error("Fill in the friendId, authorId fields");
}

const queryUser = await userDatabase.findUser();
const existFriend = queryUser.findIndex((user) => {
return user.id === friendId;
});

if (existFriend === -1) {
throw new Error("Friend id does not exist.");
}

const existauthorId = queryUser.findIndex((user) => {
return user.id === authorId;
});

if (existauthorId === -1) {
throw new Error("User id does not exist.");
}

const id: string = idGenerator.generateId();

const queryResult: FriendshipInputDTO[] =
await friendshipDatabase.findFriendship(authorId);

const existFriendship = queryResult.findIndex((user) => {
return user.friend_id === friendId;
});

if (existFriendship != -1) {
throw new Error("friendship already exists!");
}
const idFriend: string = idGenerator.generateId();

await friendshipDatabase.insertPost({
id,
idRows: idFriend,
friendId,
authorId,
});
} catch (error: any) {
throw new Error(error.message);
}
};

findFriendship = () => {};

deleteFriendship = async (input: DeleteFriendshipInputDTO): Promise<void> => {
try {
const { friendId, authorId } = input;

if (!friendId || !authorId) {
throw new Error("Fill in the friendId, authorId fields");
}

const queryUser = await userDatabase.findUser();
const existFriend = queryUser.findIndex((user) => {
return user.id === friendId;
});

if (existFriend === -1) {
throw new Error("Friend id does not exist.");
}

const existauthorId = queryUser.findIndex((user) => {
return user.id === authorId;
});

if (existauthorId === -1) {
throw new Error("User id does not exist.");
}

const queryResult: FriendshipInputDTO[] = await friendshipDatabase.findFriendship(authorId);

const existFriendship = queryResult.findIndex((user) => {
return user.friend_id === friendId;
});

if (existFriendship === -1) {
throw new Error("friendship does not exist!");
}

await friendshipDatabase.deletePost(input);
} catch (error: any) {
throw new Error(error.message);
}
};
}
Loading