LANCommander/LANCommander.Server.Services/RedistributableService.cs

68 lines
2.5 KiB
C#
Raw Permalink Normal View History

2024-08-04 18:44:33 -05:00
using LANCommander.Server.Data;
using LANCommander.Server.Data.Models;
using LANCommander.Server.Services.Extensions;
using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.EntityFrameworkCore;
using ZiggyCreatures.Caching.Fusion;
2024-08-04 18:44:33 -05:00
namespace LANCommander.Server.Services
{
public sealed class RedistributableService(
ILogger<SDK.Services.RedistributableClient> logger,
SettingsProvider<Settings.Settings> settingsProvider,
IFusionCache cache,
IMapper mapper,
IHttpContextAccessor httpContextAccessor,
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<Redistributable>(logger, settingsProvider, cache, mapper, httpContextAccessor, contextFactory)
{
2025-02-23 08:49:43 -06:00
public override async Task<Redistributable> AddAsync(Redistributable entity)
{
await cache.ExpireGameCacheAsync();
return await base.AddAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(r => r.Archives);
await context.UpdateRelationshipAsync(r => r.Games);
await context.UpdateRelationshipAsync(r => r.Pages);
await context.UpdateRelationshipAsync(r => r.Scripts);
});
}
2025-02-02 14:58:07 -06:00
public override async Task<Redistributable> UpdateAsync(Redistributable entity)
{
if (entity.Games != null && entity.Games.Any())
{
foreach (var game in entity.Games)
{
await cache.ExpireGameCacheAsync(game?.Id);
}
}
2025-02-02 14:58:07 -06:00
return await base.UpdateAsync(entity, async context =>
{
await context.UpdateRelationshipAsync(r => r.Archives);
await context.UpdateRelationshipAsync(r => r.Games);
await context.UpdateRelationshipAsync(r => r.Pages);
await context.UpdateRelationshipAsync(r => r.Scripts);
});
}
2025-04-11 02:31:29 -05:00
public async Task<SDK.Models.Manifest.Redistributable> GetManifestAsync(Guid manifestId)
{
var redistributable = await AsNoTracking()
.AsSplitQuery()
.Query(q =>
{
return q
.Include(r => r.Archives)
.Include(r => r.Scripts);
})
2025-10-05 19:41:24 -05:00
.GetAsync(manifestId);
2025-04-11 02:31:29 -05:00
2025-10-05 19:41:24 -05:00
return mapper.Map<SDK.Models.Manifest.Redistributable>(redistributable);
2025-04-11 02:31:29 -05:00
}
}
}