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

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
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.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.security.Principal;
import java.util.List;

import at.ac.tuwien.inso.controller.Constants;
import at.ac.tuwien.inso.entity.Course;
import at.ac.tuwien.inso.entity.Student;
import at.ac.tuwien.inso.service.CourseService;
import at.ac.tuwien.inso.service.StudentService;
import at.ac.tuwien.inso.service.UserAccountService;
import at.ac.tuwien.inso.service.course_recommendation.RecommendationService;

@Controller
@RequestMapping("/student/recommended")
public class StudentRecommendedCoursesController {

    private static final Logger log = LoggerFactory.getLogger(StudentMyCoursesController.class);


    @Autowired
    private StudentService studentService;

    @Autowired
    private RecommendationService recommendationService;


    @ModelAttribute("recommendedCourses")
    private List<Course> getRecommendedCourses(Principal principal) {

        log.info("Getting recommendation for student: [{}]", principal.getName());

        Student student = studentService.findByUsername(principal.getName());

        return recommendationService.recommendCoursesSublist(student);
    }


    @GetMapping
    public String courses() {
        return "/student/recommended";
    }


}

@@ -359,16 +359,59 @@
 efault;%0A
+import org.springframework.http.MediaType;%0A
 import o
@@ -448,24 +448,24 @@
 Controller;%0A
-
 import org.s
@@ -668,24 +668,144 @@
 thVariable;%0A
+import org.springframework.web.bind.annotation.PostMapping;%0Aimport org.springframework.web.bind.annotation.RequestBody;%0A
 import org.s
@@ -1592,16 +1592,73 @@
 rvice;%0A%0A
+    @Autowired%0A    private CourseService courseService;%0A%0A
     @Aut
@@ -1719,24 +1719,25 @@
 nService;%0A%0A%0A
+%0A
     @ModelAt
@@ -1951,61 +1951,39 @@
 t = 
-studentService.findByUsername(principal.getName()
+getLoggedInStudent(principal
 );%0A
-%0A
     
@@ -2149,11 +2149,564 @@
 %0A    %7D%0A%0A
+    @PostMapping(consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)%0A    public String dismissCourse(Principal principal, Long dismissedId) %7B%0A        log.info(%22Post with %5B%7B%7D%5D as request body%22, dismissedId);%0A        Student student = getLoggedInStudent(principal);%0A        courseService.dismissCourse(student, dismissedId);%0A        return %22redirect:/student/recommended%22;%0A    %7D%0A%0A%0A    private Student getLoggedInStudent(Principal principal) %7B%0A        Student student = studentService.findByUsername(principal.getName());%0A        return student;%0A    %7D%0A
 %0A%7D%0A

Add method to hadle post of dismissed course