Created
June 6, 2015 19:42
-
-
Save victorximenis/37b5018122e33878705d to your computer and use it in GitHub Desktop.
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.unipe.dsw.controller; | |
import br.unipe.dsw.entity.Categoria; | |
import br.unipe.dsw.entity.Hospede; | |
import br.unipe.dsw.entity.Quarto; | |
import br.unipe.dsw.entity.Reserva; | |
import br.unipe.dsw.repository.HospedeRepository; | |
import br.unipe.dsw.repository.QuartoRepository; | |
import br.unipe.dsw.repository.ReservaRepository; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.ui.ModelMap; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
/** | |
* Created by Victor on 05/06/2015. | |
*/ | |
@Controller | |
@RequestMapping("/reserva") | |
public class ReservaController { | |
@Autowired | |
ReservaRepository reservaRepository; | |
@Autowired | |
HospedeRepository hospedeRepository; | |
@Autowired | |
QuartoRepository quartoRepository; | |
@RequestMapping(value = "/list") | |
public String list(ModelMap modelMap){ | |
List<Reserva> reservaList = (List<Reserva>)reservaRepository.findAll(); | |
modelMap.addAttribute("reservas", reservaList); | |
return "reserva/list"; | |
} | |
@RequestMapping(value = "/nova", method = RequestMethod.GET) | |
public String create(ModelMap modelMap){ | |
Reserva reserva; | |
reserva = new Reserva(); | |
reserva.setHospede(new Hospede()); | |
reserva.setQuarto(new Quarto()); | |
modelMap.addAttribute("quartos", selectQuarto()); | |
modelMap.addAttribute("hospedes", selectHospede()); | |
modelMap.addAttribute("reserva", reserva); | |
return "reserva/nova"; | |
} | |
public Map<Long, String> selectHospede(){ | |
List<Hospede> hospedes = (List<Hospede>)hospedeRepository.findAll(); | |
Map<Long, String> mapa = new HashMap<Long, String>(); | |
for(Hospede hospede:hospedes){ | |
mapa.put(hospede.getId(), hospede.getNome()); | |
} | |
return mapa; | |
} | |
public Map<Long, String> selectQuarto(){ | |
List<Quarto> quartos = (List<Quarto>)quartoRepository.findAll(); | |
Map<Long, String> mapa = new HashMap<Long, String>(); | |
for(Quarto quarto:quartos){ | |
mapa.put(quarto.getId(), quarto.getNumero()); | |
} | |
return mapa; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment