56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using Learn.Archives.API.Controllers.Dto;
|
|
using Learn.Archives.API.Expand;
|
|
using Learn.Archives.Core.Common;
|
|
using Learn.Archives.Core.Model;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Diagnostics;
|
|
using System.Security.Claims;
|
|
using UserCenter.Model;
|
|
|
|
namespace Learn.Archives.API.Controllers
|
|
{
|
|
[ApiExplorerSettings(GroupName = "公共接口")]
|
|
[Route("api/address")]
|
|
public class AddressController : Controller
|
|
{
|
|
private readonly Repository<Province> _provinceService;
|
|
private readonly Repository<City> _cityService;
|
|
private readonly Repository<Region> _regionService;
|
|
|
|
public AddressController(Repository<Province> provinceService, Repository<Region> regionService, Repository<City> cityService)
|
|
{
|
|
_provinceService = provinceService;
|
|
_regionService = regionService;
|
|
_cityService = cityService;
|
|
}
|
|
/// <summary>
|
|
/// 获取所有省份
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("province"), AllowAnonymous]
|
|
public async Task<IList<Province>> GetProvince()
|
|
{
|
|
return await _provinceService.GetListAsync();
|
|
}
|
|
/// <summary>
|
|
/// 获取省份下的市区
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("{pid}/city"), AllowAnonymous]
|
|
public async Task<IList<City>> GetProvince(int pid)
|
|
{
|
|
return await _cityService.GetListAsync(s => s.Pid == pid);
|
|
}
|
|
/// <summary>
|
|
/// 获取市区下的区县
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("{cid}/region"), AllowAnonymous]
|
|
public async Task<IList<Region>> GetRegion(int cid)
|
|
{
|
|
return await _regionService.GetListAsync(s => s.Cid == cid);
|
|
}
|
|
}
|
|
}
|