package com.cool.bang.modules.business.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.business.domain.JobHomePath;
import com.cool.bang.modules.business.service.IJobHomePathService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 首页信息
 *
 * @author Sy
 * @version 1.0.0
 * 2024-11-11 13:42
 */
@RestController
@RequestMapping(ControllerConstant.BUSINESS + "homePath/v1")
public class JobHomePathController extends BaseController {

    private IJobHomePathService jobHomePathService;

    @Autowired
    public JobHomePathController(IJobHomePathService jobHomePathService) {
        this.jobHomePathService = jobHomePathService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','business:homePath:main')")
    public ResultTable main(PageDomain pageDomain, JobHomePath param) {
        PageInfo<JobHomePath> jobHomePathPage = jobHomePathService.page(pageDomain, param);
        return pageTable(jobHomePathPage.getList(), jobHomePathPage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','business:homePath:main')")
    public Result get(@PathVariable Long id) {
        return success(jobHomePathService.queryById(id));
    }

    @PostMapping
    @PreAuthorize("hasPermission('','business:homePath:add')")
    public Result add(@Validated JobHomePath jobHomePath) {
        jobHomePath.insertConfigure();
        return decide(jobHomePathService.save(jobHomePath));
    }

    @PostMapping("edit")
    @PreAuthorize("hasPermission('','business:homePath:edit')")
    public Result edit(@Validated JobHomePath jobHomePath) {
        return decide(jobHomePathService.update(jobHomePath));
    }

    @GetMapping("remove/{id}")
    @PreAuthorize("hasPermission('','business:homePath:del')")
    public Result remove(@PathVariable Integer id) {
        return decide(jobHomePathService.removeById(id));
    }

}
