package com.kiisoo.ic.region.controller;

import com.kiisoo.ic.common.BaseController;
import com.kiisoo.ic.region.service.RegionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 区域
 */
@RestController
@RequestMapping("/region")
@Slf4j
public class RegionController extends BaseController{

    @Autowired
    private RegionService regionService;
    /**
     * 查看用户所属的区域及店铺信息
     */
    @ResponseBody
    @PostMapping("/user/region")
    public Map<String, Object> saveAccountInput(@RequestParam("userId")long userId) {
        return data(regionService.getRegionAndShop(userId));
    }

    /**
     * 查看用户所属的区域
     */
    @ResponseBody
    @PostMapping("/user/only/region")
    public Map<String, Object> getUserRegion(@RequestParam("userId")long userId) {
        try {
            return data(regionService.getUserRegion(userId));
        }catch (Exception e){
            log.error("查找用户区域",e);
            return fail();
        }
    }
}
