Giter Club home page Giter Club logo

react_todo-app-api's Introduction

Todo API

Descrição

Esta é uma API RESTful para gerenciar uma lista de tarefas (todos). A API foi construída utilizando Node.js, Express, TypeScript e Prisma ORM, seguindo um padrão de camadas. O banco de dados utilizado é o PostgreSQL. O projeto inclui validações, tratamento de erros e segue boas práticas de codificação com ESLint e Prettier.

TypeScript    Express    PostgreSQL    Prisma

Tecnologias Utilizadas

  • Node.js
  • Express
  • TypeScript
  • Prisma ORM
  • PostgreSQL
  • ESLint - para manter a qualidade do código
  • Prettier - para formatação do código
  • dotenv - para variáveis de ambiente
  • express-async-errors - para tratamento de erros assíncronos

Instalação

  1. Clone o repositório:

    git clone https://github.com/seu-usuario/nome-do-repositorio.git
    cd nome-do-repositorio
  2. Instale as dependências:

    npm install
  3. Configure as variáveis de ambiente:

    Crie um arquivo .env na raiz do projeto e adicione as seguintes variáveis:

    DATABASE_URL="postgresql://user:password@localhost:5432/mydatabase"
  4. Execute as migrações do banco de dados:

    npx prisma migrate dev

Uso

Para iniciar o servidor, use o comando:

npm run dev

Endpoints

GET /todos

Carrega todas as tarefas.

Response:

[
  { "id": 74, "completed": false, "userId": 4, "title": "expedita tempore nobis eveniet laborum maiores", "createdAt": "2020-07-06T14:30:32.542Z", "updatedAt": "2020-07-06T14:30:32.542Z" },
  { "id": 77, "completed": true, "userId": 4, "title": "consequatur illum asperiores", "createdAt": "2020-07-06T14:30:32.542Z", "updatedAt": "2020-07-06T14:30:32.542Z" },
  { "id": 83, "completed": false, "userId": 5, "title": "rerum est autem sunt rem eveniet architecto", "createdAt": "2020-07-06T14:30:32.542Z", "updatedAt": "2020-07-06T14:30:32.542Z" }
]

Endpoints

GET /todos?userId=2&completed=true

Carrega todas as tarefas concluídas do usuário com ID 2.

Response:

[
  { "id": 77, "completed": true, "userId": 2, "title": "consequatur illum asperiores", "createdAt": "2020-07-06T14:30:32.542Z", "updatedAt": "2020-07-06T14:30:32.542Z" }
]

Endpoints

GET /todos/:id

Carrega uma tarefa pelo ID.

Response:

{
  "id": 74,
  "userId": 4,
  "completed": false,
  "title": "expedita tempore nobis eveniet laborum maiores",
  "createdAt": "2020-07-06T14:30:32.542Z",
  "updatedAt": "2020-07-06T14:30:32.542Z"
}

POST /todos

Cria uma nova tarefa.

Request:

{
  "title": "Learn JS",
  "userId": 4,
  "completed": false
}

Response:

{
  "id": 85,
  "userId": 4,
  "completed": false,
  "title": "Learn JS",
  "createdAt": "2020-07-06T14:30:32.542Z",
  "updatedAt": "2020-07-06T14:30:32.542Z"
}

PATCH /todos/

Atualiza uma tarefa pelo ID.

Request:

{
  "completed": true
}

Response:

{
  "id": 74,
  "userId": 4,
  "completed": true,
  "title": "expedita tempore nobis eveniet laborum maiores",
  "createdAt": "2020-07-06T14:30:32.542Z",
  "updatedAt": "2020-07-06T14:30:32.542Z"
}

DELETE /todos/:id

Exclui uma tarefa pelo ID.

Response:

{
  "message": "No content"
}

Estrutura do Projeto

A estrutura de pastas do projeto é a seguinte:

Estrutura do Projeto

src
├── configs
│   └── database
│       └── prismaClient.ts
├── controllers
│   ├── CreateTodoController.ts
│   ├── DeleteTodoController.ts
│   ├── EditTodoController.ts
│   ├── GetAllTodosController.ts
│   ├── GetTodoController.ts
│   └── index.ts
├── dto
│   ├── EditTodoDTO.ts
│   ├── TodoDTO.ts
│   └── index.ts
├── entities
│   └── Todo.ts
├── errors
│   ├── AppError.ts
│   ├── errorHandler.ts
│   └── index.ts
├── middlewares
│   ├── index.ts
│   ├── verifyEditTodoFields.ts
│   ├── verifyIfIdIsANumber.ts
│   ├── verifyIfTodosExists.ts
│   └── verifyTodoFields.ts
├── repositories
│   └── todo.repository.ts
├── routes
│   └── todo.routes.ts
├── server
│   └── index.ts
├── services
│   ├── CreateTodoService.ts
│   ├── DeleteTodoService.ts
│   ├── EditTodoService.ts
│   ├── GetAllTodosService.ts
│   ├── GetTodoService.ts
│   └── index.ts
├── types
│   └── Filters.ts
└── app.ts
 

Contribuição

Se você quiser contribuir com este projeto, siga estas etapas:

  1. Fork o projeto
  2. Crie uma branch para sua feature (git checkout -b feature/AmazingFeature)
  3. Commit suas mudanças (git commit -m 'Add some AmazingFeature')
  4. Push para a branch (git push origin feature/AmazingFeature)
  5. Abra um Pull Request

Licença

Distribuído sob a licença MIT. Veja LICENSE aqui para mais informações.

Qualquer dúvida ou sugestão, fique à vontade para entrar em contato. Agradeço pelo interesse no projeto!

react_todo-app-api's People

Contributors

mfcastilho avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.