You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.4 KiB

package com.example.classroomattendance.controller;
import com.example.classroomattendance.model.Student;
import com.example.classroomattendance.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@PostMapping("/pick")
public String pickRandomStudent(Model model) {
Student pickedStudent = studentService.pickRandomStudent();
model.addAttribute("pickedStudent", pickedStudent);
model.addAttribute("students", studentService.getAllStudents());
return "index";
}
@PostMapping("/updatePoints")
public String updateStudentPoints(@RequestParam Long studentId, @RequestParam double points, Model model) {
studentService.updateStudentPoints(studentId, points);
model.addAttribute("pickedStudent", studentService.pickRandomStudent());
model.addAttribute("students", studentService.getAllStudents());
return "index";
}
@GetMapping("/")
public String listStudents(Model model) {
model.addAttribute("students", studentService.getAllStudents());
return "index";
}
}