Walle.Api/AI.Common/Services/PromptService.cs

49 lines
1.3 KiB
C#

using AI.Common.Dtos;
using AI.Common.Entities;
using AI.Common.Services.Interface;
using Mapster;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AI.Common.Services
{
public class PromptService : IPromptService
{
private readonly ISqlSugarClient _sqlSugarClient;
public PromptService(ISqlSugarClient sqlSugarClient)
{
this._sqlSugarClient = sqlSugarClient;
}
public async Task<List<PromptDto>> GetListAsync()
{
var entities = await _sqlSugarClient.Queryable<Prompts>().ToListAsync();
return entities.Adapt<List<PromptDto>>();
}
public async Task AddAsync(Prompts prompts)
{
await _sqlSugarClient.Insertable(prompts).ExecuteCommandAsync();
}
public async Task UpdateAsync(Prompts prompts)
{
await _sqlSugarClient.Updateable(prompts)
.UpdateColumns(x => new { x.Name, x.Prompt })
.ExecuteCommandHasChangeAsync();
}
public async Task DeleteAsync(long id)
{
await _sqlSugarClient.Updateable<Prompts>()
.SetColumns(x => x.IsDelete == true)
.Where(x => x.Id == id).ExecuteCommandAsync();
}
}
}