Update DCR Api

main
ilitirit 3 years ago
parent e6a90d31b7
commit b1bfa3dca5

@ -56,9 +56,9 @@ namespace Expedience.Api.Controllers
try try
{ {
using var scope = _serviceScopeFactory.CreateScope(); using var scope = _serviceScopeFactory.CreateScope();
using var repository = scope.ServiceProvider.GetService<IRepository>(); using var repository = scope.ServiceProvider.GetService<IExpedienceRepository>();
var results = repository.GetDutyCompletionRecords(expac, CancellationToken.None); var results = await repository.GetDutyCompletionRecords(expac, cancellationToken);
return Ok(results); return Ok(results);
} }
catch (Exception ex) catch (Exception ex)
@ -66,7 +66,7 @@ namespace Expedience.Api.Controllers
_logger.LogError(ex, "Error getting Duty Completion Records for {expac}: {errorMessage}", expac, ex.Message); _logger.LogError(ex, "Error getting Duty Completion Records for {expac}: {errorMessage}", expac, ex.Message);
} }
return Ok(); return StatusCode(500);
} }
[HttpGet("UserName/{worldId}/{userHash}")] [HttpGet("UserName/{worldId}/{userHash}")]

@ -35,7 +35,7 @@ builder.Services.AddMassTransit(opt =>
}); });
builder.Services.AddEnyimMemcached(); builder.Services.AddEnyimMemcached();
builder.Services.AddScoped<IRepository, ExpedienceRepository>(); builder.Services.AddScoped<IExpedienceRepository, ExpedienceRepository>();
builder.Services.AddSingleton<IDistributedLock, DistributedLock>(); builder.Services.AddSingleton<IDistributedLock, DistributedLock>();
builder.Services.AddSingleton<IDecryptor, Decryptor>(); builder.Services.AddSingleton<IDecryptor, Decryptor>();

@ -1,17 +1,17 @@
using System; using System;
using System.Collections.Generic;
using Enyim.Caching; using Enyim.Caching;
using Expedience.Infrastructure.Models; using Expedience.Infrastructure.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Expedience.Infrastructure namespace Expedience.Infrastructure
{ {
public interface IRepository : IDisposable public interface IExpedienceRepository : IDisposable
{ {
Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken); Task<List<DutyCompletionRecord>> GetDutyCompletionRecords(string expac, CancellationToken cancellationToken);
} }
public class ExpedienceRepository : IRepository public class ExpedienceRepository : IExpedienceRepository
{ {
private readonly ExpedienceContext _dbContext; private readonly ExpedienceContext _dbContext;
private readonly IMemcachedClient _memcachedClient; private readonly IMemcachedClient _memcachedClient;
@ -31,18 +31,17 @@ namespace Expedience.Infrastructure
} }
else else
{ {
var records = await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"CALL get_dutycompletionrecords {expac}") var records = await _dbContext.DutyCompletionRecords.FromSqlInterpolated($"SELECT * FROM public.get_dutycompletionrecords({expac})")
.ToListAsync(); .ToListAsync();
await _memcachedClient.AddAsync(cacheKey, records, TimeSpan.FromMinutes(10)); await _memcachedClient.AddAsync(cacheKey, records, TimeSpan.FromMinutes(10));
return records; return records;
} }
} }
public void Dispose() public void Dispose()
{ {
_dbContext.Dispose(); _memcachedClient.Dispose();
} }
} }
} }

@ -11,8 +11,15 @@ namespace Expedience.Infrastructure.Models
public int TerritoryId { get; set; } public int TerritoryId { get; set; }
public string ContentName { get; set; } public string ContentName { get; set; }
public string ContentType { get; set; } public string ContentType { get; set; }
public string Expac { get; set; }
public int Level { get; set; } public int Level { get; set; }
public TimeSpan? MinTime { get; set; } public int ContentSortKey { get; set; }
public TimeSpan? AverageTime { get; set; } public int ExpacSortKey { get; set; }
public TimeSpan? MinNormal { get; set; }
public TimeSpan? AvgNormal { get; set; }
public TimeSpan? MinSolo { get; set; }
public TimeSpan? AvgSolo { get; set; }
public TimeSpan? MinMine { get; set; }
public TimeSpan? AvgMine { get; set; }
} }
} }

Loading…
Cancel
Save