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
package br.com.paydomestic.service; | |
import java.io.Serializable; | |
import java.util.List; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
public interface CrudService<E, idEntity extends Serializable> { | |
public List<E> findAll(); |
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
package br.com.paydomestic.service; | |
import java.io.Serializable; | |
import java.util.List; | |
public abstract class AbstractService<E, idEntity extends Serializable> implements CrudService<E, idEntity> { | |
@Override | |
public List<E> findAll() { | |
return getRepository().findAll(); |
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
package br.com.paydomestic.service; | |
import java.util.Date; | |
import java.util.List; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.data.jpa.repository.JpaRepository; | |
import org.springframework.stereotype.Service; | |
import org.springframework.transaction.annotation.Transactional; |
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
package com.example; | |
import java.io.Serializable; | |
import java.util.Date; | |
import javax.persistence.Column; | |
import javax.persistence.Entity; | |
import javax.persistence.GeneratedValue; | |
import javax.persistence.GenerationType; | |
import javax.persistence.Id; |
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
@PutMapping("/salarios/{salario_id}/editar") | |
public String save(Model model, @PathVariable("salario_id") Integer id, RedirectAttributes redirectAttributes) { | |
try { | |
if (id != null) { | |
SalarioMinimo salarioMinimo = (SalarioMinimo) salarioMinimoService.findOne(id); | |
salarioMinimoService.save(salarioMinimo); | |
redirectAttributes.addFlashAttribute("sucesso", "Salário Editado com sucesso."); | |
} | |
} catch (Exception e) { | |
e.printStackTrace(); |
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
@Autowired | |
private JdbcTemplate jdbcTemplate; | |
@After | |
public void tearDown() { | |
JdbcTestUtils.deleteFromTables(jdbcTemplate, "salarios_minimos"); | |
} |
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
@Test | |
public void testPUTSalarioMinimoController() throws Exception { | |
SalarioMinimo salarioMinimo = (SalarioMinimo) salarioMinimoService.save(new SalarioMinimo("AL", "800", new SimpleDateFormat("dd/MM/yyyy").parse("01/01/2016"), new SimpleDateFormat("dd/MM/yyyy").parse("01/02/2016"), "decreto test")); | |
this.mockMvc.perform(MockMvcRequestBuilders.put("/salarios/" + salarioMinimo.getId() + "/editar")).andExpect(MockMvcResultMatchers.redirectedUrl("/salarios")); | |
} |
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
@PostMapping("/salarios") | |
public String save(@Valid @ModelAttribute("salarioMinimo") SalarioMinimo salarioMinimo, BindingResult bindingResult, RedirectAttributes redirectAttributes) { | |
try { | |
salarioMinimoService.save(salarioMinimo); | |
redirectAttributes.addFlashAttribute("sucesso", "Salário salvo com sucesso."); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
redirectAttributes.addFlashAttribute("error", "Problema ao salvar salário."); | |
} | |
return "redirect:/salarios/novo"; |
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
@Test | |
public void testPOSTSaveSalarioMinimoController() throws Exception { | |
this.mockMvc.perform(MockMvcRequestBuilders.post("/salarios") | |
.param("estado", "BR") | |
.param("salario", "800") | |
.param("dataInicio", "01/01/2016") | |
.param("dataFim", "02/02/2016") | |
).andExpect(MockMvcResultMatchers.redirectedUrl("/salarios/novo")); | |
} |
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
package com.example; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.Model; | |
import org.springframework.web.bind.annotation.GetMapping; | |
import org.springframework.web.bind.annotation.ModelAttribute; | |
import org.springframework.web.bind.annotation.ResponseBody; | |
@Controller | |
public class SalarioMinimoController { |