Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #1

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e59ca74
Update README.md
GabRodrigues23 Oct 23, 2024
687b8bf
Update README.md
GabRodrigues23 Oct 24, 2024
27857de
Update README.md
GabRodrigues23 Oct 24, 2024
e2e57af
Add initial structure for Repositories, Services, and Controllers for…
GabRodrigues23 Nov 4, 2024
2cbe888
Removed irrelevant comments to declutter the code and reorganized cod…
GabRodrigues23 Nov 4, 2024
189950f
Remove unnecessary comments to improve code readability
GabRodrigues23 Nov 5, 2024
b7a5504
Mapped API paths, updated README, and added endpoint documentation
GabRodrigues23 Nov 5, 2024
1435c87
Refactoring Contas a Receber
GabRodrigues23 Nov 5, 2024
e65e1f9
Developing Contas a Pagar, Refactoring Contas a Receber and Update RE…
GabRodrigues23 Nov 5, 2024
e6c0304
Refactored Fornecedor, Developed FornecedorService.java
GabRodrigues23 Nov 5, 2024
d687763
Refactored Cliente, Developed ClienteService.java
GabRodrigues23 Nov 5, 2024
c4a5dbe
Maintenance and Optimization
GabRodrigues23 Nov 6, 2024
a8f06d1
update
GabRodrigues23 Nov 7, 2024
9f405b3
test and update
GabRodrigues23 Nov 7, 2024
3f856b1
moving User.java to optimaze code
GabRodrigues23 Nov 14, 2024
5edd002
developing validation to emissao and vencimento
GabRodrigues23 Nov 14, 2024
d2de72f
deleting exercicios_controllers
GabRodrigues23 Nov 26, 2024
3c44c64
updating validations
GabRodrigues23 Nov 26, 2024
c888e77
Merge branch 'main' into dev
GabRodrigues23 Nov 27, 2024
f90be46
add validations to ContasReceber
GabRodrigues23 Nov 27, 2024
d824f48
add validation to ContasPagar
GabRodrigues23 Nov 27, 2024
d5551b8
add validations to Fornecedor
GabRodrigues23 Nov 27, 2024
a3cf371
refactoring validations to ContasPagar and ContasReceber
GabRodrigues23 Nov 27, 2024
1466406
Add validations to Cliente
GabRodrigues23 Nov 27, 2024
8f151da
Add validations to Cliente
GabRodrigues23 Nov 27, 2024
6df19a8
Deleting unusable comments and correcting grammar
GabRodrigues23 Nov 27, 2024
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
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
# controle-financeiro
# Controle Financeiro

Projeto desenvolvido em aula, utilizando java com Spring Boot.
Projeto desenvolvido durante as aulas do 5º ciclo do curso de Análise e Desenvolvimento de Sistemas na FATEC de Itapetininga, orientado pelo professor de Eletiva de Programação Web, **Danilo Gustavo Albano Valim** - [h2danilofatec](https://github.com/h2danilofatec).

## Participantes

- **Amanda França Marino Santos Lopes Paes** - [Mandy-Marino](https://github.com/Mandy-Marino)
- **Gabriel Rodrigues de Oliveira** - [GabRodrigues23](https://github.com/GabRodrigues23)
- **Gustavo Cesar Kravszenko** - [Kravszenko](https://github.com/Kravszenko)
- **Gustavo Henrique Meira Souza** - [gusmeira88](https://github.com/gusmeira88)
- **Neemias Borges de Matos** - [NeemiasBorges](https://github.com/NeemiasBorges)

## Descrição do Projeto

Este projeto visa fornecer uma plataforma simples e eficaz para o controle de clientes, fornecedores, contas a pagar e contas a receber.

## Funcionalidades

- Cadastro de Clientes e Fornecedores
- Controle de Contas a Pagar
- Controle de Contas a Receber

## Tecnologias Utilizadas

- Java
- Spring Boot

## Como Executar o Projeto

1. Clone o repositório:
```bash
https://github.com/GabRodrigues23/controle-financeiro.git

2. Importe os Endpoints no HoppScotch:
```file
controle-financeiro.json
1 change: 1 addition & 0 deletions controle-financeiro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"v":4,"name":"controle-financeiro","folders":[{"v":4,"name":"Cliente","folders":[],"requests":[{"preRequestScript":"","headers":[],"body":{"body":"{\n \"nome\" : \"Gustavo\"\n}\n\n","contentType":"application/json"},"params":[],"v":"8","method":"POST","requestVariables":[],"testScript":"","endpoint":"http://localhost:8090/api/cliente/create","auth":{"authActive":true,"authType":"inherit"},"responses":{},"name":"Create"},{"v":"8","endpoint":"http://localhost:8090/api/cliente/read","name":"SelectAll","params":[],"headers":[],"method":"GET","auth":{"authType":"inherit","authActive":true},"preRequestScript":"","testScript":"","body":{"contentType":"application/json","body":"\n\n"},"requestVariables":[],"responses":{}},{"v":"8","endpoint":"http://localhost:8090/api/cliente/read/1","preRequestScript":"","headers":[],"method":"GET","responses":{},"testScript":"","requestVariables":[],"name":"SelectById","params":[],"body":{"body":"\n\n","contentType":"application/json"},"auth":{"authType":"inherit","authActive":true}},{"method":"PUT","preRequestScript":"","requestVariables":[],"testScript":"","body":{"body":"{\n \"nome\" : \"Gustavo Kravszenko\"\n}\n\n","contentType":"application/json"},"auth":{"authType":"inherit","authActive":true},"responses":{},"v":"8","endpoint":"http://localhost:8090/api/cliente/update/1","headers":[],"params":[],"name":"Update"},{"endpoint":"http://localhost:8090/api/cliente/delete/1","auth":{"authType":"inherit","authActive":true},"params":[],"requestVariables":[],"testScript":"","body":{"body":"\n\n","contentType":"application/json"},"preRequestScript":"","name":"Delete","method":"DELETE","v":"8","responses":{},"headers":[]}],"auth":{"authType":"inherit","authActive":true},"headers":[]},{"v":4,"name":"Fornecedor","folders":[],"requests":[{"headers":[],"name":"Create","v":"8","testScript":"","preRequestScript":"","params":[],"requestVariables":[],"endpoint":"http://localhost:8090/api/fornecedor/create","responses":{},"method":"POST","auth":{"authActive":true,"authType":"inherit"},"body":{"body":"{\n \"nome\" : \"Neemias Borges\"\n}\n\n","contentType":"application/json"}},{"auth":{"authType":"inherit","authActive":true},"v":"8","responses":{},"body":{"contentType":"application/json","body":""},"headers":[],"testScript":"","params":[],"endpoint":"http://localhost:8090/api/fornecedor/read","name":"SelectAll","preRequestScript":"","method":"GET","requestVariables":[]},{"headers":[],"testScript":"","preRequestScript":"","v":"8","responses":{},"method":"GET","auth":{"authActive":true,"authType":"inherit"},"name":"SelectById","params":[],"endpoint":"http://localhost:8090/api/fornecedor/read/1","body":{"body":"","contentType":"application/json"},"requestVariables":[]},{"body":{"contentType":"application/json","body":"{\n \"nome\" : \"Amanda Marino\"\n}\n\n"},"params":[],"method":"PUT","responses":{},"preRequestScript":"","requestVariables":[],"auth":{"authType":"inherit","authActive":true},"v":"8","name":"Update","testScript":"","headers":[],"endpoint":"http://localhost:8090/api/fornecedor/update/1"},{"method":"DELETE","headers":[],"v":"8","requestVariables":[],"params":[],"testScript":"","body":{"contentType":"application/json","body":""},"preRequestScript":"","endpoint":"http://localhost:8090/api/fornecedor/delete/1","auth":{"authActive":true,"authType":"inherit"},"name":"Delete","responses":{}}],"auth":{"authActive":true,"authType":"inherit"},"headers":[]},{"v":4,"name":"ContasPagar","folders":[],"requests":[{"body":{"contentType":"application/json","body":""},"responses":{},"method":"POST","requestVariables":[],"headers":[],"auth":{"authType":"inherit","authActive":true},"testScript":"","v":"8","params":[],"name":"Create","preRequestScript":"","endpoint":"http://localhost:8090/api/contaspagar/create"},{"auth":{"authType":"inherit","authActive":true},"v":"8","responses":{},"body":{"contentType":"application/json","body":""},"headers":[],"testScript":"","params":[],"endpoint":"http://localhost:8090/api/contaspagar/read","name":"SelectAll","preRequestScript":"","method":"GET","requestVariables":[]},{"body":{"contentType":"application/json","body":""},"params":[],"method":"GET","responses":{},"preRequestScript":"","requestVariables":[],"auth":{"authType":"inherit","authActive":true},"v":"8","name":"SelectById","testScript":"","headers":[],"endpoint":"http://localhost:8090/api/contaspagar/read/1"},{"body":{"contentType":"application/json","body":""},"params":[],"method":"PUT","responses":{},"preRequestScript":"","requestVariables":[],"auth":{"authType":"inherit","authActive":true},"v":"8","name":"Update","testScript":"","headers":[],"endpoint":"http://localhost:8090/api/contaspagar/update/1"},{"method":"DELETE","body":{"contentType":"application/json","body":""},"requestVariables":[],"auth":{"authActive":true,"authType":"inherit"},"responses":{},"headers":[],"v":"8","testScript":"","endpoint":"http://localhost:8090/api/contaspagar/delete/1","name":"Delete","params":[],"preRequestScript":""}],"auth":{"authType":"inherit","authActive":true},"headers":[]},{"v":4,"name":"ContasReceber","folders":[],"requests":[{"requestVariables":[],"params":[],"body":{"contentType":"application/json","body":""},"method":"POST","responses":{},"headers":[],"v":"8","preRequestScript":"","endpoint":"http://localhost:8090/api/contasreceber/create","name":"Create","testScript":"","auth":{"authType":"inherit","authActive":true}},{"auth":{"authType":"inherit","authActive":true},"v":"8","responses":{},"body":{"contentType":"application/json","body":""},"headers":[],"testScript":"","params":[],"endpoint":"http://localhost:8090/api/contasreceber/read","name":"SelectAll","preRequestScript":"","method":"GET","requestVariables":[]},{"body":{"contentType":"application/json","body":""},"params":[],"method":"GET","responses":{},"preRequestScript":"","requestVariables":[],"auth":{"authType":"inherit","authActive":true},"v":"8","name":"SelectById","testScript":"","headers":[],"endpoint":"http://localhost:8090/api/contasreceber/read/1"},{"body":{"contentType":"application/json","body":""},"params":[],"method":"PUT","responses":{},"preRequestScript":"","requestVariables":[],"auth":{"authType":"inherit","authActive":true},"v":"8","name":"Update","testScript":"","headers":[],"endpoint":"http://localhost:8090/api/contasreceber/update/1"},{"v":"8","preRequestScript":"","method":"DELETE","headers":[],"responses":{},"auth":{"authType":"inherit","authActive":true},"body":{"body":"","contentType":"application/json"},"params":[],"testScript":"","endpoint":"http://localhost:8090/api/contasreceber/delete/1","requestVariables":[],"name":"Delete"}],"auth":{"authActive":true,"authType":"inherit"},"headers":[]}],"requests":[],"auth":{"authType":"none","authActive":true},"headers":[]}
8 changes: 7 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.2</version>
<version>3.3.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.fatec</groupId>
Expand All @@ -30,6 +30,12 @@
<java.version>17</java.version>
</properties>
<dependencies>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
public void addCorsMappings(@SuppressWarnings("null") CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*") // Permite todas as origens
.allowedMethods("*")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,124 +1,72 @@
package com.fatec.controle_financeiro.controllers;

import com.fatec.controle_financeiro.domain.cliente.ClienteRepository;
import com.fatec.controle_financeiro.domain.cliente.ClienteService;
import com.fatec.controle_financeiro.entities.Cliente;
import com.fatec.controle_financeiro.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.fatec.controle_financeiro.domain.cliente.ClienteService;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/cliente")
public class ClienteController {
private ClienteService clienteService;

@Autowired
private ClienteRepository clienteRepository;

private List<Cliente> clientes = new ArrayList<>();
private int proximoId = 1;

//CRUD = CREATE, READ, UPDATE E DELETE
public ClienteController(ClienteService clienteService) {
this.clienteService = clienteService;
}

//CREATE
@PostMapping()
public ResponseEntity<Cliente> create(@RequestBody Cliente cliente) {

/*for (Cliente cli : clientes) {
if (cli.getName().equals(cliente.getName())) {
throw new IllegalArgumentException("ja existe nome");
}
// CREATE
@PostMapping("/create")
public ResponseEntity<?> create(@RequestBody Cliente cliente) {
try {
Cliente clienteCreated = clienteService.create(cliente);
return new ResponseEntity<>(clienteCreated, HttpStatus.CREATED);
} catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().body(ex.getMessage());
} catch (Exception ex){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}

cliente.setId(proximoId++);
clientes.add(cliente);

return new ResponseEntity<>(cliente, HttpStatus.CREATED);*/
Cliente clienteCreated = clienteRepository.save(cliente);
return new ResponseEntity<>(clienteCreated, HttpStatus.CREATED);
}


//READ
@GetMapping()
// READ ALL
@GetMapping("/read")
public ResponseEntity<List<Cliente>> getAllCliente() {
//SELECT * FROM CLIENTES
List<Cliente> clientes = clienteRepository.findAll();

List<Cliente> clientes = clienteService.findAll();
return new ResponseEntity<>(clientes, HttpStatus.OK);
}

@GetMapping("{id}")
public ResponseEntity<Cliente> getById(@PathVariable int id) {
/*for (Cliente cliente : clientes) {
if (cliente.getId() == id) {
return new ResponseEntity<>(cliente, HttpStatus.OK);
}
}
// Se o cliente não for encontrado, retorna status 404 Not Found
return new ResponseEntity<>(HttpStatus.NOT_FOUND);*/

//select * from cliente where id = {id}
Optional<Cliente> cliente = clienteRepository.findById(id);
if (cliente.isPresent()) {
return new ResponseEntity<>(cliente.get(), HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
// READ BY ID
@GetMapping("/read/{id}")
public ResponseEntity<Cliente> getById(@PathVariable Long id) {
return clienteService.findById(id)
.map(cliente -> new ResponseEntity<>(cliente, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

//UPDATE
@PutMapping("{id}")
public ResponseEntity<Cliente> updateCliente(@PathVariable int id, @RequestBody Cliente entity) {
// Percorre a lista de clientes para encontrar o cliente com o ID correspondente
/*for (Cliente cliente : clientes) {
if (cliente.getId() == id) {
// Se o cliente for encontrado, atualiza suas informações
cliente.setName(entity.getName());
// Retorna o cliente atualizado com status 200 OK
return new ResponseEntity<>(cliente, HttpStatus.OK);
}
}
// Se o cliente não for encontrado, retorna status 404 Not Found
return new ResponseEntity<>(HttpStatus.NOT_FOUND);*/

Optional<Cliente> clienteAtual = clienteRepository.findById(id);
if (clienteAtual.isPresent()) {
entity.setId(id);
clienteRepository.save(entity);
return new ResponseEntity<>(entity, HttpStatus.OK);
} else {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
// UPDATE
@PutMapping("/update/{id}")
public ResponseEntity<?> updateCliente(@PathVariable Long id, @RequestBody Cliente entity) {
try {
Cliente updated = clienteService.update(id, entity);
return new ResponseEntity<>(updated, HttpStatus.OK);
} catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().body(ex.getMessage());
} catch (Exception ex){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

//DELETE
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteCliente(@PathVariable int id) {
// Percorre a lista de clientes para encontrar o cliente com o ID correspondente
/*for (Cliente cliente : clientes) {
if (cliente.getId() == id) {
// Se o cliente for encontrado, remove-o da lista
clientes.remove(cliente);
// Retorna status 204 No Content
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}
// Se o cliente não for encontrado, retorna status 404 Not Found
return new ResponseEntity<>(HttpStatus.NOT_FOUND);*/

Optional<Cliente> clienteAtual = clienteRepository.findById(id);
if (clienteAtual.isPresent()) {
clienteRepository.deleteById(id);
// DELETE
@DeleteMapping("/delete/{id}")
public ResponseEntity<?> deleteCliente(@PathVariable Long id) {
try {
clienteService.delete(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} else {
} catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().body(ex.getMessage());
} catch (Exception ex){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.fatec.controle_financeiro.controllers;
import com.fatec.controle_financeiro.entities.ContasPagar;
import com.fatec.controle_financeiro.domain.contaspagar.ContasPagarService;

import java.util.List;

import org.springframework.http.HttpStatus;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/contaspagar")
public class ContasPagarController {
private final ContasPagarService pagarService;

public ContasPagarController(ContasPagarService pagarService){
this.pagarService = pagarService;
}

// CREATE
@PostMapping("/create")
public ResponseEntity<?> create(@RequestBody ContasPagar pagar) {
try {
ContasPagar pagarCreated = pagarService.create(pagar);
return new ResponseEntity<>(pagarCreated, HttpStatus.CREATED);
} catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().body(ex.getMessage());
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Erro inesperado: " + ex.getMessage());
}
}

// READ ALL
@GetMapping("/read")
public ResponseEntity<List<ContasPagar>> getAllPagar() {
List<ContasPagar> contasPagar = pagarService.findAll();
return new ResponseEntity<>(contasPagar, HttpStatus.OK);
}

// READ BY ID
@GetMapping("/read/{id}")
public ResponseEntity<ContasPagar> getById(@PathVariable Long id) {
return pagarService.findById(id)
.map(pagar -> new ResponseEntity<>(pagar, HttpStatus.OK))
.orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}

// UPDATE
@PutMapping("/update/{id}")
public ResponseEntity<?> updatePagar(@PathVariable Long id, @RequestBody ContasPagar entity) {
try {
ContasPagar updated = pagarService.update(id, entity);
return new ResponseEntity<>(updated, HttpStatus.OK);
} catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().body(ex.getMessage());
} catch (Exception ex){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}

// DELETE
@DeleteMapping("/delete/{id}")
public ResponseEntity<?> deletePagar(@PathVariable Long id) {
try {
pagarService.delete(id);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
} catch (IllegalArgumentException ex) {
return ResponseEntity.badRequest().body(ex.getMessage());
} catch (Exception ex){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
}
Loading