package stuTest.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import stuTest.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import stuTest.pojo.Student;
import stuTest.service.StudentService;

@RestController
@RequestMapping("/StudentAction")
@CrossOrigin(maxAge = 3600)
public class StudentController {
    @Autowired
    StudentService studentService;


    @RequestMapping("/get")
    @CrossOrigin(maxAge = 3600)
    public Result getStudent(String name) {
        if (name == null) {
            return Result.fail(null);
        }
        return studentService.selectStudent(name);
    }

    @RequestMapping("/add")
    @CrossOrigin(maxAge = 3600)
    public Result addStudent(Student student) {
        if (student == null) {
            return Result.fail(null);
        }
        return studentService.insertStudent(student);
    }

    @RequestMapping("/del")
    @CrossOrigin(maxAge = 3600)
    public Result deleteStudent(int id) {
        return studentService.deleteStudent(id);
    }

    @RequestMapping("/upd")
    @CrossOrigin(maxAge = 3600)
    public Result updateStudent(Student student) {
        if (student == null) {
            return Result.fail(null);
        }
        return studentService.updateStudent(student);
    }
}
