package com.example.demo.data;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.example.demo.model.Employee;

@Controller
@RequestMapping("/emps3")
public class Controller3 {

	@Autowired
	private Repository3_Interfejs repository;
	
	@GetMapping
	public String readAll(Model model) {
		List<Employee> emps = repository.findAll();
		model.addAttribute("emps", emps);
		return "employees";
	}
	
	@GetMapping("/{id}")
	public String readOne(Model model,
			@PathVariable("id") Integer idPracownika) {
		Employee emp = repository.findById(idPracownika);
		List<Employee> emps = List.of(emp);
		model.addAttribute("emps", emps);
		return "employees";
	}
}
