package com.dbnt.faisp.main.codeMgt;

import com.dbnt.faisp.main.codeMgt.model.CodeCatg;
import com.dbnt.faisp.main.codeMgt.service.CodeMgtService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/codeMgt")
public class CodeMgtController {

  private final CodeMgtService codeMgtService;

  @GetMapping("/codeMgtPage")
  public ModelAndView codeMgtPage() {
    ModelAndView mav = new ModelAndView("adminPage/codeMgt/codeMgt");
    return mav;
  }

  @PostMapping("/saveCode")
  @ResponseBody
  public String saveCode(@RequestBody List<CodeCatg> codeCategoryList){
    codeMgtService.saveCode(codeCategoryList);
    return "";
  }

  @GetMapping("/selectCodeCatgList")
  public List<CodeCatg> selectCodeCatgList(){
    return codeMgtService.selectCodeCatgAndChild();
  }
}
