From 17675a11ce8a8fa10351f6d0283241eaa025721e Mon Sep 17 00:00:00 2001 From: Chris Hubbard Date: Mon, 27 Nov 2023 11:33:04 -0500 Subject: [PATCH] Add ProductUserChanges --- .../BackendServicesExtension.cs | 3 + .../ProductUserChangeController.cs | 29 + .../Data/AppDbContext.cs | 8 + .../Forms/ProductUserChangeForm.cs | 40 + ...27163406_AddProductUserChanges.Designer.cs | 1228 +++++++++++++++++ .../20231127163406_AddProductUserChanges.cs | 47 + .../Migrations/AppDbContextModelSnapshot.cs | 32 + .../Models/ProductUserChange.cs | 27 + .../ProductUserChangeRepository.cs | 37 + .../IProcessProductUserChangeService.cs | 14 + .../ProcessProductUserChangeService.cs | 61 + .../Services/ProductUserChangeService.cs | 52 + 12 files changed, 1578 insertions(+) create mode 100644 source/OptimaJet.DWKit.StarterApplication/Controllers/ProductUserChangeController.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Forms/ProductUserChangeForm.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.Designer.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Models/ProductUserChange.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Repositories/ProductUserChangeRepository.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Services/Contracts/IProcessProductUserChangeService.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Services/ProcessProductUserChangeService.cs create mode 100644 source/OptimaJet.DWKit.StarterApplication/Services/ProductUserChangeService.cs diff --git a/source/OptimaJet.DWKit.StarterApplication/BackendServicesExtension.cs b/source/OptimaJet.DWKit.StarterApplication/BackendServicesExtension.cs index 233607ccfa..f7216530eb 100644 --- a/source/OptimaJet.DWKit.StarterApplication/BackendServicesExtension.cs +++ b/source/OptimaJet.DWKit.StarterApplication/BackendServicesExtension.cs @@ -53,6 +53,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services }); }); + services.AddHttpContextAccessor(); // Add service / repository overrides @@ -66,6 +67,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services services.AddScoped, ProductRepository>(); services.AddScoped, OrganizationStoreRepository>(); services.AddScoped, ProjectImportRepository>(); + services.AddScoped, ProductUserChangeRepository>(); // for operations services.AddScoped, ProjectService>(); @@ -86,6 +88,7 @@ public static IServiceCollection AddApiServices(this IServiceCollection services services.AddScoped, ProjectService>(); services.AddScoped, ProjectImportService>(); services.AddScoped, ProductService>(); + services.AddScoped, ProductUserChangeService>(); services.AddScoped, GroupMembershipService>(); services.AddScoped, OrganizationMembershipService>(); services.AddScoped, OrganizationMembershipInviteService>(); diff --git a/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductUserChangeController.cs b/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductUserChangeController.cs new file mode 100644 index 0000000000..930000e550 --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Controllers/ProductUserChangeController.cs @@ -0,0 +1,29 @@ + +using System.Threading.Tasks; +using JsonApiDotNetCore.Services; +using Microsoft.AspNetCore.Mvc; +using OptimaJet.DWKit.StarterApplication.Models; +using OptimaJet.DWKit.StarterApplication.Services; + +namespace OptimaJet.DWKit.StarterApplication.Controllers +{ + public class ProductUserChangeController : BaseController + { + public ProductUserChangeController( + IJsonApiContext jsonApiContext, + IResourceService resourceService, + ICurrentUserContext currentUserContext, + OrganizationService organizationService, + UserService userService) + : base(jsonApiContext, resourceService, currentUserContext, organizationService, userService) + + { + } + + public override Task PostAsync([FromBody] ProductUserChange entity) + { + + return base.PostAsync(entity); + } + } +} diff --git a/source/OptimaJet.DWKit.StarterApplication/Data/AppDbContext.cs b/source/OptimaJet.DWKit.StarterApplication/Data/AppDbContext.cs index 86b2b6d450..b47c01f7dd 100644 --- a/source/OptimaJet.DWKit.StarterApplication/Data/AppDbContext.cs +++ b/source/OptimaJet.DWKit.StarterApplication/Data/AppDbContext.cs @@ -40,6 +40,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) var workflowSchemeEntity = modelBuilder.Entity(); var projectImportEntity = modelBuilder.Entity(); var productPublicationEntity = modelBuilder.Entity(); + var productUserChangeEntity = modelBuilder.Entity(); userEntity .HasMany(u => u.OrganizationMemberships) @@ -243,6 +244,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) productPublicationEntity .HasIndex(p => p.Package); + productUserChangeEntity + .HasOne(p => p.Product) + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.SetNull); + productWorkflowSchemeEntity.ToTable("WorkflowProcessScheme"); @@ -308,6 +315,7 @@ public override int SaveChanges() public DbSet ProductTransitions { get; set; } public DbSet ProductBuilds { get; set; } public DbSet ProductPublications { get; set; } + public DbSet ProductUserChanges { get; set; } public DbSet ProjectImports { get; set; } public DbSet Authors { get; set; } } diff --git a/source/OptimaJet.DWKit.StarterApplication/Forms/ProductUserChangeForm.cs b/source/OptimaJet.DWKit.StarterApplication/Forms/ProductUserChangeForm.cs new file mode 100644 index 0000000000..f8bb0581dd --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Forms/ProductUserChangeForm.cs @@ -0,0 +1,40 @@ +using System; +using System.Linq; +using JsonApiDotNetCore.Data; +using Microsoft.EntityFrameworkCore; +using OptimaJet.DWKit.StarterApplication.Models; +using OptimaJet.DWKit.StarterApplication.Repositories; +using OptimaJet.DWKit.StarterApplication.Services; +namespace OptimaJet.DWKit.StarterApplication.Forms +{ + public class ProductUserChangeForm : BaseForm + { + public IEntityRepository ProductRepository { get; } + public ProductUserChangeForm( + UserRepository userRepository, + IEntityRepository userRolesRepository, + ICurrentUserContext currentUserContext, + IEntityRepository productRepository) + : base(userRepository, userRolesRepository, currentUserContext) + { + ProductRepository = productRepository; + } + + public bool IsValid(ProductUserChange productUserChange) + { + if (productUserChange.ProductId != null) + { + var product = ProductRepository.Get() + .Where(p => p.Id.Equals(productUserChange.ProductId)) + .FirstOrDefaultAsync().Result; + if (product == null) + { + var message = $"Product {productUserChange.ProductId} not found"; + AddError(message); + } + } + + return base.IsValid(); + } + } +} diff --git a/source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.Designer.cs b/source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.Designer.cs new file mode 100644 index 0000000000..b6c032d8ee --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.Designer.cs @@ -0,0 +1,1228 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using OptimaJet.DWKit.StarterApplication.Data; +using OptimaJet.DWKit.StarterApplication.Models; + +namespace OptimaJet.DWKit.StarterApplication.Migrations +{ + [DbContext(typeof(AppDbContext))] + [Migration("20231127163406_AddProductUserChanges")] + partial class AddProductUserChanges + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:PostgresExtension:uuid-ossp", "'uuid-ossp', '', ''") + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) + .HasAnnotation("ProductVersion", "2.1.0-rtm-30799") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ApplicationType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("ApplicationTypes"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Author", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CanUpdate"); + + b.Property("ProjectId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.HasIndex("UserId"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Email", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Bcc"); + + b.Property("Cc"); + + b.Property("ContentModelJson"); + + b.Property("ContentTemplate"); + + b.Property("Created") + .ValueGeneratedOnAdd(); + + b.Property("Subject"); + + b.Property("To"); + + b.HasKey("Id"); + + b.ToTable("Emails"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Group", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Abbreviation"); + + b.Property("Name"); + + b.Property("OwnerId"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Groups"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.GroupMembership", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("GroupId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("UserId"); + + b.ToTable("GroupMemberships"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Notification", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated"); + + b.Property("DateEmailSent"); + + b.Property("DateRead"); + + b.Property("DateUpdated"); + + b.Property("LinkUrl"); + + b.Property("Message"); + + b.Property("MessageId"); + + b.Property("MessageSubstitutionsJson"); + + b.Property("SendEmail"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("UserId"); + + b.ToTable("Notifications"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Organization", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BuildEngineApiAccessToken"); + + b.Property("BuildEngineUrl"); + + b.Property("LogoUrl"); + + b.Property("Name"); + + b.Property("OwnerId"); + + b.Property("PublicByDefault") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("UseDefaultBuildEngine") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("WebsiteUrl"); + + b.HasKey("Id"); + + b.HasIndex("OwnerId"); + + b.ToTable("Organizations"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationInvite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Name"); + + b.Property("OwnerEmail"); + + b.Property("Token"); + + b.HasKey("Id"); + + b.ToTable("OrganizationInvites"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationInviteRequest", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("Name"); + + b.Property("OrgAdminEmail"); + + b.Property("WebsiteUrl"); + + b.HasKey("Id"); + + b.ToTable("OrganizationInviteRequests"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationMembership", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("OrganizationId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("UserId"); + + b.ToTable("OrganizationMemberships"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationMembershipInvite", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("Email") + .IsRequired(); + + b.Property("Expires") + .ValueGeneratedOnAdd() + .HasDefaultValueSql("current_date + 7"); + + b.Property("InvitedById"); + + b.Property("OrganizationId"); + + b.Property("Redeemed") + .ValueGeneratedOnAdd() + .HasDefaultValue(false); + + b.Property("Token") + .IsRequired() + .ValueGeneratedOnAdd() + .HasDefaultValueSql("uuid_generate_v4()"); + + b.HasKey("Id"); + + b.HasIndex("InvitedById"); + + b.HasIndex("OrganizationId"); + + b.ToTable("OrganizationMembershipInvites"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationProductDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("OrganizationId"); + + b.Property("ProductDefinitionId"); + + b.HasKey("Id"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("ProductDefinitionId"); + + b.ToTable("OrganizationProductDefinitions"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationStore", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("OrganizationId"); + + b.Property("StoreId"); + + b.HasKey("Id"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("StoreId"); + + b.ToTable("OrganizationStores"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Product", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasDefaultValueSql("uuid_generate_v4()"); + + b.Property("DateBuilt"); + + b.Property("DateCreated"); + + b.Property("DatePublished"); + + b.Property("DateUpdated"); + + b.Property("ProductDefinitionId"); + + b.Property("ProjectId"); + + b.Property("Properties"); + + b.Property("PublishLink"); + + b.Property("StoreId"); + + b.Property("StoreLanguageId"); + + b.Property("VersionBuilt"); + + b.Property("WorkflowBuildId"); + + b.Property("WorkflowComment"); + + b.Property("WorkflowJobId"); + + b.Property("WorkflowPublishId"); + + b.HasKey("Id"); + + b.HasIndex("ProductDefinitionId"); + + b.HasIndex("ProjectId"); + + b.HasIndex("StoreId"); + + b.HasIndex("StoreLanguageId"); + + b.ToTable("Products"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductArtifact", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArtifactType"); + + b.Property("ContentType"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("FileSize"); + + b.Property("ProductBuildId"); + + b.Property("ProductId"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.HasIndex("ProductBuildId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductArtifacts"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductBuild", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BuildId"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("ProductId"); + + b.Property("Success"); + + b.Property("Version"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductBuilds"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("Properties"); + + b.Property("RebuildWorkflowId"); + + b.Property("RepublishWorkflowId"); + + b.Property("TypeId"); + + b.Property("WorkflowId"); + + b.HasKey("Id"); + + b.HasIndex("RebuildWorkflowId"); + + b.HasIndex("RepublishWorkflowId"); + + b.HasIndex("TypeId"); + + b.HasIndex("WorkflowId"); + + b.ToTable("ProductDefinitions"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductPublication", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Channel"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("LogUrl"); + + b.Property("Package"); + + b.Property("ProductBuildId"); + + b.Property("ProductId"); + + b.Property("ReleaseId"); + + b.Property("Success"); + + b.HasKey("Id"); + + b.HasIndex("Package"); + + b.HasIndex("ProductBuildId"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductPublications"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductTransition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AllowedUserNames"); + + b.Property("Command"); + + b.Property("Comment"); + + b.Property("DateTransition"); + + b.Property("DestinationState"); + + b.Property("InitialState"); + + b.Property("ProductId"); + + b.Property("TransitionType") + .ValueGeneratedOnAdd() + .HasDefaultValue(1); + + b.Property("WorkflowType"); + + b.Property("WorkflowUserId"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductTransitions"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductUserChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Change"); + + b.Property("DateCompleted"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("Email"); + + b.Property("ProductId"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductUserChanges"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflow", b => + { + b.Property("Id"); + + b.Property("ActivityName"); + + b.Property("SchemeId"); + + b.Property("StateName"); + + b.HasKey("Id"); + + b.HasIndex("SchemeId"); + + b.ToTable("WorkflowProcessInstance"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflowScheme", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("IsObsolete"); + + b.Property("Scheme"); + + b.Property("SchemeCode"); + + b.HasKey("Id"); + + b.ToTable("WorkflowProcessScheme"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Project", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AllowDownloads") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("AutomaticBuilds") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("DateActive"); + + b.Property("DateArchived"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("Description"); + + b.Property("GroupId"); + + b.Property("ImportId"); + + b.Property("IsPublic") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("Language"); + + b.Property("Name"); + + b.Property("OrganizationId"); + + b.Property("OwnerId"); + + b.Property("TypeId"); + + b.Property("WorkflowAppProjectUrl"); + + b.Property("WorkflowProjectId") + .ValueGeneratedOnAdd() + .HasDefaultValue(0); + + b.Property("WorkflowProjectUrl"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("ImportId"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("OwnerId"); + + b.HasIndex("TypeId"); + + b.ToTable("Projects"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProjectImport", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("GroupId"); + + b.Property("ImportData"); + + b.Property("OrganizationId"); + + b.Property("OwnerId"); + + b.Property("TypeId"); + + b.HasKey("Id"); + + b.HasIndex("GroupId"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("OwnerId"); + + b.HasIndex("TypeId"); + + b.ToTable("ProjectImports"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Reviewer", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Email"); + + b.Property("Locale"); + + b.Property("Name"); + + b.Property("ProjectId"); + + b.HasKey("Id"); + + b.HasIndex("ProjectId"); + + b.ToTable("Reviewers"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Role", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("RoleName"); + + b.HasKey("Id"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Store", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("StoreTypeId"); + + b.HasKey("Id"); + + b.HasIndex("StoreTypeId"); + + b.ToTable("Stores"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.StoreLanguage", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.Property("StoreTypeId"); + + b.HasKey("Id"); + + b.HasIndex("StoreTypeId"); + + b.ToTable("StoreLanguages"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.StoreType", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Name"); + + b.HasKey("Id"); + + b.ToTable("StoreTypes"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.SystemStatus", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BuildEngineApiAccessToken"); + + b.Property("BuildEngineUrl"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("SystemAvailable"); + + b.HasKey("Id"); + + b.ToTable("SystemStatuses"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("Email"); + + b.Property("EmailNotification") + .ValueGeneratedOnAdd() + .HasDefaultValue(true); + + b.Property("ExternalId"); + + b.Property("FamilyName"); + + b.Property("GivenName"); + + b.Property("IsLocked"); + + b.Property("Locale"); + + b.Property("Name"); + + b.Property("Phone"); + + b.Property("ProfileVisibility") + .ValueGeneratedOnAdd() + .HasDefaultValue(1); + + b.Property("Timezone"); + + b.Property("WorkflowUserId"); + + b.HasKey("Id"); + + b.HasIndex("WorkflowUserId"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.UserRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("OrganizationId"); + + b.Property("RoleId"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("OrganizationId"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId"); + + b.ToTable("UserRoles"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.UserTask", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ActivityName"); + + b.Property("Comment"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("ProductId"); + + b.Property("Status"); + + b.Property("UserId"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.HasIndex("UserId"); + + b.ToTable("UserTasks"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.WorkflowDefinition", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Description"); + + b.Property("Enabled"); + + b.Property("Name"); + + b.Property("Properties"); + + b.Property("StoreTypeId"); + + b.Property("Type") + .ValueGeneratedOnAdd() + .HasDefaultValue(1); + + b.Property("WorkflowBusinessFlow"); + + b.Property("WorkflowScheme"); + + b.HasKey("Id"); + + b.HasIndex("StoreTypeId"); + + b.ToTable("WorkflowDefinitions"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.WorkflowScheme", b => + { + b.Property("Code") + .ValueGeneratedOnAdd(); + + b.Property("Scheme"); + + b.HasKey("Code"); + + b.ToTable("WorkflowScheme"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Author", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Project", "Project") + .WithMany("Authors") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Group", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Owner") + .WithMany("Groups") + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.GroupMembership", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "User") + .WithMany("GroupMemberships") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Notification", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "User") + .WithMany("Notifications") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Organization", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationMembership", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany("OrganizationMemberships") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "User") + .WithMany("OrganizationMemberships") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationMembershipInvite", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "InvitedBy") + .WithMany() + .HasForeignKey("InvitedById") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany() + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationProductDefinition", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany("OrganizationProductDefinitions") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ProductDefinition", "ProductDefinition") + .WithMany() + .HasForeignKey("ProductDefinitionId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.OrganizationStore", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany("OrganizationStores") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Store", "Store") + .WithMany("OrganizationStores") + .HasForeignKey("StoreId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Product", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ProductDefinition", "ProductDefinition") + .WithMany() + .HasForeignKey("ProductDefinitionId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Project", "Project") + .WithMany("Products") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Store", "Store") + .WithMany() + .HasForeignKey("StoreId"); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.StoreLanguage", "StoreLanguage") + .WithMany() + .HasForeignKey("StoreLanguageId"); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductArtifact", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ProductBuild", "ProductBuild") + .WithMany("ProductArtifacts") + .HasForeignKey("ProductBuildId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductBuild", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany("ProductBuilds") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductDefinition", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.WorkflowDefinition", "RebuildWorkflow") + .WithMany() + .HasForeignKey("RebuildWorkflowId"); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.WorkflowDefinition", "RepublishWorkflow") + .WithMany() + .HasForeignKey("RepublishWorkflowId"); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ApplicationType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.WorkflowDefinition", "Workflow") + .WithMany() + .HasForeignKey("WorkflowId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductPublication", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ProductBuild", "ProductBuild") + .WithMany("ProductPublications") + .HasForeignKey("ProductBuildId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany("ProductPublications") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductTransition", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany("Transitions") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductUserChange", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflow", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithOne("ProductWorkflow") + .HasForeignKey("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflow", "Id") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflowScheme", "Scheme") + .WithMany() + .HasForeignKey("SchemeId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Project", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ProjectImport", "Import") + .WithMany() + .HasForeignKey("ImportId"); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany() + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.Restrict); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ApplicationType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.Restrict); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProjectImport", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Group", "Group") + .WithMany() + .HasForeignKey("GroupId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany() + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "Owner") + .WithMany() + .HasForeignKey("OwnerId") + .OnDelete(DeleteBehavior.SetNull); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.ApplicationType", "Type") + .WithMany() + .HasForeignKey("TypeId") + .OnDelete(DeleteBehavior.SetNull); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Reviewer", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Project", "Project") + .WithMany("Reviewers") + .HasForeignKey("ProjectId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.Store", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.StoreType", "StoreType") + .WithMany() + .HasForeignKey("StoreTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.StoreLanguage", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.StoreType", "StoreType") + .WithMany("Languages") + .HasForeignKey("StoreTypeId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.UserRole", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Organization", "Organization") + .WithMany("UserRoles") + .HasForeignKey("OrganizationId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.UserTask", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany("UserTasks") + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.Cascade); + + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.User", "User") + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.WorkflowDefinition", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.StoreType", "StoreType") + .WithMany() + .HasForeignKey("StoreTypeId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.cs b/source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.cs new file mode 100644 index 0000000000..fe7359c2bc --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Migrations/20231127163406_AddProductUserChanges.cs @@ -0,0 +1,47 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +namespace OptimaJet.DWKit.StarterApplication.Migrations +{ + public partial class AddProductUserChanges : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "ProductUserChanges", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), + ProductId = table.Column(nullable: false), + Email = table.Column(nullable: true), + Change = table.Column(nullable: true), + DateCreated = table.Column(nullable: true), + DateUpdated = table.Column(nullable: true), + DateCompleted = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_ProductUserChanges", x => x.Id); + table.ForeignKey( + name: "FK_ProductUserChanges_Products_ProductId", + column: x => x.ProductId, + principalTable: "Products", + principalColumn: "Id", + onDelete: ReferentialAction.SetNull); + }); + + migrationBuilder.CreateIndex( + name: "IX_ProductUserChanges_ProductId", + table: "ProductUserChanges", + column: "ProductId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "ProductUserChanges"); + } + } +} diff --git a/source/OptimaJet.DWKit.StarterApplication/Migrations/AppDbContextModelSnapshot.cs b/source/OptimaJet.DWKit.StarterApplication/Migrations/AppDbContextModelSnapshot.cs index 3ae61312d8..0bffb69558 100644 --- a/source/OptimaJet.DWKit.StarterApplication/Migrations/AppDbContextModelSnapshot.cs +++ b/source/OptimaJet.DWKit.StarterApplication/Migrations/AppDbContextModelSnapshot.cs @@ -511,6 +511,30 @@ protected override void BuildModel(ModelBuilder modelBuilder) b.ToTable("ProductTransitions"); }); + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductUserChange", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("Change"); + + b.Property("DateCompleted"); + + b.Property("DateCreated"); + + b.Property("DateUpdated"); + + b.Property("Email"); + + b.Property("ProductId"); + + b.HasKey("Id"); + + b.HasIndex("ProductId"); + + b.ToTable("ProductUserChanges"); + }); + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflow", b => { b.Property("Id"); @@ -1064,6 +1088,14 @@ protected override void BuildModel(ModelBuilder modelBuilder) .OnDelete(DeleteBehavior.Cascade); }); + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductUserChange", b => + { + b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") + .WithMany() + .HasForeignKey("ProductId") + .OnDelete(DeleteBehavior.SetNull); + }); + modelBuilder.Entity("OptimaJet.DWKit.StarterApplication.Models.ProductWorkflow", b => { b.HasOne("OptimaJet.DWKit.StarterApplication.Models.Product", "Product") diff --git a/source/OptimaJet.DWKit.StarterApplication/Models/ProductUserChange.cs b/source/OptimaJet.DWKit.StarterApplication/Models/ProductUserChange.cs new file mode 100644 index 0000000000..6ae443f178 --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Models/ProductUserChange.cs @@ -0,0 +1,27 @@ +using System; +using JsonApiDotNetCore.Models; + +namespace OptimaJet.DWKit.StarterApplication.Models +{ + public class ProductUserChange : Identifiable, ITrackDate + { + [HasOne("product")] + public virtual Product Product { get; set; } + public Guid ProductId { get; set; } + + [Attr("email")] + public string Email { get; set; } + + [Attr("change")] + public string Change { get; set; } + + [Attr("date-created")] + public DateTime? DateCreated { get; set; } + + [Attr("date-updated")] + public DateTime? DateUpdated { get; set; } + + [Attr("date-completed")] + public DateTime? DateCompleted { get; set; } + } +} diff --git a/source/OptimaJet.DWKit.StarterApplication/Repositories/ProductUserChangeRepository.cs b/source/OptimaJet.DWKit.StarterApplication/Repositories/ProductUserChangeRepository.cs new file mode 100644 index 0000000000..15074ddd26 --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Repositories/ProductUserChangeRepository.cs @@ -0,0 +1,37 @@ +using System; +using System.Threading.Tasks; +using Hangfire; +using JsonApiDotNetCore.Data; +using JsonApiDotNetCore.Services; +using Microsoft.Extensions.Logging; +using OptimaJet.DWKit.StarterApplication.Models; +using OptimaJet.DWKit.StarterApplication.Services; +using OptimaJet.DWKit.StarterApplication.Services.Contracts; + +namespace OptimaJet.DWKit.StarterApplication.Repositories +{ + public class ProductUserChangeRepository : BaseRepository + { + public IBackgroundJobClient BackgroundJobClient { get; } + public ProductUserChangeRepository( + ILoggerFactory loggerFactory, + IJsonApiContext jsonApiContext, + IDbContextResolver contextResolver, + CurrentUserRepository currentUserRepository, + EntityHooksService statusUpdateService, + IBackgroundJobClient backgroundJobClient + ) : base(loggerFactory, jsonApiContext, currentUserRepository, statusUpdateService, contextResolver) + { + BackgroundJobClient = backgroundJobClient; + } + + public override async Task CreateAsync(ProductUserChange entity) + { + var result = await base.CreateAsync(entity); + var data = new ProcessProductUserChangeData { Id = result.Id }; + BackgroundJobClient.Enqueue(service => service.Process(data)); + return result; + } + } +} + diff --git a/source/OptimaJet.DWKit.StarterApplication/Services/Contracts/IProcessProductUserChangeService.cs b/source/OptimaJet.DWKit.StarterApplication/Services/Contracts/IProcessProductUserChangeService.cs new file mode 100644 index 0000000000..95359d316a --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Services/Contracts/IProcessProductUserChangeService.cs @@ -0,0 +1,14 @@ +using System; +namespace OptimaJet.DWKit.StarterApplication.Services.Contracts +{ + public interface IProcessProductUserChangeService + { + void Process(ProcessProductUserChangeData data); + } + + public class ProcessProductUserChangeData + { + public int Id { get; set; } + } +} + diff --git a/source/OptimaJet.DWKit.StarterApplication/Services/ProcessProductUserChangeService.cs b/source/OptimaJet.DWKit.StarterApplication/Services/ProcessProductUserChangeService.cs new file mode 100644 index 0000000000..d712f967f4 --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Services/ProcessProductUserChangeService.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Bugsnag; +using Hangfire; +using I18Next.Net.Plugins; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using OptimaJet.DWKit.StarterApplication.Models; +using OptimaJet.DWKit.StarterApplication.Repositories; +using OptimaJet.DWKit.StarterApplication.Services.BuildEngine; +using OptimaJet.DWKit.StarterApplication.Services.Contracts; +using OptimaJet.DWKit.StarterApplication.Services.Workflow; +using OptimaJet.DWKit.StarterApplication.Utility; +using Serilog; + + +namespace OptimaJet.DWKit.StarterApplication.Services +{ + public class ProcessProductUserChangeService : IProcessProductUserChangeService + { + public IJobRepository ProductUserChangeRepository { get; } + public IClient BugsnagClient { get; } + + public ProcessProductUserChangeService( + IJobRepository productUserChangeRepository, + IClient bugsnagClient + ) + { + ProductUserChangeRepository = productUserChangeRepository; + BugsnagClient = bugsnagClient; + } + + + public void Process(ProcessProductUserChangeData data) + { + ProcessProductUserChange(data.Id).Wait(); + } + + public async Task ProcessProductUserChange(int Id) + { + var productUserChange = await ProductUserChangeRepository.Get() + .Where(puc => puc.Id == Id) + .FirstOrDefaultAsync(); + if (productUserChange == null) + { + // Creating an Exception to report to BugSnag. Don't want to Retry. + var ex = new Exception($"ProductUserChange id={Id}: not found"); + Log.Error(ex, "ProductUserchange: id not found"); + BugsnagClient.Notify(ex); + return; + } + + //TODO: Start workflow + } + } +} + diff --git a/source/OptimaJet.DWKit.StarterApplication/Services/ProductUserChangeService.cs b/source/OptimaJet.DWKit.StarterApplication/Services/ProductUserChangeService.cs new file mode 100644 index 0000000000..d55b26656f --- /dev/null +++ b/source/OptimaJet.DWKit.StarterApplication/Services/ProductUserChangeService.cs @@ -0,0 +1,52 @@ +using System; +using System.Threading.Tasks; +using JsonApiDotNetCore.Data; +using JsonApiDotNetCore.Internal; +using JsonApiDotNetCore.Services; +using Microsoft.Extensions.Logging; +using OptimaJet.DWKit.StarterApplication.Forms; +using OptimaJet.DWKit.StarterApplication.Models; +using OptimaJet.DWKit.StarterApplication.Repositories; + +namespace OptimaJet.DWKit.StarterApplication.Services +{ + public class ProductUserChangeService : EntityResourceService + { + public IJsonApiContext JsonApiContext { get; } + public UserRepository UserRepository { get; } + public ICurrentUserContext CurrentUserContext { get; } + public IEntityRepository UserRolesRepository { get; } + public IEntityRepository ProductUserChangeRepository { get; } + public IEntityRepository ProductRepository { get; } + + public ProductUserChangeService( + IJsonApiContext jsonApiContext, + UserRepository userRepository, + ICurrentUserContext currentUserContext, + IEntityRepository userRolesRepository, + IEntityRepository productUserChangeRepository, + IEntityRepository productRepository, + ILoggerFactory loggerFactory) : base(jsonApiContext, productUserChangeRepository, loggerFactory) + { + JsonApiContext = jsonApiContext; + ProductUserChangeRepository = productUserChangeRepository; + ProductRepository = productRepository; + UserRolesRepository = userRolesRepository; + UserRepository = userRepository; + CurrentUserContext = currentUserContext; + } + + public override async Task CreateAsync(ProductUserChange resource) + { + var form = new ProductUserChangeForm(UserRepository, + UserRolesRepository, + CurrentUserContext, + ProductRepository); + if (!form.IsValid(resource)) + { + throw new JsonApiException(form.Errors); + } + return await base.CreateAsync(resource); + } + } +}