// Path: ch06/src/main/java/info/thecodinglive/model/Team.java
// @Entity
// @Table(name="teams")
// public class Team {
//     @Id
//     @GeneratedValue
//     private Integer id;
//     
// 	private String teamName;
// 
//     private Integer rating;
// 
//     public String getTeamName() {
// 		return teamName;
// 	}
// 	public void setTeamName(String teamName) {
// 		this.teamName = teamName;
// 	}
// 
// 
//     public Integer getId() {
//         return id;
//     }
//     public void setId(Integer id) {
//         this.id = id;
//     }
// 
//     public Integer getRating() {
//         return rating;
//     }
//     public void setRating(Integer rating) {
//         this.rating = rating;
//     }
// }
// 
// Path: ch06/src/main/java/info/thecodinglive/service/TeamService.java
// public interface TeamService {
//     public void addTeam(Team team);
//     public void updateTeam(Team team);
//     public Team getTeam(int id);
//     public void deleteTeam(int id);
//     public List<Team> getTeams();
// }


import info.thecodinglive.model.Team;
import info.thecodinglive.service.TeamService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
		
		return "team";
	}
	
	
	  @RequestMapping(value = "/add", method = RequestMethod.POST)
	    public String addingTeam(@ModelAttribute("teamForm")Team team, Model m, BindingResult result){
	        
	        teamService.addTeam(team);

	        String message = "team was successful added";
	        m.addAttribute("message", message);

	        return "home";
	    }
	  
	
	  @RequestMapping(value = "/delete/{id}", method= RequestMethod.GET)
	  public String deleteTeam(@PathVariable Integer id, Model m){
		  
		  teamService.deleteTeam(id);
		  
		  String message = "team was succefuly deleted";
		  m.addAttribute("message", message);
		  
		  return "home";
	  }
	  
	  
		@RequestMapping(value="/edit/{id}", method=RequestMethod.GET)
// Path: ch06/src/main/java/info/thecodinglive/model/Team.java
// @Entity
// @Table(name="teams")
// public class Team {
//     @Id
//     @GeneratedValue
//     private Integer id;
//     
// 	private String teamName;
// 
//     private Integer rating;
// 
//     public String getTeamName() {
// 		return teamName;
// 	}
// 	public void setTeamName(String teamName) {
// 		this.teamName = teamName;
// 	}
// 
// 
//     public Integer getId() {
//         return id;
//     }
//     public void setId(Integer id) {
//         this.id = id;
//     }
// 
//     public Integer getRating() {
//         return rating;
//     }
//     public void setRating(Integer rating) {
//         this.rating = rating;
//     }
// }
// 
// Path: ch06/src/main/java/info/thecodinglive/service/TeamService.java
// public interface TeamService {
//     public void addTeam(Team team);
//     public void updateTeam(Team team);
//     public Team getTeam(int id);
//     public void deleteTeam(int id);
//     public List<Team> getTeams();
// }


// Path: ch06/src/main/java/info/thecodinglive/controller/TeamController.java
import info.thecodinglive.model.Team;
import info.thecodinglive.service.TeamService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

		
		return "team";
	}
	
	
	  @RequestMapping(value = "/add", method = RequestMethod.POST)
	    public String addingTeam(@ModelAttribute("teamForm")Team team, Model m, BindingResult result){
	        
	        teamService.addTeam(team);

	        String message = "team was successful added";
	        m.addAttribute("message", message);

	        return "home";
	    }
	  
	
	  @RequestMapping(value = "/delete/{id}", method= RequestMethod.GET)
	  public String deleteTeam(@PathVariable Integer id, Model m){
		  
		  teamService.deleteTeam(id);
		  
		  String message = "team was succefuly deleted";
		  m.addAttribute("message", message);
		  
		  return "home";
	  }
	  
	  
		@RequestMapping(value="/edit/{id}", method=RequestMethod.GET)
		public String editTeamPage(ModelMap model, @PathVariable Integer id){