Skip to content

Commit

Permalink
Merge pull request #24 from Joaquimborges/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
lexscruz committed Nov 1, 2021
2 parents 997022b + 2440135 commit a072d6e
Show file tree
Hide file tree
Showing 20 changed files with 489 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.bootcamp_w3_g3.model.entity.Armazem;
import com.bootcamp_w3_g3.service.ArmazemService;
import com.bootcamp_w3_g3.service.RepresentanteService;
import com.bootcamp_w3_g3.service.SetorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,7 +13,7 @@
import java.util.List;

@RestController
@RequestMapping("armazem")
@RequestMapping("armazem/")
public class ArmazemController {

@Autowired
Expand All @@ -23,12 +22,10 @@ public class ArmazemController {
@Autowired
private RepresentanteService representanteService;

@Autowired
private SetorService setorService;

@PostMapping("/criar")
public ResponseEntity<ArmazemDTO> criarArmazem(@RequestBody ArmazemForm armazemForm) {
Armazem armazem = armazemService.criarArmazem(armazemForm.converte(representanteService, setorService));
Armazem armazem = armazemService.criarArmazem(armazemForm.converte(representanteService));

return new ResponseEntity<>(ArmazemDTO.converter(armazem), HttpStatus.CREATED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,10 @@ public ResponseEntity<ProdutoDTO> alterar(@RequestBody ProdutoForm produtoForm)
* @return produtoDTO
*/
@DeleteMapping(value="/deletar/{cod}")
public Produto apagar(@PathVariable Long cod)
public ResponseEntity<Produto> apagar(@PathVariable Long cod)
{
return produtoService.apagar(cod);
produtoService.apagar(cod);
return new ResponseEntity<>(HttpStatus.OK);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.NoSuchElementException;

@RestController
@RequestMapping("representante")
@RequestMapping("representante/")
public class RepresentanteController {

@Autowired
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/bootcamp_w3_g3/controller/SetorController.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @author hugo damm
*/
@RestController
@RequestMapping("setor")
@RequestMapping("setor/")
public class SetorController {

@Autowired
Expand All @@ -31,22 +31,22 @@ public ResponseEntity<SetorDTO> salvar(@RequestBody SetorForm setorForm){
return new ResponseEntity<>(SetorDTO.converter(setor), HttpStatus.CREATED);
}

@DeleteMapping("/remover")
public String remover(@PathVariable String codigo) {
setorService.removerSetor(codigo);
@DeleteMapping("/remover/{id}")
public String remover(@PathVariable Long id) {
setorService.removerSetor(id);

return "Setor removido";
}

@GetMapping("/obter/{id}")
@GetMapping("/obter/{codigo}")
public ResponseEntity<SetorDTO> obter(@PathVariable String codigo){
Setor setor = setorService.obterSetor(codigo);
return new ResponseEntity<>(SetorDTO.converter(setor), HttpStatus.OK);
}

@GetMapping("/listar")
public ResponseEntity<List<SetorDTO>> listar(){
List<Setor> setores = setorService.listarSetores();
@GetMapping("/listar/{armazem_id}")
public ResponseEntity<List<SetorDTO>> listar(@PathVariable Long armazem_id){
List<Setor> setores = setorService.lista(armazem_id);
return new ResponseEntity<>(SetorDTO.converterLista(setores), HttpStatus.OK);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

import com.bootcamp_w3_g3.model.entity.Armazem;
import com.bootcamp_w3_g3.model.entity.Representante;
import com.bootcamp_w3_g3.model.entity.Setor;
import com.bootcamp_w3_g3.service.RepresentanteService;
import com.bootcamp_w3_g3.service.SetorService;
import lombok.*;


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

@AllArgsConstructor
@NoArgsConstructor
Expand All @@ -25,7 +22,7 @@ public class ArmazemForm {
private String uf;
private RepresentanteForm representanteForm;

public Armazem converte(RepresentanteService representanteService, SetorService setorService) {
public Armazem converte(RepresentanteService representanteService) {
Representante representante = representanteService.obter(representanteForm.getCodigo());

return Armazem.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* @author hugo damm
* @autor Joaquim Borges
*/

@NoArgsConstructor
Expand All @@ -24,18 +24,18 @@ public class SetorForm {
private String tipoProduto;
private ArmazemForm armazem;
private Integer espacoDisponivel = 100;
private List<LoteForm> lote;


//private List<Lote> lote;


public Setor converte(ArmazemService armazemService){
Armazem armazem = armazemService.obterArmazem(this.armazem.getCodArmazem());
return Setor.builder()
.codigo(codigo)
.nome(nome)
.tipoProduto(tipoProduto)
.armazem(armazem).build();
.armazem(armazem)
.build();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class ArmazemDTO {
private String nome;
private String endereco;
private String uf;
private Representante representante;
private RepresentanteDTO representanteDTO;

public static ArmazemDTO converter(Armazem armazem) {

Expand All @@ -30,15 +30,15 @@ public static ArmazemDTO converter(Armazem armazem) {
armazem.getNome(),
armazem.getEndereco(),
armazem.getUf(),
armazem.getRepresentante()
RepresentanteDTO.converteEmRepresentanteDTO(armazem.getRepresentante())

);

}


public static List<ArmazemDTO> armazemDTOListConverte(List<Armazem> armazemList) {
List<ArmazemDTO> armazemDTOList = new ArrayList<>();

for (Armazem armazem : armazemList) {

armazemDTOList.add(
Expand All @@ -47,7 +47,7 @@ public static List<ArmazemDTO> armazemDTOListConverte(List<Armazem> armazemList)
armazem.getNome(),
armazem.getEndereco(),
armazem.getUf(),
armazem.getRepresentante()
RepresentanteDTO.converteEmRepresentanteDTO(armazem.getRepresentante())
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ public class SetorDTO {
private String codigo;
private String nome;
private String tipoProduto;
private Armazem armazem;
private List<Lote> lote;
private ArmazemDTO armazemDTO;

public static SetorDTO converter(Setor setor){
return SetorDTO.builder()
.codigo(setor.getCodigo())
.nome(setor.getNome())
.tipoProduto(setor.getTipoProduto())
.armazem(setor.getArmazem()).build();
.armazemDTO(ArmazemDTO.converter(setor.getArmazem())).build();
}

public static List<SetorDTO> converterLista(List<Setor> setorList){
Expand All @@ -37,8 +36,7 @@ public static List<SetorDTO> converterLista(List<Setor> setorList){
.codigo(setor.getCodigo())
.nome(setor.getNome())
.tipoProduto(setor.getTipoProduto())
.armazem(setor.getArmazem())
.build());
.armazemDTO(ArmazemDTO.converter(setor.getArmazem())).build());
}
return setorDTOList;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/bootcamp_w3_g3/model/entity/Armazem.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@


import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;


@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Getter
@Setter
@Entity
@SuperBuilder
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Representante {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/bootcamp_w3_g3/model/entity/Setor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


import javax.persistence.*;
import java.util.List;


/**
* @author hugo damm
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/bootcamp_w3_g3/service/ArmazemService.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ public Armazem obterArmazem(String cod) {
return armazemRepository.findByCodArmazem(cod);
}

public Armazem deletarArmazem(String cod){
return armazemRepository.deleteByCodArmazem(cod);
public Armazem deletarArmazem(Long id){
armazemRepository.deleteById(id);
return null;
}

public Armazem atualizarArmazem(Armazem armazem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public List<Representante> listar() {

public Representante atualizar(Representante representante) {
Representante representanteEdited = representanteRepository.getByCodigo(representante.getCodigo());
representanteEdited.setNome(representante.getNome());
representanteEdited.setSobrenome(representante.getSobrenome());
representanteEdited.setTelefone(representante.getTelefone());
representanteEdited.setEndereco(representante.getEndereco());

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/bootcamp_w3_g3/service/SetorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public Setor get(Long id){
}

public Setor obterSetor(String codigo){
Setor setor = setorRepository.findByCodigo(codigo);
return setor;
return setorRepository.findByCodigo(codigo);

}

public List<Setor> listarSetores(){
Expand All @@ -51,16 +51,16 @@ public List<Setor> lista(Long armazemId){
public Setor atualizarSetor(Setor setor){
Setor editedSetor = setorRepository.findByCodigo(setor.getCodigo());

editedSetor.setCodigo(setor.getCodigo());
editedSetor.setNome(setor.getNome());
editedSetor.setTipoProduto(setor.getTipoProduto());
editedSetor.setArmazem(setor.getArmazem());

return setorRepository.save(editedSetor);
}

public Setor removerSetor(String codigo) {
return setorRepository.deleteByCodigo(codigo);
public Setor removerSetor(Long id) {
setorRepository.deleteById(id);
return null;
}

}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/armazem-w3
spring.datasource.username= postgres
spring.datasource.password= lUk3nyb@
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.ddl-auto=create-drop

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
Expand Down

0 comments on commit a072d6e

Please sign in to comment.