Browse Source

Add marketing api

pull/809/head
Christian Arenas 7 years ago
parent
commit
32247c503d
19 changed files with 566 additions and 96 deletions
  1. +10
    -10
      docker-compose.override.yml
  2. +10
    -10
      docker-compose.prod.yml
  3. +14
    -12
      docker-compose.vs.debug.yml
  4. +5
    -5
      docker-compose.vs.release.yml
  5. +59
    -9
      src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs
  6. +1
    -1
      src/Services/Marketing/Marketing.API/Dockerfile
  7. +63
    -6
      src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs
  8. +48
    -1
      src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs
  9. +10
    -20
      src/Services/Marketing/Marketing.API/Marketing.API.csproj
  10. +108
    -0
      src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.Designer.cs
  11. +71
    -0
      src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.cs
  12. +107
    -0
      src/Services/Marketing/Marketing.API/Migrations/MarketingContextModelSnapshot.cs
  13. +16
    -3
      src/Services/Marketing/Marketing.API/Model/Campaing.cs
  14. +9
    -0
      src/Services/Marketing/Marketing.API/Model/Location.cs
  15. +29
    -0
      src/Services/Marketing/Marketing.API/Model/Rule.cs
  16. +0
    -1
      src/Services/Marketing/Marketing.API/Program.cs
  17. +3
    -3
      src/Services/Marketing/Marketing.API/Properties/launchSettings.json
  18. +2
    -12
      src/Services/Marketing/Marketing.API/Startup.cs
  19. +1
    -3
      src/Services/Marketing/Marketing.API/appsettings.Development.json

+ 10
- 10
docker-compose.override.yml View File

@ -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"
- "5107:80"

+ 10
- 10
docker-compose.prod.yml View File

@ -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"
- "5107:80"

+ 14
- 12
docker-compose.vs.debug.yml View File

@ -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"

+ 5
- 5
docker-compose.vs.release.yml View File

@ -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"
- "com.microsoft.visualstudio.targetoperatingsystem=linux"

+ 59
- 9
src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs View File

@ -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<string> Get()
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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();
}
}
}
}

+ 1
- 1
src/Services/Marketing/Marketing.API/Dockerfile View File

@ -1,4 +1,4 @@
FROM microsoft/aspnetcore:1.1
FROM microsoft/aspnetcore:1.1.2
ARG source
WORKDIR /app
EXPOSE 80


+ 63
- 6
src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs View File

@ -6,20 +6,77 @@
public class MarketingContext : DbContext
{
public MarketingContext(DbContextOptions options) : base(options)
{
public MarketingContext(DbContextOptions<MarketingContext> options) : base(options)
{
}
public DbSet<Campaing> Campaings { get; set; }
public DbSet<Campaign> Campaigns { get; set; }
public DbSet<Rule> Rules { get; set; }
public DbSet<UserProfileRule> UserProfileRules { get; set; }
public DbSet<PurchaseHistoryRule> PurchaseHistoryRules { get; set; }
public DbSet<UserLocationRule> UserLocationRules { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Campaing>(ConfigureCampaings);
builder.Entity<Campaign>(ConfigureCampaigns);
builder.Entity<Rule>(ConfigureRules);
builder.Entity<UserLocationRule>(ConfigureUserLocationRules);
}
void ConfigureCampaings(EntityTypeBuilder<Campaing> builder)
void ConfigureCampaigns(EntityTypeBuilder<Campaign> 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<Rule> builder)
{
builder.ToTable("Rules");
builder.HasKey(r => r.Id);
builder.HasDiscriminator<int>("RuleTypeId")
.HasValue<UserProfileRule>(1)
.HasValue<PurchaseHistoryRule>(2)
.HasValue<UserLocationRule>(3);
builder.Property(r => r.Description)
.HasColumnName("Description")
.IsRequired();
}
void ConfigureUserLocationRules(EntityTypeBuilder<UserLocationRule> builder)
{
builder.Property(r => r.LocationId)
.HasColumnName("LocationId")
.IsRequired();
}
}
}
}

+ 48
- 1
src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs View File

@ -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<Campaign> GetPreconfiguredMarketings()
{
return new List<Campaign>
{
new Campaign
{
Description = "Campaign1",
From = DateTime.Now,
To = DateTime.Now.AddDays(7),
Url = "http://CampaignUrl.test/12f09ed3cef54187123f500ad",
Rules = new List<Rule>
{
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<Rule>
{
new UserLocationRule
{
Description = "UserLocationRule2",
LocationId = 1
}
}
}
};
}
}
}

+ 10
- 20
src/Services/Marketing/Marketing.API/Marketing.API.csproj View File

@ -2,20 +2,20 @@
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<RuntimeFrameworkVersion>1.1.2</RuntimeFrameworkVersion>
<OutputType>Exe</OutputType>
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
<RootNamespace>Microsoft.eShopOnContainers.Services.Marketing.API</RootNamespace>
<PackageTargetFallback>portable-net45+win8</PackageTargetFallback>
<UserSecretsId>aspnet-TestApp-ce941b30-19cf-4972-b34f-d03f2e7976ed</UserSecretsId>
<UserSecretsId>aspnet-Marketing.API-20161122013619</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<Folder Include="IntegrationEvents\EventHandling\" />
<Folder Include="IntegrationEvents\Events\" />
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
@ -24,23 +24,14 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" /><PackageReference Include="IdentityServer4.AccessTokenValidation" Version="1.2.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.0-preview1-final" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2" />
@ -52,5 +43,4 @@
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
</Project>

+ 108
- 0
src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.Designer.cs View File

@ -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<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "campaign_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Description")
.IsRequired()
.HasColumnName("Description");
b.Property<DateTime>("From")
.HasColumnName("From");
b.Property<DateTime>("To")
.HasColumnName("To");
b.Property<string>("Url");
b.HasKey("Id");
b.ToTable("Campaign");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("CampaignId");
b.Property<string>("Description")
.IsRequired()
.HasColumnName("Description");
b.Property<int>("RuleTypeId");
b.HasKey("Id");
b.HasIndex("CampaignId");
b.ToTable("Rules");
b.HasDiscriminator<int>("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<int>("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);
});
}
}
}

+ 71
- 0
src/Services/Marketing/Marketing.API/Migrations/20170601175200_Initial.cs View File

@ -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<int>(nullable: false),
Description = table.Column<string>(nullable: false),
From = table.Column<DateTime>(nullable: false),
To = table.Column<DateTime>(nullable: false),
Url = table.Column<string>(nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Campaign", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Rules",
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn),
CampaignId = table.Column<int>(nullable: false),
Description = table.Column<string>(nullable: false),
RuleTypeId = table.Column<int>(nullable: false),
LocationId = table.Column<int>(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");
}
}
}

+ 107
- 0
src/Services/Marketing/Marketing.API/Migrations/MarketingContextModelSnapshot.cs View File

@ -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<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "campaign_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Description")
.IsRequired()
.HasColumnName("Description");
b.Property<DateTime>("From")
.HasColumnName("From");
b.Property<DateTime>("To")
.HasColumnName("To");
b.Property<string>("Url");
b.HasKey("Id");
b.ToTable("Campaign");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Marketing.API.Model.Rule", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd();
b.Property<int>("CampaignId");
b.Property<string>("Description")
.IsRequired()
.HasColumnName("Description");
b.Property<int>("RuleTypeId");
b.HasKey("Id");
b.HasIndex("CampaignId");
b.ToTable("Rules");
b.HasDiscriminator<int>("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<int>("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);
});
}
}
}

+ 16
- 3
src/Services/Marketing/Marketing.API/Model/Campaing.cs View File

@ -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<Rule> Rules { get; set; }
}
}
}

+ 9
- 0
src/Services/Marketing/Marketing.API/Model/Location.cs View File

@ -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; }
}
}

+ 29
- 0
src/Services/Marketing/Marketing.API/Model/Rule.cs View File

@ -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; }
}
}

+ 0
- 1
src/Services/Marketing/Marketing.API/Program.cs View File

@ -12,7 +12,6 @@
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();


+ 3
- 3
src/Services/Marketing/Marketing.API/Properties/launchSettings.json View File

@ -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"
}
}
}
}

+ 2
- 12
src/Services/Marketing/Marketing.API/Startup.cs View File

@ -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();
}


+ 1
- 3
src/Services/Marketing/Marketing.API/appsettings.Development.json View File

@ -2,9 +2,7 @@
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Warning"
}
}
}

Loading…
Cancel
Save