Fixed issue with Bookmarks with no tags not being returned #25
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using YABA.Common.Interfaces;
|
||||
@ -21,5 +22,7 @@ namespace YABA.Models
|
||||
[ForeignKey(nameof(User))]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public ICollection<BookmarkTag> BookmarkTags { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using YABA.Models.Interfaces;
|
||||
|
||||
@ -14,5 +15,7 @@ namespace YABA.Models
|
||||
[ForeignKey(nameof(User))]
|
||||
public int UserId { get; set; }
|
||||
public virtual User User { get; set; }
|
||||
|
||||
public virtual ICollection<BookmarkTag> TagBookmarks { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using HtmlAgilityPack;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@ -40,27 +41,29 @@ namespace YABA.Service
|
||||
public IEnumerable<BookmarkDTO> GetAll(bool showHidden = false)
|
||||
{
|
||||
var currentUserId = GetCurrentUserId();
|
||||
|
||||
var bookmarkTagsLookup = _roContext.BookmarkTags
|
||||
.Include(x => x.Bookmark)
|
||||
.Include(x => x.Tag)
|
||||
.Where(x => x.Bookmark.UserId == currentUserId && x.Tag.UserId == currentUserId)
|
||||
.ToList()
|
||||
.GroupBy(x => x.BookmarkId)
|
||||
.ToDictionary(k => k.Key, v => new KeyValuePair<Bookmark, List<Tag>>(v.FirstOrDefault()?.Bookmark, v.Select(x => x.Tag).ToList()));
|
||||
var userBookmarkDTOs = new List<BookmarkDTO>();
|
||||
|
||||
foreach (var bookmarkTag in bookmarkTagsLookup)
|
||||
|
||||
var showHiddenCondition = new Func<Bookmark, bool>(b => b.IsHidden || b.BookmarkTags.Where(x => x.Tag.UserId == currentUserId).Any(x => x.Tag.IsHidden));
|
||||
var showNotHiddenCondition = new Func<Bookmark, bool>(b => !b.IsHidden && b.BookmarkTags.Where(x => x.Tag.UserId == currentUserId).All(bt => !bt.Tag.IsHidden));
|
||||
|
||||
var filteredBookmarks = _roContext.Bookmarks
|
||||
.Include(b => b.BookmarkTags)
|
||||
.ThenInclude(bt => bt.Tag)
|
||||
.Where(b => b.UserId == currentUserId)
|
||||
.Where(showHidden ? showHiddenCondition : showNotHiddenCondition)
|
||||
.ToList();
|
||||
|
||||
foreach(var bookmark in filteredBookmarks)
|
||||
{
|
||||
if ((showHidden && (bookmarkTag.Value.Key.IsHidden || bookmarkTag.Value.Value.Any(x => x.IsHidden))) // If showHidden = true, only add Bookmarks that are marked Hidden OR when any of its Tags are marked Hidden
|
||||
|| (!showHidden && !bookmarkTag.Value.Key.IsHidden && bookmarkTag.Value.Value.All(x => !x.IsHidden))) // If showHidden = false, only add when Bookmark is not marked Hidden AND when any of its Tags are not marked as Hidden
|
||||
{
|
||||
var bookmarkDTO = _mapper.Map<BookmarkDTO>(bookmarkTag.Value.Key);
|
||||
var bookmarkTagDTOs = _mapper.Map<IEnumerable<TagDTO>>(bookmarkTag.Value.Value);
|
||||
bookmarkDTO.Tags.AddRange(bookmarkTagDTOs);
|
||||
var isBookmarkHidden = bookmark.IsHidden;
|
||||
var bookmarkDTO = _mapper.Map<BookmarkDTO>(bookmark);
|
||||
|
||||
var bookmarkTags = bookmark.BookmarkTags.Select(x => x.Tag);
|
||||
bookmarkDTO.Tags = _mapper.Map<List<TagDTO>>(bookmarkTags);
|
||||
|
||||
userBookmarkDTOs.Add(bookmarkDTO);
|
||||
}
|
||||
}
|
||||
|
||||
return userBookmarkDTOs;
|
||||
}
|
||||
|
||||
@ -328,7 +328,7 @@ export function BookmarksListView(props) {
|
||||
}
|
||||
</Col>
|
||||
<Col xs="3">
|
||||
{ getTagGroups(getNotSelectedTags()).length <= 0 && <div className="fs-3">No Tags gound</div> }
|
||||
{ getTagGroups(getNotSelectedTags()).length <= 0 && <div className="fs-3">No Tags found</div> }
|
||||
{
|
||||
getTagGroups(getNotSelectedTags()).map((group) => {
|
||||
return <div key={group.name} className="mb-3">
|
||||
|
||||
Reference in New Issue
Block a user