Feed: refactor properties and fields
This commit is contained in:
parent
9025dcc0a3
commit
ccd017a927
@ -36,80 +36,21 @@ namespace ASC.Feed
|
||||
|
||||
#region Modules
|
||||
|
||||
public static string BookmarksModule
|
||||
{
|
||||
get { return "bookmarks"; }
|
||||
}
|
||||
|
||||
public static string BlogsModule
|
||||
{
|
||||
get { return "blogs"; }
|
||||
}
|
||||
|
||||
public static string ForumsModule
|
||||
{
|
||||
get { return "forums"; }
|
||||
}
|
||||
|
||||
public static string EventsModule
|
||||
{
|
||||
get { return "events"; }
|
||||
}
|
||||
|
||||
public static string ProjectsModule
|
||||
{
|
||||
get { return "projects"; }
|
||||
}
|
||||
|
||||
public static string MilestonesModule
|
||||
{
|
||||
get { return "milestones"; }
|
||||
}
|
||||
|
||||
public static string DiscussionsModule
|
||||
{
|
||||
get { return "discussions"; }
|
||||
}
|
||||
|
||||
public static string TasksModule
|
||||
{
|
||||
get { return "tasks"; }
|
||||
}
|
||||
|
||||
public static string CommentsModule
|
||||
{
|
||||
get { return "comments"; }
|
||||
}
|
||||
|
||||
public static string CrmTasksModule
|
||||
{
|
||||
get { return "crmTasks"; }
|
||||
}
|
||||
|
||||
public static string ContactsModule
|
||||
{
|
||||
get { return "contacts"; }
|
||||
}
|
||||
|
||||
public static string DealsModule
|
||||
{
|
||||
get { return "deals"; }
|
||||
}
|
||||
|
||||
public static string CasesModule
|
||||
{
|
||||
get { return "cases"; }
|
||||
}
|
||||
|
||||
public static string FilesModule
|
||||
{
|
||||
get { return "files"; }
|
||||
}
|
||||
|
||||
public static string FoldersModule
|
||||
{
|
||||
get { return "folders"; }
|
||||
}
|
||||
public const string BookmarksModule = "bookmarks";
|
||||
public const string BlogsModule = "blogs";
|
||||
public const string ForumsModule = "forums";
|
||||
public const string EventsModule = "events";
|
||||
public const string ProjectsModule = "projects";
|
||||
public const string MilestonesModule = "milestones";
|
||||
public const string DiscussionsModule = "discussions";
|
||||
public const string TasksModule = "tasks";
|
||||
public const string CommentsModule = "comments";
|
||||
public const string CrmTasksModule = "crmTasks";
|
||||
public const string ContactsModule = "contacts";
|
||||
public const string DealsModule = "deals";
|
||||
public const string CasesModule = "cases";
|
||||
public const string FilesModule = "files";
|
||||
public const string FoldersModule = "folders";
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
@ -27,9 +27,38 @@ namespace ASC.Feed.Aggregator
|
||||
{
|
||||
public class Feed
|
||||
{
|
||||
public Feed()
|
||||
{
|
||||
}
|
||||
public string Item { get; set; }
|
||||
public string ItemId { get; set; }
|
||||
public Guid AuthorId { get; private set; }
|
||||
public Guid ModifiedBy { get; set; }
|
||||
public DateTime CreatedDate { get; private set; }
|
||||
public DateTime ModifiedDate { get; set; }
|
||||
public string Product { get; set; }
|
||||
public string Module { get; set; }
|
||||
public string ExtraLocation { get; set; }
|
||||
public string ExtraLocationUrl { get; set; }
|
||||
public FeedAction Action { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string ItemUrl { get; set; }
|
||||
public string Description { get; set; }
|
||||
public string AdditionalInfo { get; set; }
|
||||
public string AdditionalInfo2 { get; set; }
|
||||
public string AdditionalInfo3 { get; set; }
|
||||
public string AdditionalInfo4 { get; set; }
|
||||
public bool HasPreview { get; set; }
|
||||
public bool CanComment { get; set; }
|
||||
public object Target { get; set; }
|
||||
public string CommentApiUrl { get; set; }
|
||||
public IEnumerable<FeedComment> Comments { get; set; }
|
||||
public string GroupId { get; set; }
|
||||
public string Keywords { get; set; }
|
||||
public string Id => $"{Item}_{ItemId}";
|
||||
|
||||
// это значит, что новость может обновляться (пр. добавление комментариев);
|
||||
// следовательно и права доступа могут устаревать
|
||||
public bool Variate { get; private set; }
|
||||
|
||||
public Feed() { }
|
||||
|
||||
public Feed(Guid author, DateTime date, bool variate = false)
|
||||
{
|
||||
@ -42,65 +71,5 @@ namespace ASC.Feed.Aggregator
|
||||
Action = FeedAction.Created;
|
||||
Variate = variate;
|
||||
}
|
||||
|
||||
public string Item { get; set; }
|
||||
|
||||
public string ItemId { get; set; }
|
||||
|
||||
public string Id
|
||||
{
|
||||
get { return $"{Item}_{ItemId}"; }
|
||||
}
|
||||
|
||||
public Guid AuthorId { get; private set; }
|
||||
|
||||
public Guid ModifiedBy { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; private set; }
|
||||
|
||||
public DateTime ModifiedDate { get; set; }
|
||||
|
||||
public string Product { get; set; }
|
||||
|
||||
public string Module { get; set; }
|
||||
|
||||
public string ExtraLocation { get; set; }
|
||||
|
||||
public string ExtraLocationUrl { get; set; }
|
||||
|
||||
public FeedAction Action { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string ItemUrl { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string AdditionalInfo { get; set; }
|
||||
|
||||
public string AdditionalInfo2 { get; set; }
|
||||
|
||||
public string AdditionalInfo3 { get; set; }
|
||||
|
||||
public string AdditionalInfo4 { get; set; }
|
||||
|
||||
public bool HasPreview { get; set; }
|
||||
|
||||
public bool CanComment { get; set; }
|
||||
|
||||
public object Target { get; set; }
|
||||
|
||||
public string CommentApiUrl { get; set; }
|
||||
|
||||
public IEnumerable<FeedComment> Comments { get; set; }
|
||||
|
||||
|
||||
// это значит, что новость может обновляться (пр. добавление комментариев);
|
||||
// следовательно и права доступа могут устаревать
|
||||
public bool Variate { get; private set; }
|
||||
|
||||
public string GroupId { get; set; }
|
||||
|
||||
public string Keywords { get; set; }
|
||||
}
|
||||
}
|
@ -27,15 +27,14 @@ namespace ASC.Feed.Aggregator
|
||||
{
|
||||
public class FeedComment
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public Guid AuthorId { get; private set; }
|
||||
|
||||
public FeedComment(Guid author)
|
||||
{
|
||||
AuthorId = author;
|
||||
}
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Description { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
}
|
||||
}
|
@ -27,9 +27,9 @@ namespace ASC.Feed
|
||||
{
|
||||
public struct FeedFilter
|
||||
{
|
||||
public int Tenant { get; set; }
|
||||
public TimeInterval Time { get; private set; }
|
||||
|
||||
public int Tenant { get; set; }
|
||||
|
||||
public FeedFilter(TimeInterval time) : this()
|
||||
{
|
||||
|
@ -33,49 +33,37 @@ namespace ASC.Feed
|
||||
public class FeedMin
|
||||
{
|
||||
public string Id { get; set; }
|
||||
|
||||
public Guid AuthorId { get; set; }
|
||||
|
||||
public FeedMinUser Author { get; set; }
|
||||
|
||||
public DateTime CreatedDate { get; set; }
|
||||
|
||||
public DateTime ModifiedDate { get; set; }
|
||||
|
||||
public string Product { get; set; }
|
||||
|
||||
public string Item { get; set; }
|
||||
|
||||
public string Title { get; set; }
|
||||
|
||||
public string ItemUrl { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public string AdditionalInfo { get; set; }
|
||||
|
||||
public string AdditionalInfo2 { get; set; }
|
||||
|
||||
public string Module { get; set; }
|
||||
|
||||
public string ExtraLocation { get; set; }
|
||||
|
||||
public IEnumerable<FeedComment> Comments { get; set; }
|
||||
|
||||
public class FeedComment
|
||||
{
|
||||
public Guid AuthorId { get; set; }
|
||||
|
||||
public FeedMinUser Author { get; set; }
|
||||
|
||||
public string Description { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
|
||||
public FeedMin ToFeedMin()
|
||||
{
|
||||
return new FeedMin { Author = Author, Title = Description, CreatedDate = Date, ModifiedDate = Date };
|
||||
return new FeedMin
|
||||
{
|
||||
Author = Author,
|
||||
Title = Description,
|
||||
CreatedDate = Date,
|
||||
ModifiedDate = Date
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,21 +27,15 @@ namespace ASC.Feed
|
||||
{
|
||||
public struct TimeInterval
|
||||
{
|
||||
private readonly DateTime toTime;
|
||||
|
||||
|
||||
public DateTime From { get; }
|
||||
public DateTime To => _toTime != default ? _toTime : DateTime.MaxValue;
|
||||
|
||||
public DateTime To
|
||||
{
|
||||
get { return toTime != default ? toTime : DateTime.MaxValue; }
|
||||
}
|
||||
|
||||
private readonly DateTime _toTime;
|
||||
|
||||
public TimeInterval(DateTime fromTime, DateTime toTime)
|
||||
{
|
||||
this.From = fromTime;
|
||||
this.toTime = toTime;
|
||||
From = fromTime;
|
||||
_toTime = toTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,23 +28,27 @@ namespace ASC.Feed.Data
|
||||
[Scope]
|
||||
public class FeedAggregateDataProvider
|
||||
{
|
||||
private AuthContext AuthContext { get; }
|
||||
private TenantManager TenantManager { get; }
|
||||
private TenantUtil TenantUtil { get; }
|
||||
private Lazy<FeedDbContext> LazyFeedDbContext { get; }
|
||||
private FeedDbContext FeedDbContext { get => LazyFeedDbContext.Value; }
|
||||
private readonly AuthContext _authContext;
|
||||
private readonly TenantManager _tenantManager;
|
||||
private readonly TenantUtil _tenantUtil;
|
||||
private readonly Lazy<FeedDbContext> _lazyFeedDbContext;
|
||||
private readonly FeedDbContext FeedDbContext => _lazyFeedDbContext.Value;
|
||||
|
||||
public FeedAggregateDataProvider(AuthContext authContext, TenantManager tenantManager, TenantUtil tenantUtil, DbContextManager<FeedDbContext> dbContextManager)
|
||||
public FeedAggregateDataProvider(
|
||||
AuthContext authContext,
|
||||
TenantManager tenantManager,
|
||||
TenantUtil tenantUtil,
|
||||
DbContextManager<FeedDbContext> dbContextManager)
|
||||
: this(authContext, tenantManager, tenantUtil)
|
||||
{
|
||||
LazyFeedDbContext = new Lazy<FeedDbContext>(() => dbContextManager.Get(Constants.FeedDbId));
|
||||
_lazyFeedDbContext = new Lazy<FeedDbContext>(() => dbContextManager.Get(Constants.FeedDbId));
|
||||
}
|
||||
|
||||
public FeedAggregateDataProvider(AuthContext authContext, TenantManager tenantManager, TenantUtil tenantUtil)
|
||||
{
|
||||
AuthContext = authContext;
|
||||
TenantManager = tenantManager;
|
||||
TenantUtil = tenantUtil;
|
||||
_authContext = authContext;
|
||||
_tenantManager = tenantManager;
|
||||
_tenantUtil = tenantUtil;
|
||||
}
|
||||
|
||||
public DateTime GetLastTimeAggregate(string key)
|
||||
@ -183,10 +187,10 @@ namespace ASC.Feed.Data
|
||||
private List<FeedResultItem> GetFeedsInternal(FeedApiFilter filter)
|
||||
{
|
||||
var q = FeedDbContext.FeedAggregates
|
||||
.Where(r => r.Tenant == TenantManager.GetCurrentTenant().TenantId)
|
||||
.Where(r => r.ModifiedBy != AuthContext.CurrentAccount.ID)
|
||||
.Where(r => r.Tenant == _tenantManager.GetCurrentTenant().TenantId)
|
||||
.Where(r => r.ModifiedBy != _authContext.CurrentAccount.ID)
|
||||
.Join(FeedDbContext.FeedUsers, a => a.Id, b => b.FeedId, (aggregates, users) => new { aggregates, users })
|
||||
.Where(r => r.users.UserId == AuthContext.CurrentAccount.ID)
|
||||
.Where(r => r.users.UserId == _authContext.CurrentAccount.ID)
|
||||
.OrderByDescending(r => r.aggregates.ModifiedDate)
|
||||
.Skip(filter.Offset)
|
||||
.Take(filter.Max);
|
||||
@ -235,10 +239,10 @@ namespace ASC.Feed.Data
|
||||
r.Author,
|
||||
r.ModifiedBy,
|
||||
r.GroupId,
|
||||
TenantUtil.DateTimeFromUtc(r.CreatedDate),
|
||||
TenantUtil.DateTimeFromUtc(r.ModifiedDate),
|
||||
TenantUtil.DateTimeFromUtc(r.AggregateDate),
|
||||
TenantUtil))
|
||||
_tenantUtil.DateTimeFromUtc(r.CreatedDate),
|
||||
_tenantUtil.DateTimeFromUtc(r.ModifiedDate),
|
||||
_tenantUtil.DateTimeFromUtc(r.AggregateDate),
|
||||
_tenantUtil))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@ -293,9 +297,19 @@ namespace ASC.Feed.Data
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class FeedResultItem
|
||||
{
|
||||
public string Json { get; private set; }
|
||||
public string Module { get; private set; }
|
||||
public Guid AuthorId { get; private set; }
|
||||
public Guid ModifiedById { get; private set; }
|
||||
public string GroupId { get; private set; }
|
||||
public bool IsToday { get; private set; }
|
||||
public bool IsYesterday { get; private set; }
|
||||
public DateTime CreatedDate { get; private set; }
|
||||
public DateTime ModifiedDate { get; private set; }
|
||||
public DateTime AggregatedDate { get; private set; }
|
||||
|
||||
public FeedResultItem(
|
||||
string json,
|
||||
string module,
|
||||
@ -331,26 +345,6 @@ namespace ASC.Feed.Data
|
||||
AggregatedDate = aggregatedDate;
|
||||
}
|
||||
|
||||
public string Json { get; private set; }
|
||||
|
||||
public string Module { get; private set; }
|
||||
|
||||
public Guid AuthorId { get; private set; }
|
||||
|
||||
public Guid ModifiedById { get; private set; }
|
||||
|
||||
public string GroupId { get; private set; }
|
||||
|
||||
public bool IsToday { get; private set; }
|
||||
|
||||
public bool IsYesterday { get; private set; }
|
||||
|
||||
public DateTime CreatedDate { get; private set; }
|
||||
|
||||
public DateTime ModifiedDate { get; private set; }
|
||||
|
||||
public DateTime AggregatedDate { get; private set; }
|
||||
|
||||
public FeedMin ToFeedMin(UserManager userManager)
|
||||
{
|
||||
var feedMin = JsonConvert.DeserializeObject<FeedMin>(Json);
|
||||
|
@ -27,18 +27,19 @@ namespace ASC.Feed.Data
|
||||
{
|
||||
public class FeedReadedDataProvider
|
||||
{
|
||||
private const string dbId = Constants.FeedDbId;
|
||||
private FeedDbContext FeedDbContext => _lazyFeedDbContext.Value;
|
||||
|
||||
private AuthContext AuthContext { get; }
|
||||
private TenantManager TenantManager { get; }
|
||||
private Lazy<FeedDbContext> LazyFeedDbContext { get; }
|
||||
private FeedDbContext FeedDbContext { get => LazyFeedDbContext.Value; }
|
||||
private const string _dbId = Constants.FeedDbId;
|
||||
|
||||
private readonly AuthContext _authContext;
|
||||
private readonly TenantManager _tenantManager;
|
||||
private readonly Lazy<FeedDbContext> _lazyFeedDbContext;
|
||||
|
||||
public FeedReadedDataProvider(AuthContext authContext, TenantManager tenantManager, DbContextManager<FeedDbContext> dbContextManager)
|
||||
{
|
||||
AuthContext = authContext;
|
||||
TenantManager = tenantManager;
|
||||
LazyFeedDbContext = new Lazy<FeedDbContext>(() => dbContextManager.Get(dbId));
|
||||
_authContext = authContext;
|
||||
_tenantManager = tenantManager;
|
||||
_lazyFeedDbContext = new Lazy<FeedDbContext>(() => dbContextManager.Get(_dbId));
|
||||
}
|
||||
|
||||
public DateTime GetTimeReaded()
|
||||
@ -108,12 +109,12 @@ namespace ASC.Feed.Data
|
||||
|
||||
private int GetTenant()
|
||||
{
|
||||
return TenantManager.GetCurrentTenant().TenantId;
|
||||
return _tenantManager.GetCurrentTenant().TenantId;
|
||||
}
|
||||
|
||||
private Guid GetUser()
|
||||
{
|
||||
return AuthContext.CurrentAccount.ID;
|
||||
return _authContext.CurrentAccount.ID;
|
||||
}
|
||||
}
|
||||
}
|
@ -27,28 +27,20 @@ namespace ASC.Feed.Data
|
||||
{
|
||||
public class FeedRow
|
||||
{
|
||||
public Aggregator.Feed Feed { get; private set; }
|
||||
|
||||
public string Id { get { return Feed.Id; } }
|
||||
|
||||
public bool ClearRightsBeforeInsert { get { return Feed.Variate; } }
|
||||
|
||||
public DateTime AggregatedDate { get; set; }
|
||||
public IList<Guid> Users { get; set; }
|
||||
public int Tenant { get; set; }
|
||||
|
||||
public string ProductId { get; set; }
|
||||
|
||||
public string ModuleId { get { return Feed.Module; } }
|
||||
|
||||
public Guid AuthorId { get { return Feed.AuthorId; } }
|
||||
|
||||
public Guid ModifiedById { get { return Feed.ModifiedBy; } }
|
||||
|
||||
public DateTime CreatedDate { get { return Feed.CreatedDate; } }
|
||||
|
||||
public DateTime ModifiedDate { get { return Feed.ModifiedDate; } }
|
||||
|
||||
public string GroupId { get { return Feed.GroupId; } }
|
||||
|
||||
public Aggregator.Feed Feed { get; private set; }
|
||||
public string Id => Feed.Id;
|
||||
public bool ClearRightsBeforeInsert => Feed.Variate;
|
||||
public string ModuleId => Feed.Module;
|
||||
public Guid AuthorId => Feed.AuthorId;
|
||||
public Guid ModifiedById => Feed.ModifiedBy;
|
||||
public DateTime CreatedDate => Feed.CreatedDate;
|
||||
public DateTime ModifiedDate => Feed.ModifiedDate;
|
||||
public string GroupId => Feed.GroupId;
|
||||
public string Keywords => Feed.Keywords;
|
||||
public string Json
|
||||
{
|
||||
get
|
||||
@ -60,13 +52,6 @@ namespace ASC.Feed.Data
|
||||
}
|
||||
}
|
||||
|
||||
public string Keywords { get { return Feed.Keywords; } }
|
||||
|
||||
public DateTime AggregatedDate { get; set; }
|
||||
|
||||
public IList<Guid> Users { get; set; }
|
||||
|
||||
|
||||
public FeedRow(Aggregator.Feed feed)
|
||||
{
|
||||
Users = new List<Guid>();
|
||||
|
Loading…
Reference in New Issue
Block a user