db changes and build pipeline
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
2022-07-15 12:21:37 -04:00
parent 5337e7ccb8
commit e6d6b629db
30 changed files with 1332 additions and 132 deletions

View File

@@ -47,6 +47,11 @@ public abstract class BaseRepository<TEntityType> : IRepository<TEntityType> whe
return entity;
}
public virtual async Task<IEnumerable<TEntityType>> GetAllIncluded()
{
return await GetWhereIncluded(i => true);
}
public virtual async Task<TEntityType?> GetIncluded(TEntityType entity)
{
return await GetIncluded(dbEntity => GetPrimaryKey(dbEntity).SequenceEqual(GetPrimaryKey(entity)));

View File

@@ -4,5 +4,5 @@ namespace DBConnection.Repositories.Interfaces;
public interface INovelRepository : IRepository<Novel>
{
Task<Novel?> GetNovel(Guid guid);
}

View File

@@ -14,4 +14,5 @@ public interface IRepository<TEntityType> : IRepository where TEntityType : Base
Task<TEntityType?> GetIncluded(TEntityType entity);
Task<TEntityType?> GetIncluded(Func<TEntityType, bool> predicate);
Task<IEnumerable<TEntityType>> GetWhereIncluded(Func<TEntityType, bool> predicate);
Task<IEnumerable<TEntityType>> GetAllIncluded();
}

View File

@@ -17,16 +17,38 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
public override async Task<Novel> Upsert(Novel entity)
{
var dbEntity = await GetIncluded(entity) ?? entity;
// Author
dbEntity.Author = await _authorRepository.GetIncluded(entity.Author) ?? entity.Author;
//Tags
List<Tag> newTags = new List<Tag>();
foreach (var tag in dbEntity.Tags)
foreach (var tag in entity.Tags)
{
newTags.Add(await _tagRepository.GetIncluded(tag) ?? tag);
}
dbEntity.Tags.Clear();
dbEntity.Tags = newTags;
//chapters
var newChapters = new List<Chapter>();
foreach (var chapter in entity.Chapters.ToList())
{
var existingChapter = await DbContext.Chapters.FindAsync(chapter.Url);
if (existingChapter == null)
{
newChapters.Add(chapter);
}
else
{
existingChapter.Name = chapter.Name;
existingChapter.DateUpdated = chapter.DateUpdated;
newChapters.Add(existingChapter);
}
}
dbEntity.Chapters.Clear();
dbEntity.Chapters = newChapters;
// update in db
if (DbContext.Entry(dbEntity).State == EntityState.Detached)
{
dbEntity.Guid = Guid.NewGuid();
DbContext.Add(dbEntity);
}
@@ -42,6 +64,11 @@ public class NovelRepository : BaseRepository<Novel>, INovelRepository
.Include(i => i.Tags);
}
public async Task<Novel?> GetNovel(Guid guid)
{
return await GetIncluded(i => i.Guid == guid);
}
public async Task<Novel?> GetNovel(string url)
{
return await GetIncluded(i => i.Url == url);