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

@@ -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);