64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
using Common;
|
|||
|
|
using CommonDomain;
|
||
|
|
using CommonInfrastructure;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using MongoDB.Driver;
|
||
|
|
using MongoRepository;
|
||
|
|
|
||
|
|
namespace AdminApi.GameConfigs
|
||
|
|
{
|
||
|
|
[ApiController, Route("adminapi/[controller]")]
|
||
|
|
public class BotConfigController : BaseController
|
||
|
|
{
|
||
|
|
private readonly IMongoBaseRepository<BotProfileEntity> _botRepo;
|
||
|
|
|
||
|
|
public BotConfigController(IMongoBaseRepository<BotProfileEntity> botRepo)
|
||
|
|
{
|
||
|
|
_botRepo = botRepo;
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpGet("GetAll")]
|
||
|
|
public async Task<BaseResponse<List<BotProfileEntity>>> GetAll()
|
||
|
|
{
|
||
|
|
var list = await _botRepo.FilterByAsync(_ => true);
|
||
|
|
return this.ToResult(list.ToList());
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("Add")]
|
||
|
|
public async Task<BaseResponse<string>> Add(BotProfileEntity entity)
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(entity.Name))
|
||
|
|
return this.ToFailResult<string>("名称不能为空");
|
||
|
|
|
||
|
|
await _botRepo.InsertOneAsync(entity);
|
||
|
|
return this.ToResult("添加成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("Update")]
|
||
|
|
public async Task<BaseResponse<string>> Update(BotProfileEntity entity)
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(entity.Id))
|
||
|
|
return this.ToFailResult<string>("缺少Id");
|
||
|
|
|
||
|
|
if (string.IsNullOrWhiteSpace(entity.Name))
|
||
|
|
return this.ToFailResult<string>("名称不能为空");
|
||
|
|
|
||
|
|
var update = Builders<BotProfileEntity>.Update
|
||
|
|
.Set(x => x.Name, entity.Name)
|
||
|
|
.Set(x => x.Avatar, entity.Avatar ?? string.Empty);
|
||
|
|
await _botRepo.UpdateByIdAsync(entity.Id, update);
|
||
|
|
return this.ToResult("更新成功");
|
||
|
|
}
|
||
|
|
|
||
|
|
[HttpPost("Delete")]
|
||
|
|
public async Task<BaseResponse<string>> Delete([FromQuery] string id)
|
||
|
|
{
|
||
|
|
if (string.IsNullOrWhiteSpace(id))
|
||
|
|
return this.ToFailResult<string>("缺少Id");
|
||
|
|
|
||
|
|
await _botRepo.DeleteByIdAsync(id);
|
||
|
|
return this.ToResult("删除成功");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|