This file contains hidden or 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
public class LocacaoServiceTest { | |
@Rule | |
public ErrorCollector error = new ErrorCollector(); | |
@Test | |
public void teste() throws Exception { | |
//cenario | |
LocacaoService service = new LocacaoService(); | |
Usuario usuario = new Usuario("Usuario 1"); | |
Filme filme = new Filme("Filme 1", 2, 4.0); |
This file contains hidden or 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
public class LocacaoService { | |
public Locacao alugarFilme(Usuario usuario, Filme filme) throws Exception { | |
if(filme.getEstoque() == 0) { | |
throw new Exception("Filme sem estoque"); | |
} | |
Locacao locacao = new Locacao(); | |
locacao.setFilme(filme); | |
locacao.setUsuario(usuario); | |
locacao.setDataLocacao(new Date()); |
This file contains hidden or 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
public class LocacaoServiceTest { | |
@Rule | |
public ErrorCollector error = new ErrorCollector(); | |
@Test | |
public void teste() throws Exception { | |
// cenario | |
LocacaoService service = new LocacaoService(); | |
Usuario usuario = new Usuario("Usuario 1"); | |
Filme filme = new Filme("Filme 1", 2, 4.0); |
This file contains hidden or 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
@GetMapping() | |
public ResponseEntity<Iterable<Carro>> get() { | |
return ResponseEntity.ok(service.getCarros()); | |
} |
This file contains hidden or 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
@GetMapping("/{id}") | |
public ResponseEntity get(@PathVariable("id") Long id) { | |
Optional<Carro> carro = service.getCarroById(id); | |
if(carro.isPresent()) { | |
return ResponseEntity.ok(carro.get()); | |
} else { | |
return ResponseEntity.notFound().build(); | |
} | |
} |
This file contains hidden or 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
@Query(value = "SELECT * FROM Aluno WHERE nome = :nome", nativeQuery = true) | |
public List<Aluno> procuraPorNome(String nome); |
This file contains hidden or 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
@OneToMany(mappedBy = "categoria") | |
@JsonIgnore | |
private List<Produto> produtos; |
This file contains hidden or 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
@ManyToOne(fetch=FetchType.EAGER) | |
@JoinColumn(name = "categoria_id") | |
private Categoria categoria; | |
@ManyToMany | |
@JoinTable( name = "produto_imagem", | |
joinColumns = @JoinColumn(name="produto_id"), | |
inverseJoinColumns = @JoinColumn(name="imagem_id") | |
) | |
This file contains hidden or 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
@SpringBootApplication | |
public class ApicursoApplication implements CommandLineRunner { | |
@Autowired | |
private ProdutoRepository produtorepository; | |
@Autowired | |
private CategoriaRepository categoriarepository; | |
@Autowired | |
private ImagemRepository imagemRepository; | |
public static void main(String[] args) { |
This file contains hidden or 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
// injeção de dependência do alunoService | |
@Autowired | |
private AlunoService alunoService; | |
// busca a lista com todos os alunos, o @GetMapping recebe a URL onde que vamos usar | |
@GetMapping(value = "alunos") | |
public List<Aluno> getAll() { | |
return this.alunoService.findAll(); | |
} | |