Got most of admin panel working. Data issues fixed
This commit is contained in:
@@ -5,11 +5,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArchiveCategoryProvider : IArchiveCategoryProvider
|
||||
{
|
||||
private Microsoft.EntityFrameworkCore.IDbContextFactory<ArchiveDbContext> _dbFactory;
|
||||
private Microsoft.EntityFrameworkCore.IDbContextFactory<ApplicationDbContext> _dbFactory;
|
||||
private ILogger _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArchiveCategoryProvider(Microsoft.EntityFrameworkCore.IDbContextFactory<ArchiveDbContext> dbFactory, ILogger<ArchiveCategoryProvider> logger)
|
||||
public ArchiveCategoryProvider(Microsoft.EntityFrameworkCore.IDbContextFactory<ApplicationDbContext> dbFactory, ILogger<ArchiveCategoryProvider> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_logger = logger;
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArchiveEntryTagProvider : IArchiveEntryTagProvider
|
||||
{
|
||||
private readonly IDbContextFactory<ArchiveDbContext> _dbFactory;
|
||||
private readonly IDbContextFactory<ApplicationDbContext> _dbFactory;
|
||||
private readonly ILogger<ArchiveEntryTagProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArchiveEntryTagProvider(IDbContextFactory<ArchiveDbContext> context, ILogger<ArchiveEntryTagProvider> logger)
|
||||
public ArchiveEntryTagProvider(IDbContextFactory<ApplicationDbContext> context, ILogger<ArchiveEntryTagProvider> logger)
|
||||
{
|
||||
_dbFactory = context;
|
||||
_logger = logger;
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArtifactDefectProvider : IArtifactDefectProvider
|
||||
{
|
||||
private readonly IDbContextFactory<ArchiveDbContext> _dbFactory;
|
||||
private readonly IDbContextFactory<ApplicationDbContext> _dbFactory;
|
||||
private readonly ILogger<ArtifactDefectProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArtifactDefectProvider(IDbContextFactory<ArchiveDbContext> context, ILogger<ArtifactDefectProvider> logger)
|
||||
public ArtifactDefectProvider(IDbContextFactory<ApplicationDbContext> context, ILogger<ArtifactDefectProvider> logger)
|
||||
{
|
||||
_dbFactory = context;
|
||||
_logger = logger;
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArtifactGroupingProvider : IArtifactGroupingProvider
|
||||
{
|
||||
private readonly ArchiveDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly ILogger<ArtifactGroupingProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArtifactGroupingProvider(ArchiveDbContext context, ILogger<ArtifactGroupingProvider> logger)
|
||||
public ArtifactGroupingProvider(ApplicationDbContext context, ILogger<ArtifactGroupingProvider> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
@@ -18,12 +18,18 @@ public class ArtifactGroupingProvider : IArtifactGroupingProvider
|
||||
|
||||
public async Task<ArtifactGrouping?> GetGroupingAsync(int id)
|
||||
{
|
||||
return await _context.ArtifactGroupings.Where(g => g.Id == id).FirstOrDefaultAsync();
|
||||
return await _context.ArtifactGroupings
|
||||
.Where(g => g.Id == id)
|
||||
.Include(g => g.Category)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<ArtifactGrouping?> GetGroupingAsync(string artifactGroupingIdentifier)
|
||||
{
|
||||
return await _context.ArtifactGroupings.Where(g => g.ArtifactGroupingIdentifier == artifactGroupingIdentifier).FirstOrDefaultAsync();
|
||||
return await _context.ArtifactGroupings
|
||||
.Where(g => g.ArtifactGroupingIdentifier == artifactGroupingIdentifier)
|
||||
.Include(g => g.Category)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task CreateGroupingAsync(ArtifactGrouping grouping)
|
||||
@@ -38,9 +44,37 @@ public class ArtifactGroupingProvider : IArtifactGroupingProvider
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteGroupingAsync(int id)
|
||||
{
|
||||
await _context.ArtifactGroupings
|
||||
.Where(p => p.Id == id)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteGroupingAsync(ArtifactGrouping grouping)
|
||||
{
|
||||
_context.ArtifactGroupings.Remove(grouping);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ArtifactGrouping>> GetGroupingsPaged(int pageNumber, int resultsCount)
|
||||
{
|
||||
if (pageNumber < 1 || resultsCount < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException($"Either page number or number of results was less than or equal to 0. {nameof(pageNumber)}={pageNumber} {nameof(resultsCount)}={resultsCount}");
|
||||
}
|
||||
|
||||
var totalCount = await _context.ArtifactGroupings.CountAsync();
|
||||
|
||||
var items = await _context.ArtifactGroupings
|
||||
.Include(g => g.Category)
|
||||
.OrderBy(g => g.Id)
|
||||
.Skip((pageNumber - 1) * resultsCount)
|
||||
.Take(resultsCount)
|
||||
.ToListAsync();
|
||||
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -9,11 +9,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArtifactStorageLocationProvider : IArtifactStorageLocationProvider
|
||||
{
|
||||
private readonly IDbContextFactory<ArchiveDbContext> _dbFactory;
|
||||
private readonly IDbContextFactory<ApplicationDbContext> _dbFactory;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArtifactStorageLocationProvider(IDbContextFactory<ArchiveDbContext> dbFactory, ILogger<ArtifactStorageLocationProvider> logger)
|
||||
public ArtifactStorageLocationProvider(IDbContextFactory<ApplicationDbContext> dbFactory, ILogger<ArtifactStorageLocationProvider> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_logger = logger;
|
||||
@@ -68,17 +68,66 @@ public class ArtifactStorageLocationProvider : IArtifactStorageLocationProvider
|
||||
{
|
||||
await using var context = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
return await context.ArtifactStorageLocations
|
||||
.Where(p => p.Location.ToLower().Contains(query.ToLower())).ToListAsync();
|
||||
// STEP 1: Get the unique location STRINGS that match the search query.
|
||||
// This simple query is guaranteed to be translated correctly by EF Core.
|
||||
var uniqueMatchingNames = await context.ArtifactStorageLocations
|
||||
.Where(p => p.Location.ToLower().Contains(query.ToLower()))
|
||||
.Select(p => p.Location)
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
// If no names matched, return an empty list immediately.
|
||||
if (uniqueMatchingNames is null || !uniqueMatchingNames.Any())
|
||||
{
|
||||
return new List<ArtifactStorageLocation>();
|
||||
}
|
||||
|
||||
// STEP 2: Now, fetch the full objects that correspond to the unique names.
|
||||
var matchingLocations = await context.ArtifactStorageLocations
|
||||
.Where(p => uniqueMatchingNames.Contains(p.Location))
|
||||
.ToListAsync();
|
||||
|
||||
// STEP 3: Perform a final DistinctBy on the small in-memory list to ensure
|
||||
// a clean result set with one object per location name.
|
||||
var finalResults = matchingLocations
|
||||
.DistinctBy(p => p.Location)
|
||||
.OrderBy(p => p.Location) // Optional: Orders the final search results
|
||||
.ToList();
|
||||
|
||||
return finalResults;
|
||||
}
|
||||
|
||||
public async Task<List<ArtifactStorageLocation>?> Top(int count)
|
||||
{
|
||||
await using var context = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
return await context.ArtifactStorageLocations
|
||||
.OrderBy(p => p.Location)
|
||||
// STEP 1: Get a unique, ordered list of the TOP N location *strings*.
|
||||
// This is a simple query that EF Core can always translate correctly.
|
||||
var uniqueLocationNames = await context.ArtifactStorageLocations
|
||||
.Select(p => p.Location)
|
||||
.Distinct()
|
||||
.OrderBy(locationName => locationName)
|
||||
.Take(count)
|
||||
.ToListAsync();
|
||||
|
||||
if (uniqueLocationNames is null || !uniqueLocationNames.Any())
|
||||
{
|
||||
return new List<ArtifactStorageLocation>();
|
||||
}
|
||||
|
||||
// STEP 2: Fetch all the full ArtifactStorageLocation objects that match the unique names.
|
||||
// We use the list from Step 1 to create a 'WHERE IN (...)' clause.
|
||||
var matchingLocations = await context.ArtifactStorageLocations
|
||||
.Where(p => uniqueLocationNames.Contains(p.Location))
|
||||
.ToListAsync();
|
||||
|
||||
// STEP 3: The previous query might fetch duplicates (e.g., two entries for "Box A").
|
||||
// We now perform the final DistinctBy in-memory, which is guaranteed to work.
|
||||
var finalResults = matchingLocations
|
||||
.DistinctBy(p => p.Location)
|
||||
.OrderBy(p => p.Location) // Re-apply ordering to the final list
|
||||
.ToList();
|
||||
|
||||
return finalResults;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ArtifactTypeProvider : IArtifactTypeProvider
|
||||
{
|
||||
private readonly IDbContextFactory<ArchiveDbContext> _dbFactory;
|
||||
private readonly IDbContextFactory<ApplicationDbContext> _dbFactory;
|
||||
private readonly ILogger<ArtifactTypeProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ArtifactTypeProvider(IDbContextFactory<ArchiveDbContext> dbFactory, ILogger<ArtifactTypeProvider> logger)
|
||||
public ArtifactTypeProvider(IDbContextFactory<ApplicationDbContext> dbFactory, ILogger<ArtifactTypeProvider> logger)
|
||||
{
|
||||
_dbFactory = dbFactory;
|
||||
_logger = logger;
|
||||
|
||||
@@ -5,11 +5,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class FilePathListingProvider : IFilePathListingProvider
|
||||
{
|
||||
private readonly ArchiveDbContext _context;
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly ILogger<FilePathListingProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public FilePathListingProvider(ArchiveDbContext context, ILogger<FilePathListingProvider> logger)
|
||||
public FilePathListingProvider(ApplicationDbContext context, ILogger<FilePathListingProvider> logger)
|
||||
{
|
||||
_context = context;
|
||||
_logger = logger;
|
||||
|
||||
@@ -6,5 +6,7 @@ public interface IArtifactGroupingProvider
|
||||
Task<ArtifactGrouping?> GetGroupingAsync(string artifactGroupingIdentifier);
|
||||
Task CreateGroupingAsync(ArtifactGrouping grouping);
|
||||
Task UpdateGroupingAsync(ArtifactGrouping grouping);
|
||||
Task DeleteGroupingAsync(int id);
|
||||
Task DeleteGroupingAsync(ArtifactGrouping grouping);
|
||||
Task<List<ArtifactGrouping>> GetGroupingsPaged(int pageNumber, int resultsCount);
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
public interface IListedNameProvider
|
||||
{
|
||||
Task<ListedName?> GetAssociatedNameAsync(int id);
|
||||
Task<List<ListedName>?> GetAssociatedNamesAsync(string firstName, string lastName);
|
||||
Task<List<ListedName>?> GetAssociatedNamesAsync(string name);
|
||||
Task CreateAssociatedNameAsync(ListedName associatedName);
|
||||
Task UpdateAssociatedNameAsync(ListedName associatedName);
|
||||
Task DeleteAssociatedNameAsync(ListedName associatedName);
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace OpenArchival.DataAccess;
|
||||
|
||||
public class ListedNameProvider : IListedNameProvider
|
||||
{
|
||||
private readonly IDbContextFactory<ArchiveDbContext> _dbFactory;
|
||||
private readonly IDbContextFactory<ApplicationDbContext> _dbFactory;
|
||||
private readonly ILogger<ListedNameProvider> _logger;
|
||||
|
||||
[SetsRequiredMembers]
|
||||
public ListedNameProvider(IDbContextFactory<ArchiveDbContext> context, ILogger<ListedNameProvider> logger)
|
||||
public ListedNameProvider(IDbContextFactory<ApplicationDbContext> context, ILogger<ListedNameProvider> logger)
|
||||
{
|
||||
_dbFactory = context;
|
||||
_logger = logger;
|
||||
@@ -23,12 +23,12 @@ public class ListedNameProvider : IListedNameProvider
|
||||
return await context.ArtifactAssociatedNames.Where(n => n.Id == id).FirstOrDefaultAsync();
|
||||
}
|
||||
|
||||
public async Task<List<ListedName>?> GetAssociatedNamesAsync(string firstName, string lastName)
|
||||
public async Task<List<ListedName>?> GetAssociatedNamesAsync(string name)
|
||||
{
|
||||
await using var context = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
return await context.ArtifactAssociatedNames
|
||||
.Where(n => n.FirstName == firstName && n.LastName == lastName)
|
||||
.Where(n => n.Value == name)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class ListedNameProvider : IListedNameProvider
|
||||
var lowerCaseQuery = query.ToLower();
|
||||
|
||||
return await context.ArtifactAssociatedNames
|
||||
.Where(p => (p.FirstName + " " + p.LastName).ToLower().Contains(lowerCaseQuery))
|
||||
.Where(p => p.Value.ToLower().Contains(lowerCaseQuery))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ListedNameProvider : IListedNameProvider
|
||||
await using var context = await _dbFactory.CreateDbContextAsync();
|
||||
|
||||
return await context.ArtifactAssociatedNames
|
||||
.OrderBy(p => p.FirstName)
|
||||
.OrderBy(p => p.Value)
|
||||
.Take(count)
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user