This commit is contained in:
mmrbnjd
2025-08-18 00:28:32 +03:30
parent bd1f907673
commit a10fbeab62
11 changed files with 711 additions and 4 deletions

View File

@@ -69,6 +69,7 @@ namespace Hushian.Application
services.AddScoped(typeof(PromptService));
services.AddScoped(typeof(UserService));
services.AddScoped(typeof(VerificationService));
services.AddScoped(typeof(AIService));
services.Configure<JwtSettings>(configuration.GetSection("JwtSettings"));
}
}

View File

@@ -0,0 +1,72 @@
using AutoMapper;
using Common.Dtos;
using Hushian.Application.Contracts.Persistence;
using Hushian.Application.Models;
using Hushian.Domain.Entites;
using Microsoft.EntityFrameworkCore;
using System.Linq;
namespace Hushian.Application.Services
{
public class AIService
{
private readonly IGenericRepository<AIA> _aiaRepository;
private readonly IMapper _mapper;
public AIService(IGenericRepository<AIA> aiaRepository, IMapper mapper)
{
_aiaRepository = aiaRepository;
_mapper = mapper;
}
public async Task<ResponseBase<aiResponseDto>> NewRequest
(aiNewResponseDto dto)
{
ResponseBase<aiResponseDto> response = new();
try
{
string responeai="همین جوری";
bool sucessresponseai = false;
var entity = new AIA
{
CompanyID = dto.companyId,
UserID = dto.userId,
Request = dto.requestText,
Response = responeai,
Cdatetime = DateTime.Now
};
var added = await _aiaRepository.ADD(entity);
if(sucessresponseai)
response.Value = new() { dateTime=added.Cdatetime,responseText=added.Response,requestText=added.Request};
response.Success = sucessresponseai;
}
catch (Exception)
{
response.Errors.Add("خطا در ذخیره سازی");
}
return response;
}
public async Task<List<aiResponseDto>> GetCurrent(int companyId, int userId)
{
return await _aiaRepository
.Get()
.Where(w => w.CompanyID == companyId && w.UserID == userId && w.Cdatetime.AddHours(3) >= DateTime.Now)
.OrderBy(o => o.ID)
.Select(s=>new aiResponseDto() { responseText = s.Response, requestText = s.Request,dateTime=s.Cdatetime})
.ToListAsync();
}
//public async Task<bool> DeleteEntry(int id, int companyId)
//{
// var entity = await _aiaRepository.Get().FirstOrDefaultAsync(f => f.ID == id && f.CompanyID == companyId);
// if (entity == null) return false;
// return await _aiaRepository.DELETE(entity);
//}
}
}