package com.cool.bang.modules.api.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.JobCustomer;
import com.cool.bang.modules.business.domain.LpbHouse;
import com.cool.bang.modules.business.service.IJobCustomerService;
import com.cool.bang.modules.business.service.ILpbHouseService;
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.*;

import java.util.List;

/**
 * 房屋信息
 *
 * @author Sy
 * @version 1.0.0
 * 2024-10-22 09:20
 */
@RestController
@RequestMapping(ControllerConstant.WX + "house/v1")
public class HouseController extends BaseController {
    @Autowired
    private ILpbHouseService lpbHouseService;

    @Autowired
    private IJobCustomerService jobCustomerService;

    @GetMapping
    public ResultTable main(PageDomain pageDomain, LpbHouse param) {
        param.setDelFlag(1);
        param.setState(1);
        PageInfo<LpbHouse> lpbHousePage = lpbHouseService.housePage(pageDomain, param);
        return pageTable(lpbHousePage.getList(), lpbHousePage.getTotal());
    }

    @GetMapping("{id}")
    public Result get(@PathVariable Long id) {
        return success(lpbHouseService.queryById(id));
    }

    @GetMapping("like")
    public Result addLike(String openId,Long houseId,Long communityId) {
        JobCustomer wxUser = jobCustomerService.queryByOpenid(openId);
        return decide(lpbHouseService.updateLike(wxUser.getId(),communityId,houseId));
    }

    @PostMapping("edit")
    public Result edit(@RequestBody LpbHouse lpbHouse) {
        return decide(lpbHouseService.update(lpbHouse));
    }


}
