package at.ac.tuwien.inso.controller.lecturer;

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.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.validation.Valid;

import at.ac.tuwien.inso.entity.Grade;
import at.ac.tuwien.inso.service.GradeService;


@Controller
@RequestMapping(value = "/lecturer/addGrade")
public class LecturerAddGradeController {

    @Autowired
    private GradeService gradeService;

    @GetMapping
    public String getPage(@RequestParam("courseId") Long courseId,
                          @RequestParam("studentId") Long studentId,
                          Model model) {
        model.addAttribute("grade",
                gradeService.getDefaultGradeForStudentAndCourse(studentId, courseId));
        return "lecturer/addGrade";
    }

    @PostMapping
    public String saveGrade(@Valid @ModelAttribute("grade") Grade grade,
                            RedirectAttributes redirectAttributes) {
        grade = gradeService.saveNewGradeForStudentAndCourse(grade);
        redirectAttributes.addFlashAttribute("addedGrade", grade);
        return "redirect:/lecturer/courses";
    }

}

@@ -1071,16 +1071,32 @@
 e(%22grade
+AuthorizationDTO
 %22,%0A     
@@ -1130,24 +1130,40 @@
 DefaultGrade
+AuthorizationDTO
 ForStudentAn
@@ -1193,16 +1193,90 @@
 seId));%0A
+        model.addAttribute(%22markOptions%22, gradeService.getMarkOptions());%0A
         
@@ -1388,22 +1388,110 @@
 rade
-%22) Grade grade
+AuthorizationDTO%22)%0A                                        GradeAuthorizationDTO gradeAuthorizationDTO
 ,%0A  
@@ -1561,24 +1561,30 @@
 ) %7B%0A        
+Grade 
 grade = grad
@@ -1625,24 +1625,40 @@
 Course(grade
+AuthorizationDTO
 );%0A        r

Refactor AddGradeController to work with two factor authentification