1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 17:12:49 -05:00

Split out repositories to Infrastructure.Dapper / EntityFramework (#1759)

This commit is contained in:
Oscar Hinton
2022-01-11 10:40:51 +01:00
committed by GitHub
parent e2c6fc81f4
commit e4a10aae27
536 changed files with 1629 additions and 1589 deletions

View File

@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Bit.Core.Utilities;
using Core.Models.Data;
namespace Bit.Infrastructure.EntityFramework.Repositories.Queries
{
public class CipherDetailsQuery : IQuery<CipherDetails>
{
private readonly Guid? _userId;
private readonly bool _ignoreFolders;
public CipherDetailsQuery(Guid? userId, bool ignoreFolders = false)
{
_userId = userId;
_ignoreFolders = ignoreFolders;
}
public virtual IQueryable<CipherDetails> Run(DatabaseContext dbContext)
{
var query = from c in dbContext.Ciphers
select new CipherDetails
{
Id = c.Id,
UserId = c.UserId,
OrganizationId = c.OrganizationId,
Type = c.Type,
Data = c.Data,
Attachments = c.Attachments,
CreationDate = c.CreationDate,
RevisionDate = c.RevisionDate,
DeletedDate = c.DeletedDate,
Favorite = _userId.HasValue && c.Favorites != null && c.Favorites.Contains($"\"{_userId}\":true"),
FolderId = (_ignoreFolders || !_userId.HasValue || c.Folders == null || !c.Folders.Contains(_userId.Value.ToString())) ?
null :
CoreHelpers.LoadClassFromJsonData<Dictionary<Guid, Guid>>(c.Folders)[_userId.Value],
};
return query;
}
}
}