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 _botRepo; public BotConfigController(IMongoBaseRepository botRepo) { _botRepo = botRepo; } [HttpGet("GetAll")] public async Task>> GetAll() { var list = await _botRepo.FilterByAsync(_ => true); return this.ToResult(list.ToList()); } [HttpPost("Add")] public async Task> Add(BotProfileEntity entity) { if (string.IsNullOrWhiteSpace(entity.Name)) return this.ToFailResult("名称不能为空"); await _botRepo.InsertOneAsync(entity); return this.ToResult("添加成功"); } [HttpPost("Update")] public async Task> Update(BotProfileEntity entity) { if (string.IsNullOrWhiteSpace(entity.Id)) return this.ToFailResult("缺少Id"); if (string.IsNullOrWhiteSpace(entity.Name)) return this.ToFailResult("名称不能为空"); var update = Builders.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> Delete([FromQuery] string id) { if (string.IsNullOrWhiteSpace(id)) return this.ToFailResult("缺少Id"); await _botRepo.DeleteByIdAsync(id); return this.ToResult("删除成功"); } } }