41 lines
1.5 KiB
C#
41 lines
1.5 KiB
C#
using Data.Data.Repositories;
|
|
using Data.Errors;
|
|
using DeepDrftData.Data;
|
|
using DeepDrftModels.Entities;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace DeepDrftData.Repositories;
|
|
|
|
public class TrackRepository : Repository<DeepDrftContext, TrackEntity>
|
|
{
|
|
private readonly DeepDrftContext _context;
|
|
|
|
public TrackRepository(
|
|
DeepDrftContext context,
|
|
ILogger<Repository<DeepDrftContext, TrackEntity>> logger,
|
|
IDbExceptionClassifier? classifier = null)
|
|
: base(context, logger, classifier: classifier)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
// Lookup by vault entry key. The base Repository<> only exposes id-based queries, so this
|
|
// queries the DbSet directly. Returns null on miss (service wraps in ResultContainer).
|
|
public async Task<TrackEntity?> GetByEntryKeyAsync(string entryKey)
|
|
=> await _context.Tracks.FirstOrDefaultAsync(t => t.EntryKey == entryKey);
|
|
|
|
protected override void UpdateEntity(TrackEntity target, TrackEntity source)
|
|
{
|
|
base.UpdateEntity(target, source); // copies CreatedAt, UpdatedAt, IsDeleted
|
|
target.EntryKey = source.EntryKey;
|
|
target.TrackName = source.TrackName;
|
|
target.Artist = source.Artist;
|
|
target.Album = source.Album;
|
|
target.Genre = source.Genre;
|
|
target.ReleaseDate = source.ReleaseDate;
|
|
target.ImagePath = source.ImagePath;
|
|
target.CreatedByUserId = source.CreatedByUserId;
|
|
}
|
|
}
|