package rd.controller.major;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckRole;
import rd.data.db.table.Major;
import rd.data.model.response.Response;
import rd.service.major.MajorService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/major")
public class AdminMajorController {

    private final MajorService majorService;

    public AdminMajorController(MajorService majorService) {
        this.majorService = majorService;
    }

    @SaCheckLogin
    @SaCheckRole("ADMIN")
    @PostMapping("/add")
    public Response<Major> add(@RequestParam("name") String name) {
        Major major = majorService.addMajorIfNotExists(name);
        return Response.success(major);
    }

    @SaCheckLogin
    @SaCheckRole("ADMIN")
    @PostMapping("/delete")
    public Response<Object> delete(@RequestParam("id") Long id) {
        majorService.deleteMajor(id);
        return Response.success();
    }
}
