package org.springblade.modules.app.web;

import com.wn.common.controller.BaseController;
import com.wn.common.datamodel.ResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.app.dto.CityDTO;
import org.springblade.common.auth.permission.DisableLoginVerify;
import org.springblade.modules.app.service.ICityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("app/region")
public class AppRegionController extends BaseController {

    @Autowired
    private ICityService cityService;

    /**
     * 根据id获取特定区域
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<CityDTO>> getCity(@PathVariable("id") Long id){
        CityDTO cityDTO = new CityDTO();
        cityDTO.setId(id);
        log.error("id is {}", id);
        return success(cityService.getCityDTO(cityDTO));
    }

    /**
     * 根据id获取特定区域
     * @param cityDTO
     * @return
     */
    @GetMapping("/match")
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<CityDTO>> matchCity(CityDTO cityDTO){
        return success(cityService.matchCity(cityDTO));
    }

    /**
     * 根据查询条件获取列表
     * @param cityDTO
     * @return
     */
    @GetMapping
    @DisableLoginVerify
    public ResponseEntity<ResultDTO<List<CityDTO>>> listCity(CityDTO cityDTO){
        return success(cityService.listCityDTO(cityDTO));
    }

}

