package ciai; import java.util.List; import java.util.Map; import org.springframework.stereotype.Controller; 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.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import ciai.model.Evaluation; import ciai.model.Student; @Controller @RequestMapping(value = "/course") public class CourseController { AppSingleton aa = AppSingleton.getInstance(); Database dd = aa.getDatabase(); @RequestMapping(value = "/view/{id}", method = RequestMethod.GET) public @ResponseBody List getProfessorCourses(@PathVariable String id) { return dd.getStudents(); } @RequestMapping(value = "/view/{id}/evaluations", method = RequestMethod.GET) public @ResponseBody List getEvaluations(@PathVariable String id) { return dd.getEvaluations(); } @RequestMapping(value = "/view/{id}/labs", method = RequestMethod.GET) public @ResponseBody List getLabs(@PathVariable String id) { return dd.getEvaluations(); } @RequestMapping(value = "/view/tests_exams/remove/{id}", method = RequestMethod.POST) public @ResponseBody boolean removeTest_Exam(@PathVariable int id) { return dd.removeTestOrExamFromCourse(id); } @RequestMapping(value = "/view/labSessions/remove/{id}", method = RequestMethod.POST) public @ResponseBody boolean removeLabSession(@PathVariable int id) { return dd.removeLabSessionFromCourse(id); } @RequestMapping(value = "/view/assignments/remove/{id}", method = RequestMethod.POST) public @ResponseBody boolean removeAssignment(@PathVariable int id) { return dd.removeProjectFromCourse(id); } @RequestMapping(value = "/{id}/add/evaluation", method = RequestMethod.POST) public @ResponseBody boolean addEvaluation(@PathVariable String id, @RequestParam Map requestParams) throws Exception{ String name=requestParams.get("name"); String weight=requestParams.get("weight"); String date=requestParams.get("date"); String time=requestParams.get("time"); String type=requestParams.get("type"); double w; try { w = Double.parseDouble(weight); } catch (Exception e) { return false; } return dd.addCourseEvaluation(name,type,0,w,date,time); } @RequestMapping(value = "/{id}/edit/evaluation/{evalid}", method = RequestMethod.POST) public @ResponseBody boolean editEvaluation(@PathVariable String id, @PathVariable String evalid, @RequestParam Map requestParams) throws Exception{ String name=requestParams.get("name"); String weight=requestParams.get("weight"); String date=requestParams.get("date"); String time=requestParams.get("time"); String type=requestParams.get("type"); double w; try { w = Double.parseDouble(weight); } catch (Exception e) { return false; } return dd.editCourseEvaluation(name,type,0,w,date,time,evalid); } }