Feed: refactor properties and fields

This commit is contained in:
Maksim Chegulov 2022-02-10 19:53:52 +03:00
parent 9025dcc0a3
commit ccd017a927
9 changed files with 117 additions and 246 deletions

View File

@ -36,80 +36,21 @@ namespace ASC.Feed
#region Modules #region Modules
public static string BookmarksModule public const string BookmarksModule = "bookmarks";
{ public const string BlogsModule = "blogs";
get { return "bookmarks"; } public const string ForumsModule = "forums";
} public const string EventsModule = "events";
public const string ProjectsModule = "projects";
public static string BlogsModule public const string MilestonesModule = "milestones";
{ public const string DiscussionsModule = "discussions";
get { return "blogs"; } public const string TasksModule = "tasks";
} public const string CommentsModule = "comments";
public const string CrmTasksModule = "crmTasks";
public static string ForumsModule public const string ContactsModule = "contacts";
{ public const string DealsModule = "deals";
get { return "forums"; } public const string CasesModule = "cases";
} public const string FilesModule = "files";
public const string FoldersModule = "folders";
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"; }
}
#endregion #endregion
} }

View File

@ -27,9 +27,38 @@ namespace ASC.Feed.Aggregator
{ {
public class Feed 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) public Feed(Guid author, DateTime date, bool variate = false)
{ {
@ -42,65 +71,5 @@ namespace ASC.Feed.Aggregator
Action = FeedAction.Created; Action = FeedAction.Created;
Variate = variate; 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; }
} }
} }

View File

@ -27,15 +27,14 @@ namespace ASC.Feed.Aggregator
{ {
public class FeedComment 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 Guid AuthorId { get; private set; }
public FeedComment(Guid author) public FeedComment(Guid author)
{ {
AuthorId = author; AuthorId = author;
} }
public string Id { get; set; }
public string Description { get; set; }
public DateTime Date { get; set; }
} }
} }

View File

@ -27,9 +27,9 @@ namespace ASC.Feed
{ {
public struct FeedFilter public struct FeedFilter
{ {
public int Tenant { get; set; }
public TimeInterval Time { get; private set; } public TimeInterval Time { get; private set; }
public int Tenant { get; set; }
public FeedFilter(TimeInterval time) : this() public FeedFilter(TimeInterval time) : this()
{ {

View File

@ -33,49 +33,37 @@ namespace ASC.Feed
public class FeedMin public class FeedMin
{ {
public string Id { get; set; } public string Id { get; set; }
public Guid AuthorId { get; set; } public Guid AuthorId { get; set; }
public FeedMinUser Author { get; set; } public FeedMinUser Author { get; set; }
public DateTime CreatedDate { get; set; } public DateTime CreatedDate { get; set; }
public DateTime ModifiedDate { get; set; } public DateTime ModifiedDate { get; set; }
public string Product { get; set; } public string Product { get; set; }
public string Item { get; set; } public string Item { get; set; }
public string Title { get; set; } public string Title { get; set; }
public string ItemUrl { get; set; } public string ItemUrl { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string AdditionalInfo { get; set; } public string AdditionalInfo { get; set; }
public string AdditionalInfo2 { get; set; } public string AdditionalInfo2 { get; set; }
public string Module { get; set; } public string Module { get; set; }
public string ExtraLocation { get; set; } public string ExtraLocation { get; set; }
public IEnumerable<FeedComment> Comments { get; set; } public IEnumerable<FeedComment> Comments { get; set; }
public class FeedComment public class FeedComment
{ {
public Guid AuthorId { get; set; } public Guid AuthorId { get; set; }
public FeedMinUser Author { get; set; } public FeedMinUser Author { get; set; }
public string Description { get; set; } public string Description { get; set; }
public DateTime Date { get; set; } public DateTime Date { get; set; }
public FeedMin ToFeedMin() 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
};
} }
} }
} }

View File

@ -27,21 +27,15 @@ namespace ASC.Feed
{ {
public struct TimeInterval public struct TimeInterval
{ {
private readonly DateTime toTime;
public DateTime From { get; } public DateTime From { get; }
public DateTime To => _toTime != default ? _toTime : DateTime.MaxValue;
public DateTime To private readonly DateTime _toTime;
{
get { return toTime != default ? toTime : DateTime.MaxValue; }
}
public TimeInterval(DateTime fromTime, DateTime toTime) public TimeInterval(DateTime fromTime, DateTime toTime)
{ {
this.From = fromTime; From = fromTime;
this.toTime = toTime; _toTime = toTime;
} }
} }
} }

View File

@ -28,23 +28,27 @@ namespace ASC.Feed.Data
[Scope] [Scope]
public class FeedAggregateDataProvider public class FeedAggregateDataProvider
{ {
private AuthContext AuthContext { get; } private readonly AuthContext _authContext;
private TenantManager TenantManager { get; } private readonly TenantManager _tenantManager;
private TenantUtil TenantUtil { get; } private readonly TenantUtil _tenantUtil;
private Lazy<FeedDbContext> LazyFeedDbContext { get; } private readonly Lazy<FeedDbContext> _lazyFeedDbContext;
private FeedDbContext FeedDbContext { get => LazyFeedDbContext.Value; } 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) : 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) public FeedAggregateDataProvider(AuthContext authContext, TenantManager tenantManager, TenantUtil tenantUtil)
{ {
AuthContext = authContext; _authContext = authContext;
TenantManager = tenantManager; _tenantManager = tenantManager;
TenantUtil = tenantUtil; _tenantUtil = tenantUtil;
} }
public DateTime GetLastTimeAggregate(string key) public DateTime GetLastTimeAggregate(string key)
@ -183,10 +187,10 @@ namespace ASC.Feed.Data
private List<FeedResultItem> GetFeedsInternal(FeedApiFilter filter) private List<FeedResultItem> GetFeedsInternal(FeedApiFilter filter)
{ {
var q = FeedDbContext.FeedAggregates var q = FeedDbContext.FeedAggregates
.Where(r => r.Tenant == TenantManager.GetCurrentTenant().TenantId) .Where(r => r.Tenant == _tenantManager.GetCurrentTenant().TenantId)
.Where(r => r.ModifiedBy != AuthContext.CurrentAccount.ID) .Where(r => r.ModifiedBy != _authContext.CurrentAccount.ID)
.Join(FeedDbContext.FeedUsers, a => a.Id, b => b.FeedId, (aggregates, users) => new { aggregates, users }) .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) .OrderByDescending(r => r.aggregates.ModifiedDate)
.Skip(filter.Offset) .Skip(filter.Offset)
.Take(filter.Max); .Take(filter.Max);
@ -235,10 +239,10 @@ namespace ASC.Feed.Data
r.Author, r.Author,
r.ModifiedBy, r.ModifiedBy,
r.GroupId, r.GroupId,
TenantUtil.DateTimeFromUtc(r.CreatedDate), _tenantUtil.DateTimeFromUtc(r.CreatedDate),
TenantUtil.DateTimeFromUtc(r.ModifiedDate), _tenantUtil.DateTimeFromUtc(r.ModifiedDate),
TenantUtil.DateTimeFromUtc(r.AggregateDate), _tenantUtil.DateTimeFromUtc(r.AggregateDate),
TenantUtil)) _tenantUtil))
.ToList(); .ToList();
} }
@ -293,9 +297,19 @@ namespace ASC.Feed.Data
} }
} }
public class FeedResultItem 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( public FeedResultItem(
string json, string json,
string module, string module,
@ -331,26 +345,6 @@ namespace ASC.Feed.Data
AggregatedDate = aggregatedDate; 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) public FeedMin ToFeedMin(UserManager userManager)
{ {
var feedMin = JsonConvert.DeserializeObject<FeedMin>(Json); var feedMin = JsonConvert.DeserializeObject<FeedMin>(Json);

View File

@ -27,18 +27,19 @@ namespace ASC.Feed.Data
{ {
public class FeedReadedDataProvider public class FeedReadedDataProvider
{ {
private const string dbId = Constants.FeedDbId; private FeedDbContext FeedDbContext => _lazyFeedDbContext.Value;
private AuthContext AuthContext { get; } private const string _dbId = Constants.FeedDbId;
private TenantManager TenantManager { get; }
private Lazy<FeedDbContext> LazyFeedDbContext { get; }
private FeedDbContext FeedDbContext { get => LazyFeedDbContext.Value; }
private readonly AuthContext _authContext;
private readonly TenantManager _tenantManager;
private readonly Lazy<FeedDbContext> _lazyFeedDbContext;
public FeedReadedDataProvider(AuthContext authContext, TenantManager tenantManager, DbContextManager<FeedDbContext> dbContextManager) public FeedReadedDataProvider(AuthContext authContext, TenantManager tenantManager, DbContextManager<FeedDbContext> dbContextManager)
{ {
AuthContext = authContext; _authContext = authContext;
TenantManager = tenantManager; _tenantManager = tenantManager;
LazyFeedDbContext = new Lazy<FeedDbContext>(() => dbContextManager.Get(dbId)); _lazyFeedDbContext = new Lazy<FeedDbContext>(() => dbContextManager.Get(_dbId));
} }
public DateTime GetTimeReaded() public DateTime GetTimeReaded()
@ -108,12 +109,12 @@ namespace ASC.Feed.Data
private int GetTenant() private int GetTenant()
{ {
return TenantManager.GetCurrentTenant().TenantId; return _tenantManager.GetCurrentTenant().TenantId;
} }
private Guid GetUser() private Guid GetUser()
{ {
return AuthContext.CurrentAccount.ID; return _authContext.CurrentAccount.ID;
} }
} }
} }

View File

@ -27,28 +27,20 @@ namespace ASC.Feed.Data
{ {
public class FeedRow public class FeedRow
{ {
public Aggregator.Feed Feed { get; private set; } public DateTime AggregatedDate { get; set; }
public IList<Guid> Users { get; set; }
public string Id { get { return Feed.Id; } }
public bool ClearRightsBeforeInsert { get { return Feed.Variate; } }
public int Tenant { get; set; } public int Tenant { get; set; }
public string ProductId { get; set; } public string ProductId { get; set; }
public Aggregator.Feed Feed { get; private set; }
public string ModuleId { get { return Feed.Module; } } public string Id => Feed.Id;
public bool ClearRightsBeforeInsert => Feed.Variate;
public Guid AuthorId { get { return Feed.AuthorId; } } public string ModuleId => Feed.Module;
public Guid AuthorId => Feed.AuthorId;
public Guid ModifiedById { get { return Feed.ModifiedBy; } } public Guid ModifiedById => Feed.ModifiedBy;
public DateTime CreatedDate => Feed.CreatedDate;
public DateTime CreatedDate { get { return Feed.CreatedDate; } } public DateTime ModifiedDate => Feed.ModifiedDate;
public string GroupId => Feed.GroupId;
public DateTime ModifiedDate { get { return Feed.ModifiedDate; } } public string Keywords => Feed.Keywords;
public string GroupId { get { return Feed.GroupId; } }
public string Json public string Json
{ {
get 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) public FeedRow(Aggregator.Feed feed)
{ {
Users = new List<Guid>(); Users = new List<Guid>();