8 changed files with 192 additions and 0 deletions
@ -0,0 +1,8 @@ |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
public class ConversationCreateDto |
|||
{ |
|||
[DynamicStringLength(typeof(ConversationRecordConsts), nameof(ConversationRecordConsts.MaxNameLength))] |
|||
public string? Name { get; set; } |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System; |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
public class ConversationDto : AuditedEntityDto<Guid> |
|||
{ |
|||
public string Name { get; set; } |
|||
|
|||
public DateTime CreatedAt { get; set; } |
|||
|
|||
public DateTime ExpiredAt { get; set; } |
|||
|
|||
public DateTime? UpdateAt { get; set; } |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
using Volo.Abp.Application.Dtos; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
public class ConversationGetListInput : PagedAndSortedResultRequestDto |
|||
{ |
|||
public string? Filter { get; set; } |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
using System.ComponentModel.DataAnnotations; |
|||
using Volo.Abp.Validation; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
public class ConversationUpdateDto |
|||
{ |
|||
[Required] |
|||
[DynamicStringLength(typeof(ConversationRecordConsts), nameof(ConversationRecordConsts.MaxNameLength))] |
|||
public string Name { get; set; } |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
using System; |
|||
using Volo.Abp.Application.Services; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats; |
|||
public interface IConversationAppService : |
|||
ICrudAppService< |
|||
ConversationDto, |
|||
Guid, |
|||
ConversationGetListInput, |
|||
ConversationCreateDto, |
|||
ConversationUpdateDto> |
|||
{ |
|||
} |
|||
@ -0,0 +1,82 @@ |
|||
using LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
using LINGYUN.Abp.AIManagement.Localization; |
|||
using Microsoft.Extensions.Options; |
|||
using System; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.Application.Services; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats; |
|||
public class ConversationAppService : |
|||
CrudAppService< |
|||
ConversationRecord, |
|||
ConversationDto, |
|||
Guid, |
|||
ConversationGetListInput, |
|||
ConversationCreateDto, |
|||
ConversationUpdateDto>, |
|||
IConversationAppService |
|||
{ |
|||
private readonly ConversationCleanupOptions _cleanupOptions; |
|||
public ConversationAppService( |
|||
IRepository<ConversationRecord, Guid> repository, |
|||
IOptions<ConversationCleanupOptions> cleanupOptions) |
|||
: base(repository) |
|||
{ |
|||
_cleanupOptions = cleanupOptions.Value; |
|||
|
|||
LocalizationResource = typeof(AIManagementResource); |
|||
ObjectMapperContext = typeof(AbpAIManagementApplicationModule); |
|||
} |
|||
|
|||
protected async override Task<IQueryable<ConversationRecord>> CreateFilteredQueryAsync(ConversationGetListInput input) |
|||
{ |
|||
var queryable = await base.CreateFilteredQueryAsync(input); |
|||
|
|||
return queryable |
|||
.WhereIf(!input.Filter.IsNullOrWhiteSpace(), x => x.Name.Contains(input.Filter!)); |
|||
} |
|||
|
|||
protected override ConversationRecord MapToEntity(ConversationCreateDto createInput) |
|||
{ |
|||
var createdAt = Clock.Now; |
|||
var expiredTime = createdAt.Add(_cleanupOptions.ExpiredTime); |
|||
var conversationName = createInput.Name ?? L["NewConversation"]; |
|||
return new ConversationRecord( |
|||
GuidGenerator.Create(), |
|||
conversationName, |
|||
createdAt, |
|||
expiredTime, |
|||
CurrentTenant.Id); |
|||
} |
|||
|
|||
protected override void MapToEntity(ConversationUpdateDto updateInput, ConversationRecord entity) |
|||
{ |
|||
if (!string.Equals(entity.Name, updateInput.Name, StringComparison.InvariantCultureIgnoreCase)) |
|||
{ |
|||
entity.SetName(updateInput.Name); |
|||
} |
|||
} |
|||
|
|||
protected override ConversationDto MapToGetOutputDto(ConversationRecord entity) |
|||
{ |
|||
return new ConversationDto |
|||
{ |
|||
Id = entity.Id, |
|||
CreatedAt = entity.CreatedAt, |
|||
ExpiredAt = entity.ExpiredAt, |
|||
CreationTime = entity.CreationTime, |
|||
CreatorId = entity.CreatorId, |
|||
LastModificationTime = entity.LastModificationTime, |
|||
LastModifierId = entity.LastModifierId, |
|||
Name = entity.Name, |
|||
UpdateAt = entity.UpdateAt, |
|||
}; |
|||
} |
|||
|
|||
protected override ConversationDto MapToGetListOutputDto(ConversationRecord entity) |
|||
{ |
|||
return MapToGetOutputDto(entity); |
|||
} |
|||
} |
|||
@ -0,0 +1,52 @@ |
|||
using LINGYUN.Abp.AIManagement.Chats.Dtos; |
|||
using Microsoft.AspNetCore.Mvc; |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Application.Dtos; |
|||
using Volo.Abp.AspNetCore.Mvc; |
|||
|
|||
namespace LINGYUN.Abp.AIManagement.Chats; |
|||
|
|||
[Controller] |
|||
[RemoteService(Name = AIManagementRemoteServiceConsts.RemoteServiceName)] |
|||
[Area(AIManagementRemoteServiceConsts.ModuleName)] |
|||
[Route($"api/{AIManagementRemoteServiceConsts.ModuleName}/chats/conversations")] |
|||
public class ConversationController : AbpControllerBase, IConversationAppService |
|||
{ |
|||
private readonly IConversationAppService _service; |
|||
public ConversationController(IConversationAppService service) |
|||
{ |
|||
_service = service; |
|||
} |
|||
|
|||
[HttpPost] |
|||
public virtual Task<ConversationDto> CreateAsync(ConversationCreateDto input) |
|||
{ |
|||
return _service.CreateAsync(input); |
|||
} |
|||
|
|||
[HttpDelete("{id}")] |
|||
public virtual Task DeleteAsync(Guid id) |
|||
{ |
|||
return _service.DeleteAsync(id); |
|||
} |
|||
|
|||
[HttpGet("{id}")] |
|||
public virtual Task<ConversationDto> GetAsync(Guid id) |
|||
{ |
|||
return _service.GetAsync(id); |
|||
} |
|||
|
|||
[HttpGet] |
|||
public virtual Task<PagedResultDto<ConversationDto>> GetListAsync(ConversationGetListInput input) |
|||
{ |
|||
return _service.GetListAsync(input); |
|||
} |
|||
|
|||
[HttpPut("{id}")] |
|||
public virtual Task<ConversationDto> UpdateAsync(Guid id, ConversationUpdateDto input) |
|||
{ |
|||
return _service.UpdateAsync(id, input); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue