using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AutoMapper;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
namespace Win_in.Sfs.Scp.WebApi
{
///
/// 零件服务
///
[AllowAnonymous]
[Route("api/scp/part")]
[ApiExplorerSettings(GroupName = SwaggerGroupConsts.ScpWebApi)]
public class PartAppService :ReadOnlyAppService, IPartAppService
{
private readonly IPartRepository _partRepository;
public PartAppService(IPartRepository repository) : base(repository)
{
_partRepository = repository;
}
///
/// 按ID获取零件 (Get part by ID)
///
/// 唯一ID(unique ID)
///
[HttpGet]
[Route("{id}")]
public override async Task GetAsync(Guid id)
{
return await base.GetAsync(id);
}
///
/// 按条件获取零件列表 (Get part list by request condition)
///
/// 请求条件DTO(Request condition DTO)
///
[HttpGet]
[Route("")]
public override async Task> GetListAsync(RequestDTO requestDTO)
{
return await base.GetListAsync(requestDTO);
}
///
/// 新增零件(Create New part)
///
///
[HttpPost]
[Route("")]
public async Task CreateAsync(PartCreateDto partCreateDTO)
{
var entity = ObjectMapper.Map(partCreateDTO);
entity.SetId(GuidGenerator.Create());
var ret= await _partRepository.InsertAsync(entity);
var dto = ObjectMapper.Map(ret);
return dto;
}
}
}