Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VCST-919: Add drafts and recipients tracking #4

Merged
merged 9 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Threading.Tasks;
using System.Collections.Generic;

namespace VirtoCommerce.PushMessages.Core.BackgroundJobs;

public interface IPushMessageJobService
public interface IPushMessageJobService : IRecurringJobService
{
Task StartStopRecurringJobs();
void EnqueueAddRecipients(IList<string> messageIds = null);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.Platform.Core.Settings.Events;

namespace VirtoCommerce.PushMessages.Core.BackgroundJobs;

public interface IRecurringJobService : IEventHandler<ObjectSettingChangedEvent>
{
Task StartStopRecurringJobs();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading.Tasks;
using VirtoCommerce.Platform.Core.Settings;

namespace VirtoCommerce.PushMessages.Core.BackgroundJobs;

public class RecurringJobDescriptor<T>
{
public SettingDescriptor EnableSetting { get; set; }
public SettingDescriptor CronSetting { get; set; }
public MethodInfo Method { get; set; }
public Expression<Func<T, Task>> MethodCall { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using VirtoCommerce.Platform.Core.Events;
using VirtoCommerce.Platform.Core.Settings.Events;
using VirtoCommerce.PushMessages.Core.BackgroundJobs;

namespace VirtoCommerce.PushMessages.Core.Extensions;

public static class ApplicationBuilderExtensions
{
public static void UseRecurringJobService<T>(this IApplicationBuilder appBuilder)
where T : class, IRecurringJobService
{
appBuilder.RegisterEventHandler<ObjectSettingChangedEvent, T>();

var pushMessageJobService = appBuilder.ApplicationServices.GetService<T>();
pushMessageJobService.StartStopRecurringJobs().GetAwaiter().GetResult();
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using VirtoCommerce.PushMessages.Core.BackgroundJobs;

namespace VirtoCommerce.PushMessages.Core.Extensions;

public static class ServiceCollectionExtensions
{
public static void AddRecurringJobService<TService, TImplementation>(this IServiceCollection serviceCollection)
where TService : class, IRecurringJobService
where TImplementation : class, TService
{
serviceCollection.AddSingleton<TImplementation>();
serviceCollection.AddSingleton<TService, TImplementation>();
}
}
17 changes: 11 additions & 6 deletions src/VirtoCommerce.PushMessages.Core/Models/PushMessage.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using VirtoCommerce.Platform.Core.Common;

namespace VirtoCommerce.PushMessages.Core.Models;
Expand All @@ -13,15 +12,21 @@ public class PushMessage : AuditableEntity, ICloneable

public DateTime? StartDate { get; set; }

public string Status { get; set; }
public string Status { get; set; } = PushMessageStatus.Draft;

public IList<string> MemberIds { get; set; }
public bool TrackNewRecipients { get; set; }

public string MemberQuery { get; set; }

[JsonIgnore]
public IList<string> UserIds { get; set; }
public IList<string> MemberIds { get; set; }

public object Clone()
public virtual object Clone()
{
return MemberwiseClone();
}

public virtual bool HasRecipients()
{
return MemberIds != null && MemberIds.Count > 0 || !string.IsNullOrEmpty(MemberQuery);
}
}
10 changes: 0 additions & 10 deletions src/VirtoCommerce.PushMessages.Core/Models/PushMessageMember.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ namespace VirtoCommerce.PushMessages.Core.Models;

public class PushMessageSearchCriteria : SearchCriteriaBase
{
public bool? IsDraft { get; set; }
public bool? TrackNewRecipients { get; set; }
public DateTime? CreatedDateBefore { get; set; }
public DateTime? StartDateBefore { get; set; }
public IList<string> Statuses { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ namespace VirtoCommerce.PushMessages.Core.Models;

public static class PushMessageStatus
{
public const string Draft = "Draft";
public const string Scheduled = "Scheduled";
public const string Sent = "Sent";
}
30 changes: 24 additions & 6 deletions src/VirtoCommerce.PushMessages.Core/ModuleConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,46 @@ public static IEnumerable<SettingDescriptor> AllGeneralSettings

public static class BackgroundJobs
{
public static SettingDescriptor Enable { get; } = new()
public static SettingDescriptor SendScheduledMessagesRecurringJobEnable { get; } = new()
{
Name = "PushMessages.BackgroundJobs.Enable",
Name = "PushMessages.SendScheduledMessagesRecurringJob.Enable",
GroupName = "Push Messages|Background Jobs",
ValueType = SettingValueType.Boolean,
DefaultValue = true,
};

public static SettingDescriptor CronExpression { get; } = new()
public static SettingDescriptor SendScheduledMessagesRecurringJobCronExpression { get; } = new()
{
Name = "PushMessages.BackgroundJobs.CronExpression",
Name = "PushMessages.SendScheduledMessagesRecurringJob.CronExpression",
GroupName = "Push Messages|Background Jobs",
ValueType = SettingValueType.ShortText,
DefaultValue = "0/5 * * * *",
};

public static SettingDescriptor TrackNewRecipientsRecurringJobEnable { get; } = new()
{
Name = "PushMessages.TrackNewRecipientsRecurringJob.Enable",
GroupName = "Push Messages|Background Jobs",
ValueType = SettingValueType.Boolean,
DefaultValue = true,
};

public static SettingDescriptor TrackNewRecipientsRecurringJobCronExpression { get; } = new()
{
Name = "PushMessages.TrackNewRecipientsRecurringJob.CronExpression",
GroupName = "Push Messages|Background Jobs",
ValueType = SettingValueType.ShortText,
DefaultValue = "0 0/1 * * *",
};

public static IEnumerable<SettingDescriptor> AllBackgroundJobsSettings
{
get
{
yield return Enable;
yield return CronExpression;
yield return SendScheduledMessagesRecurringJobEnable;
yield return SendScheduledMessagesRecurringJobCronExpression;
yield return TrackNewRecipientsRecurringJobEnable;
yield return TrackNewRecipientsRecurringJobCronExpression;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System.Threading.Tasks;
using VirtoCommerce.Platform.Core.GenericCrud;
using VirtoCommerce.PushMessages.Core.Models;

namespace VirtoCommerce.PushMessages.Core.Services;

public interface IPushMessageService : ICrudService<PushMessage>
{
Task<PushMessage> ChangeTracking(string messageId, bool value);
}
Loading
Loading