提交 94ef69a0 编写于 作者: lwplvx's avatar lwplvx

增加翻译接口相关

上级 c8552e19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aurora.Core.IService;
using Aurora.Core.IService.Dto;
using Aurora.Infrastructure.Response;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace Aurora.Core.Api.Controllers
{
[ApiController]
[Route("[controller]/[action]")]
public class TranslateController : ControllerBase
{
private readonly ILogger<TranslateController> _logger;
private readonly IRocketService _rocketService;
public TranslateController(ILogger<TranslateController> logger,
IRocketService rocketService)
{
_logger = logger;
_rocketService = rocketService;
}
[HttpGet]
/// <summary>
/// get words list
/// </summary>
/// <returns></returns>
public async Task<IActionResult> GetList()
{
var res = await _rocketService.GetList();
return Ok(res);
}
[HttpPost]
/// <summary>
/// biu word
/// </summary>
/// <returns></returns>
public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model)
{
var res = await _rocketService.Add(model);
return res;
}
}
}
using System;
using System.Collections.Generic;
namespace Aurora.Core.Domain.Entities
{
/// <summary>
/// 单词,我就用 Rocket 老表示单词
/// </summary>
public class Rocket : TenantEntityBase
{
public int CategoryId { get; set; }
public string Name { get; set; }
// 其他字段…… ,翻译接口调用通了再补充
public string Remark { get; set; }
}
}
using System;
namespace Aurora.Core.IService.Dto
{
public class RocketDto : BaseDto
{
public string Name { get; set; }
public string Remark { get; set; }
public int CatetoryId { get; set; }
}
}
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Aurora.Core.IService.Dto;
using Aurora.Infrastructure.Response;
namespace Aurora.Core.IService
{
public interface IRocketService
{
Task<ResponseModel<List<RocketDto>>> GetList();
Task<ResponseModel<RocketDto>> Rocket(RocketDto model);
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Aurora.Core.Domain.Entities;
using Aurora.Core.EntityFramework;
using Aurora.Core.IService;
using Aurora.Core.IService.Dto;
using Aurora.Infrastructure.Response;
using AutoMapper;
using Microsoft.EntityFrameworkCore;
namespace Aurora.Core.Service
{
public class RocketService : IRocketService
{
private readonly ApplicationDbContext _dbContext;
private readonly ApplicationReadonlyDbContext _readonlyDbContext;
private readonly IMapper _mapper;
public RocketService(ApplicationDbContext dbContext,
ApplicationReadonlyDbContext readonlyDbContext,
IMapper mapper)
{
_mapper = mapper ?? throw new ArgumentNullException(nameof(mapper));
_dbContext = dbContext;
_readonlyDbContext = readonlyDbContext;
}
public async Task<ResponseModel<List<RocketDto>>> GetList()
{
var list = await _readonlyDbContext.Categories.ToListAsync();
var dtoList = _mapper.Map<List<RocketDto>>(list);
var res = new ResponseModel<List<RocketDto>>(dtoList);
return res;
}
public async Task<ResponseModel<RocketDto>> GetById(int id)
{
var entity = await _readonlyDbContext.Categories.FirstOrDefaultAsync(m => m.ID == id);
var dto = _mapper.Map<RocketDto>(entity);
var res = new ResponseModel<RocketDto>(dto);
return res;
}
public async Task<ResponseModel<RocketDto>> Rocket(RocketDto model)
{
var entity = _mapper.Map<RocketWord>(model);
_dbContext.Categories.Add(entity);
var num = await _dbContext.SaveChangesAsync();
var dto = _mapper.Map<RocketDto>(entity);
var res = new ResponseModel<RocketDto>(dto);
return res;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册