using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using GxPress.Entity;
using GxPress.Repository.Interface;
using GxPress.Result.Department;
using GxPress.Service.Interface.Department;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace GxPress.Api.AdminControllers
{
///
/// 部门
///
[Route("api/admin/department")]
[ApiController]
[Authorize]
public class AdminDepartmentController : ControllerBase
{
private readonly IDepartmentRepository _departmentRepository;
private readonly IDepartmentService _departmentService;
public AdminDepartmentController(IDepartmentRepository departmentRepository,IDepartmentService departmentService)
{
_departmentRepository = departmentRepository;
_departmentService = departmentService;
}
///
/// 添加
///
///
///
[HttpPost]
public async Task Add([FromBody]Department request)
{
return await _departmentRepository.AddAsync(request);
}
///
/// 详情
///
///
///
[HttpGet("{id}")]
public async Task GetDetail(int id)
{
return await _departmentRepository.GetAsync(id);
}
///
/// 删除
///
///
///
[HttpDelete("{id}")]
public async Task Delete(int id)
{
return await _departmentService.DeleteAsync(id);
}
///
/// 修改
///
///
///
///
[HttpPut("{id}")]
public async Task Update(int id, [FromBody] Department request)
{
return await _departmentRepository.UpdateAsync(id, request);
}
///
/// 树形结构展示,懒加载
///
///
///
[HttpGet("tree")]
public async Task> GetTree(int id = 0)
{
return await _departmentRepository.GetTreeAsync(id);
}
}
}