From 9b95bd9762f9e6e4c1420d66953ce71336e01312 Mon Sep 17 00:00:00 2001 From: Christian Arenas Date: Thu, 1 Jun 2017 20:15:21 +0200 Subject: [PATCH] Add marketing api --- docker-compose.override.yml | 20 ++-- docker-compose.prod.yml | 20 ++-- docker-compose.vs.debug.yml | 26 +++-- docker-compose.vs.release.yml | 10 +- .../Controllers/CampaignsController.cs | 68 +++++++++-- .../Marketing/Marketing.API/Dockerfile | 2 +- .../Infrastructure/MarketingContext.cs | 69 ++++++++++- .../Infrastructure/MarketingContextSeed.cs | 49 +++++++- .../Marketing.API/Marketing.API.csproj | 30 ++--- .../20170601175200_Initial.Designer.cs | 108 ++++++++++++++++++ .../Migrations/20170601175200_Initial.cs | 71 ++++++++++++ .../MarketingContextModelSnapshot.cs | 107 +++++++++++++++++ .../Marketing/Marketing.API/Model/Campaing.cs | 19 ++- .../Marketing/Marketing.API/Model/Location.cs | 9 ++ .../Marketing/Marketing.API/Model/Rule.cs | 29 +++++ .../Marketing/Marketing.API/Program.cs | 1 - .../Properties/launchSettings.json | 6 +- .../Marketing/Marketing.API/Startup.cs | 14 +-- .../appsettings.Development.json | 4 +- 19 files changed, 566 insertions(+), 96 deletions(-) create mode 100644 src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.Designer.cs create mode 100644 src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.cs create mode 100644 src/Services/Marketing/Marketing.API/Migrations/MarketingContextModelSnapshot.cs create mode 100644 src/Services/Marketing/Marketing.API/Model/Location.cs create mode 100644 src/Services/Marketing/Marketing.API/Model/Rule.cs diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 079c86768..1348a6e9b 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -49,6 +49,15 @@ services: ports: - "5102:80" + marketing.api: + environment: + - ASPNETCORE_ENVIRONMENT=Development + - ASPNETCORE_URLS=http://0.0.0.0:80 + - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word + - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. + ports: + - "5110:80" + webspa: environment: - ASPNETCORE_ENVIRONMENT=Development @@ -94,13 +103,4 @@ services: - mvc=http://webmvc/hc - spa=http://webspa/hc ports: - - "5107:80" - - marketing.api: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - ASPNETCORE_URLS=http://0.0.0.0:80 - - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word - - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - ports: - - "5110:80" \ No newline at end of file + - "5107:80" \ No newline at end of file diff --git a/docker-compose.prod.yml b/docker-compose.prod.yml index b1dc89754..b9c46b4c2 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.prod.yml @@ -54,6 +54,15 @@ services: ports: - "5102:80" + marketing.api: + environment: + - ASPNETCORE_ENVIRONMENT=Production + - ASPNETCORE_URLS=http://0.0.0.0:80 + - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word + - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. + ports: + - "5110:80" + webspa: environment: - ASPNETCORE_ENVIRONMENT=Production @@ -99,13 +108,4 @@ services: - spa=http://webspa/hc ports: - - "5107:80" - - marketing.api: - environment: - - ASPNETCORE_ENVIRONMENT=Production - - ASPNETCORE_URLS=http://0.0.0.0:80 - - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.MarketingDb;User Id=sa;Password=Pass@word - - identityUrl=http://identity.api #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - ports: - - "5110:80" \ No newline at end of file + - "5107:80" \ No newline at end of file diff --git a/docker-compose.vs.debug.yml b/docker-compose.vs.debug.yml index ef2ff662b..85195a493 100644 --- a/docker-compose.vs.debug.yml +++ b/docker-compose.vs.debug.yml @@ -61,62 +61,64 @@ services: labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - webspa: - image: eshop/webspa:dev + marketing.api: + image: eshop/marketing.api:dev build: args: source: ${DOCKER_BUILD_SOURCE} environment: - DOTNET_USE_POLLING_FILE_WATCHER=1 volumes: - - ./src/Web/WebSPA:/app + - ./src/Services/Marketing/Marketing.API:/app - ~/.nuget/packages:/root/.nuget/packages:ro - ~/clrdbg:/clrdbg:ro entrypoint: tail -f /dev/null labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - webmvc: - image: eshop/webmvc:dev + + webspa: + image: eshop/webspa:dev build: args: source: ${DOCKER_BUILD_SOURCE} environment: - DOTNET_USE_POLLING_FILE_WATCHER=1 volumes: - - ./src/Web/WebMVC:/app + - ./src/Web/WebSPA:/app - ~/.nuget/packages:/root/.nuget/packages:ro - ~/clrdbg:/clrdbg:ro entrypoint: tail -f /dev/null labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - webstatus: - image: eshop/webstatus:dev + webmvc: + image: eshop/webmvc:dev build: args: source: ${DOCKER_BUILD_SOURCE} environment: - DOTNET_USE_POLLING_FILE_WATCHER=1 volumes: - - ./src/Web/WebStatus:/app + - ./src/Web/WebMVC:/app - ~/.nuget/packages:/root/.nuget/packages:ro - ~/clrdbg:/clrdbg:ro entrypoint: tail -f /dev/null labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - marketing.api: - image: eshop/marketing.api:dev + webstatus: + image: eshop/webstatus:dev build: args: source: ${DOCKER_BUILD_SOURCE} environment: - DOTNET_USE_POLLING_FILE_WATCHER=1 volumes: - - ./src/Marketing/Marketing.API:/app + - ./src/Web/WebStatus:/app - ~/.nuget/packages:/root/.nuget/packages:ro - ~/clrdbg:/clrdbg:ro entrypoint: tail -f /dev/null labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" + diff --git a/docker-compose.vs.release.yml b/docker-compose.vs.release.yml index 8be29c095..f01b21eff 100644 --- a/docker-compose.vs.release.yml +++ b/docker-compose.vs.release.yml @@ -41,7 +41,7 @@ services: labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - webspa: + marketing.api: build: args: source: ${DOCKER_BUILD_SOURCE} @@ -51,7 +51,7 @@ services: labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - webmvc: + webspa: build: args: source: ${DOCKER_BUILD_SOURCE} @@ -61,7 +61,7 @@ services: labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - webstatus: + webmvc: build: args: source: ${DOCKER_BUILD_SOURCE} @@ -71,7 +71,7 @@ services: labels: - "com.microsoft.visualstudio.targetoperatingsystem=linux" - marketing.api: + webstatus: build: args: source: ${DOCKER_BUILD_SOURCE} @@ -79,4 +79,4 @@ services: - ~/clrdbg:/clrdbg:ro entrypoint: tail -f /dev/null labels: - - "com.microsoft.visualstudio.targetoperatingsystem=linux" \ No newline at end of file + - "com.microsoft.visualstudio.targetoperatingsystem=linux" diff --git a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs index e5914b3ca..b029bfa51 100644 --- a/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs +++ b/src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs @@ -1,36 +1,86 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers { - using System.Collections.Generic; using Microsoft.AspNetCore.Mvc; + using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; + using System.Threading.Tasks; + using Microsoft.eShopOnContainers.Services.Marketing.API.Model; + using Microsoft.EntityFrameworkCore; [Route("api/[controller]")] public class CampaignsController : Controller { + private readonly MarketingContext _context; + + public CampaignsController(MarketingContext context) + { + _context = context; + } + [HttpGet] - public IEnumerable Get() + public async Task GetAllCampaigns() { - return new string[] { "value1", "value2" }; + var campaignList = await _context.Campaigns + .Include(c => c.Rules) + .ToListAsync(); + + return Ok(campaignList); } [HttpGet("{id:int}")] - public string Get(int id) + public async Task GetCampaignById(int id) { - return "value"; + var campaign = await _context.Campaigns + .Include(c => c.Rules) + .SingleAsync(c => c.Id == id); + + if (campaign is null) + { + return NotFound(); + } + + return Ok(campaign); } [HttpPost] - public void Post([FromBody]string value) + public async Task CreateCampaign([FromBody] Campaign campaign) { + await _context.Campaigns.AddAsync(campaign); + await _context.SaveChangesAsync(); + + return CreatedAtAction(nameof(GetCampaignById), new { id = campaign.Id }, null); } [HttpPut("{id:int}")] - public void Put(int id, [FromBody]string value) + public async Task UpdateCampaign(int id, [FromBody]Campaign campaign) { + var campaignToUpdate = await _context.Campaigns.FindAsync(id); + if (campaign is null) + { + return NotFound(); + } + + campaignToUpdate.Description = campaign.Description; + campaignToUpdate.From = campaign.From; + campaignToUpdate.To = campaign.To; + + await _context.SaveChangesAsync(); + + return CreatedAtAction(nameof(GetCampaignById), new { id = campaignToUpdate.Id }, null); } [HttpDelete("{id:int}")] - public void Delete(int id) + public async Task Delete(int id) { + var campaign = await _context.Campaigns.FindAsync(id); + if (campaign is null) + { + return NotFound(); + } + + _context.Campaigns.Remove(campaign); + await _context.SaveChangesAsync(); + + return NoContent(); } } -} +} \ No newline at end of file diff --git a/src/Services/Marketing/Marketing.API/Dockerfile b/src/Services/Marketing/Marketing.API/Dockerfile index ea0590a9f..54a79a5e4 100644 --- a/src/Services/Marketing/Marketing.API/Dockerfile +++ b/src/Services/Marketing/Marketing.API/Dockerfile @@ -1,4 +1,4 @@ -FROM microsoft/aspnetcore:1.1 +FROM microsoft/aspnetcore:1.1.2 ARG source WORKDIR /app EXPOSE 80 diff --git a/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs b/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs index dc3a80564..798d8d152 100644 --- a/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs +++ b/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs @@ -6,20 +6,77 @@ public class MarketingContext : DbContext { - public MarketingContext(DbContextOptions options) : base(options) - { + public MarketingContext(DbContextOptions options) : base(options) + { } - public DbSet Campaings { get; set; } + public DbSet Campaigns { get; set; } + + public DbSet Rules { get; set; } + public DbSet UserProfileRules { get; set; } + public DbSet PurchaseHistoryRules { get; set; } + public DbSet UserLocationRules { get; set; } protected override void OnModelCreating(ModelBuilder builder) { - builder.Entity(ConfigureCampaings); + builder.Entity(ConfigureCampaigns); + builder.Entity(ConfigureRules); + builder.Entity(ConfigureUserLocationRules); } - void ConfigureCampaings(EntityTypeBuilder builder) + void ConfigureCampaigns(EntityTypeBuilder builder) { + builder.ToTable("Campaign"); + + builder.HasKey(ci => ci.Id); + + builder.Property(ci => ci.Id) + .ForSqlServerUseSequenceHiLo("campaign_hilo") + .IsRequired(); + + builder.Property(m => m.Description) + .HasColumnName("Description") + .IsRequired(); + builder.Property(m => m.From) + .HasColumnName("From") + .IsRequired(); + + builder.Property(m => m.To) + .HasColumnName("To") + .IsRequired(); + + builder.Property(m => m.Description) + .HasColumnName("Description") + .IsRequired(); + + builder.HasMany(m => m.Rules) + .WithOne(r => r.Campaign) + .HasForeignKey(m => m.CampaignId) + .IsRequired(); + } + + void ConfigureRules(EntityTypeBuilder builder) + { + builder.ToTable("Rules"); + + builder.HasKey(r => r.Id); + + builder.HasDiscriminator("RuleTypeId") + .HasValue(1) + .HasValue(2) + .HasValue(3); + + builder.Property(r => r.Description) + .HasColumnName("Description") + .IsRequired(); + } + + void ConfigureUserLocationRules(EntityTypeBuilder builder) + { + builder.Property(r => r.LocationId) + .HasColumnName("LocationId") + .IsRequired(); } } -} +} \ No newline at end of file diff --git a/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs b/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs index 46d82e3be..9d2bb0157 100644 --- a/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs +++ b/src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs @@ -2,7 +2,11 @@ { using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; + using Microsoft.eShopOnContainers.Services.Marketing.API.Model; using Microsoft.Extensions.Logging; + using System; + using System.Collections.Generic; + using System.Linq; using System.Threading.Tasks; public class MarketingContextSeed @@ -14,7 +18,50 @@ context.Database.Migrate(); - //TODO: add model seeding + if (!context.Campaigns.Any()) + { + context.Campaigns.AddRange( + GetPreconfiguredMarketings()); + + await context.SaveChangesAsync(); + } + } + + static List GetPreconfiguredMarketings() + { + return new List + { + new Campaign + { + Description = "Campaign1", + From = DateTime.Now, + To = DateTime.Now.AddDays(7), + Url = "http://CampaignUrl.test/12f09ed3cef54187123f500ad", + Rules = new List + { + new UserLocationRule + { + Description = "UserLocationRule1", + LocationId = 1 + } + } + }, + new Campaign + { + Description = "Campaign2", + From = DateTime.Now.AddDays(7), + To = DateTime.Now.AddDays(14), + Url = "http://CampaignUrl.test/02a59eda65f241871239000ff", + Rules = new List + { + new UserLocationRule + { + Description = "UserLocationRule2", + LocationId = 1 + } + } + } + }; } } } diff --git a/src/Services/Marketing/Marketing.API/Marketing.API.csproj b/src/Services/Marketing/Marketing.API/Marketing.API.csproj index 1e6ec2416..f65be06bb 100644 --- a/src/Services/Marketing/Marketing.API/Marketing.API.csproj +++ b/src/Services/Marketing/Marketing.API/Marketing.API.csproj @@ -2,20 +2,20 @@ netcoreapp1.1 + 1.1.2 + Exe ..\..\..\..\docker-compose.dcproj Microsoft.eShopOnContainers.Services.Marketing.API portable-net45+win8 - aspnet-TestApp-ce941b30-19cf-4972-b34f-d03f2e7976ed + aspnet-Marketing.API-20161122013619 - - - + @@ -24,23 +24,14 @@ + + + + - - - - - - - - - - - - - - - + + @@ -52,5 +43,4 @@ - diff --git a/src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.Designer.cs b/src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.Designer.cs new file mode 100644 index 000000000..b0305f171 --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.Designer.cs @@ -0,0 +1,108 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; + +namespace Microsoft.eShopOnContainers.Services.Marketing.API.Migrations +{ + [DbContext(typeof(MarketingContext))] + [Migration("20170601175200_Initial")] + partial class Initial + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:Sequence:.campaign_hilo", "'campaign_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Campaign", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "campaign_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Description") + .IsRequired() + .HasColumnName("Description"); + + b.Property("From") + .HasColumnName("From"); + + b.Property("To") + .HasColumnName("To"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("Campaign"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CampaignId"); + + b.Property("Description") + .IsRequired() + .HasColumnName("Description"); + + b.Property("RuleTypeId"); + + b.HasKey("Id"); + + b.HasIndex("CampaignId"); + + b.ToTable("Rules"); + + b.HasDiscriminator("RuleTypeId"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.PurchaseHistoryRule", b => + { + b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule"); + + + b.ToTable("PurchaseHistoryRule"); + + b.HasDiscriminator().HasValue(2); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.UserLocationRule", b => + { + b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule"); + + b.Property("LocationId") + .HasColumnName("LocationId"); + + b.ToTable("UserLocationRule"); + + b.HasDiscriminator().HasValue(3); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.UserProfileRule", b => + { + b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule"); + + + b.ToTable("UserProfileRule"); + + b.HasDiscriminator().HasValue(1); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Campaign", "Campaign") + .WithMany("Rules") + .HasForeignKey("CampaignId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.cs b/src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.cs new file mode 100644 index 000000000..dee3aa12f --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Metadata; + +namespace Microsoft.eShopOnContainers.Services.Marketing.API.Migrations +{ + public partial class Initial : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateSequence( + name: "campaign_hilo", + incrementBy: 10); + + migrationBuilder.CreateTable( + name: "Campaign", + columns: table => new + { + Id = table.Column(nullable: false), + Description = table.Column(nullable: false), + From = table.Column(nullable: false), + To = table.Column(nullable: false), + Url = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Campaign", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Rules", + columns: table => new + { + Id = table.Column(nullable: false) + .Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn), + CampaignId = table.Column(nullable: false), + Description = table.Column(nullable: false), + RuleTypeId = table.Column(nullable: false), + LocationId = table.Column(nullable: true) + }, + constraints: table => + { + table.PrimaryKey("PK_Rules", x => x.Id); + table.ForeignKey( + name: "FK_Rules_Campaign_CampaignId", + column: x => x.CampaignId, + principalTable: "Campaign", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Rules_CampaignId", + table: "Rules", + column: "CampaignId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Rules"); + + migrationBuilder.DropTable( + name: "Campaign"); + + migrationBuilder.DropSequence( + name: "campaign_hilo"); + } + } +} diff --git a/src/Services/Marketing/Marketing.API/Migrations/MarketingContextModelSnapshot.cs b/src/Services/Marketing/Marketing.API/Migrations/MarketingContextModelSnapshot.cs new file mode 100644 index 000000000..3d954edcc --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Migrations/MarketingContextModelSnapshot.cs @@ -0,0 +1,107 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure; + +namespace Microsoft.eShopOnContainers.Services.Marketing.API.Migrations +{ + [DbContext(typeof(MarketingContext))] + partial class MarketingContextModelSnapshot : ModelSnapshot + { + protected override void BuildModel(ModelBuilder modelBuilder) + { + modelBuilder + .HasAnnotation("ProductVersion", "1.1.2") + .HasAnnotation("SqlServer:Sequence:.campaign_hilo", "'campaign_hilo', '', '1', '10', '', '', 'Int64', 'False'") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Campaign", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasAnnotation("SqlServer:HiLoSequenceName", "campaign_hilo") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo); + + b.Property("Description") + .IsRequired() + .HasColumnName("Description"); + + b.Property("From") + .HasColumnName("From"); + + b.Property("To") + .HasColumnName("To"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("Campaign"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("CampaignId"); + + b.Property("Description") + .IsRequired() + .HasColumnName("Description"); + + b.Property("RuleTypeId"); + + b.HasKey("Id"); + + b.HasIndex("CampaignId"); + + b.ToTable("Rules"); + + b.HasDiscriminator("RuleTypeId"); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.PurchaseHistoryRule", b => + { + b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule"); + + + b.ToTable("PurchaseHistoryRule"); + + b.HasDiscriminator().HasValue(2); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.UserLocationRule", b => + { + b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule"); + + b.Property("LocationId") + .HasColumnName("LocationId"); + + b.ToTable("UserLocationRule"); + + b.HasDiscriminator().HasValue(3); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.UserProfileRule", b => + { + b.HasBaseType("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule"); + + + b.ToTable("UserProfileRule"); + + b.HasDiscriminator().HasValue(1); + }); + + modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b => + { + b.HasOne("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Campaign", "Campaign") + .WithMany("Rules") + .HasForeignKey("CampaignId") + .OnDelete(DeleteBehavior.Cascade); + }); + } + } +} diff --git a/src/Services/Marketing/Marketing.API/Model/Campaing.cs b/src/Services/Marketing/Marketing.API/Model/Campaing.cs index 62dca8483..bbe794b1a 100644 --- a/src/Services/Marketing/Marketing.API/Model/Campaing.cs +++ b/src/Services/Marketing/Marketing.API/Model/Campaing.cs @@ -1,7 +1,20 @@ namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model { - public class Campaing + using System; + using System.Collections.Generic; + + public class Campaign { - //TODO: Add Campaing properties + public int Id { get; set; } + + public string Description { get; set; } + + public DateTime From { get; set; } + + public DateTime To { get; set; } + + public string Url { get; set; } + + public ICollection Rules { get; set; } } -} +} \ No newline at end of file diff --git a/src/Services/Marketing/Marketing.API/Model/Location.cs b/src/Services/Marketing/Marketing.API/Model/Location.cs new file mode 100644 index 000000000..e3973f425 --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Model/Location.cs @@ -0,0 +1,9 @@ +using System; +using System.Collections.Generic; +namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model +{ + public class Location + { + public int Id { get; set; } + } +} diff --git a/src/Services/Marketing/Marketing.API/Model/Rule.cs b/src/Services/Marketing/Marketing.API/Model/Rule.cs new file mode 100644 index 000000000..38a47d3eb --- /dev/null +++ b/src/Services/Marketing/Marketing.API/Model/Rule.cs @@ -0,0 +1,29 @@ +using System.Collections.Generic; + +namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model +{ + public abstract class Rule + { + public int Id { get; set; } + + public int RuleTypeId { get; set; } + + public int CampaignId { get; set; } + + public Campaign Campaign { get; set; } + + public string Description { get; set; } + } + + + public class UserProfileRule : Rule + { } + + public class PurchaseHistoryRule : Rule + { } + + public class UserLocationRule : Rule + { + public int LocationId { get; set; } + } +} diff --git a/src/Services/Marketing/Marketing.API/Program.cs b/src/Services/Marketing/Marketing.API/Program.cs index cbda3e538..981e797c1 100644 --- a/src/Services/Marketing/Marketing.API/Program.cs +++ b/src/Services/Marketing/Marketing.API/Program.cs @@ -12,7 +12,6 @@ .UseKestrel() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup() - .UseApplicationInsights() .Build(); host.Run(); diff --git a/src/Services/Marketing/Marketing.API/Properties/launchSettings.json b/src/Services/Marketing/Marketing.API/Properties/launchSettings.json index 4adb2bd6a..ec47d57ce 100644 --- a/src/Services/Marketing/Marketing.API/Properties/launchSettings.json +++ b/src/Services/Marketing/Marketing.API/Properties/launchSettings.json @@ -1,9 +1,9 @@ -{ +{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { - "applicationUrl": "http://localhost:52058/", + "applicationUrl": "http://localhost:5110", "sslPort": 0 } }, @@ -26,4 +26,4 @@ "applicationUrl": "http://localhost:52059" } } -} +} \ No newline at end of file diff --git a/src/Services/Marketing/Marketing.API/Startup.cs b/src/Services/Marketing/Marketing.API/Startup.cs index 91afead63..378ba214c 100644 --- a/src/Services/Marketing/Marketing.API/Startup.cs +++ b/src/Services/Marketing/Marketing.API/Startup.cs @@ -36,16 +36,6 @@ // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { - //services.AddHealthChecks(checks => - //{ - // var minutes = 1; - // if (int.TryParse(Configuration["HealthCheck:Timeout"], out var minutesParsed)) - // { - // minutes = minutesParsed; - // } - // checks.AddSqlCheck("MarketingDb", Configuration["ConnectionString"], TimeSpan.FromMinutes(minutes)); - //}); - // Add framework services. services.AddMvc(); @@ -106,8 +96,8 @@ c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); - //MarketingContextSeed.SeedAsync(app, loggerFactory) - // .Wait(); + MarketingContextSeed.SeedAsync(app, loggerFactory) + .Wait(); } diff --git a/src/Services/Marketing/Marketing.API/appsettings.Development.json b/src/Services/Marketing/Marketing.API/appsettings.Development.json index fa8ce71a9..5fff67bac 100644 --- a/src/Services/Marketing/Marketing.API/appsettings.Development.json +++ b/src/Services/Marketing/Marketing.API/appsettings.Development.json @@ -2,9 +2,7 @@ "Logging": { "IncludeScopes": false, "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Default": "Warning" } } }