package com.enterprise.manage.modules.asset.controller;

import com.enterprise.manage.common.base.BaseController;
import com.enterprise.manage.common.web.request.PageDomain;
import com.enterprise.manage.common.web.response.Result;
import com.enterprise.manage.common.web.response.module.ResultTable;
import com.enterprise.manage.modules.asset.domain.House;
import com.enterprise.manage.modules.asset.service.IHouseService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 房产信息 Controller
 *
 * @author QingLi Wang
 * @version 1.0.0
 * 2023-11-28 09:38
 */
@RestController
@RequestMapping("/asset/house/v1")
public class HouseController extends BaseController {

    private IHouseService houseService;

    @Autowired
    public HouseController(IHouseService houseService) {
        this.houseService = houseService;
    }

    @GetMapping
    @PreAuthorize("hasPermission('','house:house:list')")
    public ResultTable list(PageDomain pageDomain, House param) {
        PageInfo<House> housePage = houseService.page(pageDomain, param);
        return pageTable(housePage.getList(), housePage.getTotal());
    }

    @GetMapping("{id}")
    @PreAuthorize("hasPermission('','house:house:list')")
    public Result get(@PathVariable Long id) {
        return success(houseService.queryById(id));
    }

    @PostMapping
    @PreAuthorize("hasPermission('','house:house:add')")
    public Result add(House house) {
        return decide(houseService.save(house));
    }

    @PutMapping
    @PreAuthorize("hasPermission('','house:house:edit')")
    public Result edit(House house) {
        return decide(houseService.update(house));
    }

    @DeleteMapping("{id}")
    @PreAuthorize("hasPermission('','house:house:del')")
    public Result remove(@PathVariable Integer id) {
        return decide(houseService.removeById(id));
    }

}
