package rd.controller.major;

import rd.data.db.table.Major;
import rd.data.model.response.Response;
import rd.service.major.MajorService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

@RestController
@RequestMapping("/major")
public class PublicMajor {

    private final MajorService majorService;

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

    @GetMapping("/info")
    public Response<Major> get(@RequestParam("id") Long id) {
        Major major = majorService.getMajor(id);
        return Response.success(major);
    }

    @GetMapping("/list")
    public Response<Set<Major>> list() {
        var majorList = majorService.listAllMajor();
        return Response.success(majorList);
    }
}
