2024-08-04 18:44:33 -05:00
|
|
|
|
using LANCommander.Server.Data;
|
|
|
|
|
|
using LANCommander.Server.Data.Models;
|
2024-10-07 18:04:26 -05:00
|
|
|
|
using LANCommander.Server.Services.Extensions;
|
2025-02-01 02:21:34 -06:00
|
|
|
|
using AutoMapper;
|
2025-02-09 18:53:40 -06:00
|
|
|
|
using Microsoft.AspNetCore.Http;
|
2024-10-07 18:04:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-10-11 01:09:12 -05:00
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-10-30 17:44:10 -05:00
|
|
|
|
using ZiggyCreatures.Caching.Fusion;
|
2023-10-18 01:14:31 -05:00
|
|
|
|
|
2024-08-04 18:44:33 -05:00
|
|
|
|
namespace LANCommander.Server.Services
|
2023-10-18 01:14:31 -05:00
|
|
|
|
{
|
2025-02-01 02:21:34 -06:00
|
|
|
|
public sealed class RedistributableService(
|
2025-09-24 20:58:23 -05:00
|
|
|
|
ILogger<SDK.Services.RedistributableClient> logger,
|
2025-11-16 12:31:25 -06:00
|
|
|
|
SettingsProvider<Settings.Settings> settingsProvider,
|
2025-02-01 02:21:34 -06:00
|
|
|
|
IFusionCache cache,
|
|
|
|
|
|
IMapper mapper,
|
2025-02-09 18:53:40 -06:00
|
|
|
|
IHttpContextAccessor httpContextAccessor,
|
2025-11-16 12:31:25 -06:00
|
|
|
|
IDbContextFactory<DatabaseContext> contextFactory) : BaseDatabaseService<Redistributable>(logger, settingsProvider, cache, mapper, httpContextAccessor, contextFactory)
|
2023-10-18 01:14:31 -05:00
|
|
|
|
{
|
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)
|
2024-10-11 01:09:12 -05:00
|
|
|
|
{
|
2025-02-04 02:31:23 -06:00
|
|
|
|
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);
|
|
|
|
|
|
});
|
2024-10-11 01:09:12 -05:00
|
|
|
|
}
|
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
|
|
|
|
}
|
2023-10-18 01:14:31 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|