-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
criado crud do endereco, e endpoint do tipo put do documento e telefone
- Loading branch information
1 parent
d357413
commit 133f18a
Showing
7 changed files
with
122 additions
and
1 deletion.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
automanager/src/main/java/com/autobots/automanager/controles/AtualizarEndereco.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.autobots.automanager.controles; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.autobots.automanager.entidades.Cliente; | ||
import com.autobots.automanager.repositorios.ClienteRepositorio; | ||
|
||
@RestController | ||
public class AtualizarEndereco { | ||
|
||
@Autowired | ||
private ClienteRepositorio repositorio; | ||
|
||
@PutMapping("/atualizar-endereco") | ||
public void atualizarEnderecoCliente(@RequestBody Cliente cliente) { | ||
Cliente selecionado = repositorio.getById(cliente.getId()); | ||
selecionado.setEndereco(cliente.getEndereco()); | ||
repositorio.save(selecionado); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
automanager/src/main/java/com/autobots/automanager/controles/EnderecoControle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.autobots.automanager.controles; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.autobots.automanager.entidades.Endereco; | ||
import com.autobots.automanager.modelo.EnderecoAtualizador; | ||
import com.autobots.automanager.repositorios.EnderecoRepositorio; | ||
|
||
@RestController | ||
@RequestMapping("/endereco") | ||
public class EnderecoControle { | ||
|
||
@Autowired | ||
private EnderecoRepositorio repositorio; | ||
|
||
@GetMapping("/enderecos") | ||
public List<Endereco> buscarEnderecos(){ | ||
return repositorio.findAll(); | ||
} | ||
|
||
@GetMapping("/endereco/{id}") | ||
public Endereco buscarEnderecoPorId(@PathVariable Long id) { | ||
return repositorio.findById(id).get(); | ||
} | ||
|
||
@PutMapping("/atualizar") | ||
public void editarEnderecoPorId(@RequestBody Endereco atualizacao) { | ||
Endereco enderecoSelecionado = repositorio.getById(atualizacao.getId()); | ||
EnderecoAtualizador atualizador = new EnderecoAtualizador(); | ||
atualizador.atualizar(enderecoSelecionado, atualizacao); | ||
repositorio.save(enderecoSelecionado); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
automanager/src/main/java/com/autobots/automanager/controles/ExcluirEndereco.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.autobots.automanager.controles; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.autobots.automanager.entidades.Cliente; | ||
import com.autobots.automanager.repositorios.ClienteRepositorio; | ||
import com.autobots.automanager.repositorios.EnderecoRepositorio; | ||
|
||
@RestController | ||
public class ExcluirEndereco { | ||
|
||
@Autowired | ||
private ClienteRepositorio repositorio; | ||
|
||
@Autowired | ||
private EnderecoRepositorio enderecoRepo; | ||
|
||
@DeleteMapping("/excluir-endereco") | ||
public void excluirClienteEndereco(@RequestBody Cliente cliente) { | ||
Cliente selecionado = repositorio.getById(cliente.getId()); | ||
enderecoRepo.delete(selecionado.getEndereco()); | ||
selecionado.setEndereco(null); | ||
repositorio.save(selecionado); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
automanager/src/main/java/com/autobots/automanager/repositorios/EnderecoRepositorio.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.autobots.automanager.repositorios; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.autobots.automanager.entidades.Endereco; | ||
|
||
public interface EnderecoRepositorio extends JpaRepository<Endereco, Long>{ | ||
|
||
} |