Browse Source

Migrate Sql Server.Added Swagger

pull/49/merge
Unai 8 years ago
parent
commit
cfd1a37fba
12 changed files with 635 additions and 64 deletions
  1. +8
    -3
      docker-compose.yml
  2. +15
    -24
      src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs
  3. +2
    -4
      src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs
  4. +99
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.Designer.cs
  5. +108
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.cs
  6. +99
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.Designer.cs
  7. +161
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.cs
  8. +98
    -0
      src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs
  9. +35
    -27
      src/Services/Catalog/Catalog.API/Startup.cs
  10. +8
    -4
      src/Services/Catalog/Catalog.API/project.json
  11. +1
    -1
      src/Services/Catalog/Catalog.API/settings.development.json
  12. +1
    -1
      src/Services/Catalog/Catalog.API/settings.production.json

+ 8
- 3
docker-compose.yml View File

@ -15,14 +15,19 @@ services:
catalog.api: catalog.api:
image: eshop/catalog.api:latest image: eshop/catalog.api:latest
environment: environment:
- ConnectionString=Server=catalogdata;Port=5432;Database=postgres;username=postgres
- ConnectionString=Server=catalogdata;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word
expose: expose:
- "80" - "80"
depends_on: depends_on:
- catalogdata - catalogdata
catalogdata: catalogdata:
image: glennc/eshopdata
image: eshop/mssql-server-private-preview
environment:
- ACCEPT_EULA=Y
- SA_PASSWORD=Pass@word
ports:
- "1455:1433"
ordering.api: ordering.api:
image: eshop/ordering.api:latest image: eshop/ordering.api:latest
@ -43,7 +48,7 @@ services:
image: eshop/ordering.data.sqlserver.linux image: eshop/ordering.data.sqlserver.linux
ports: ports:
- "1433:1433" - "1433:1433"
basket.api: basket.api:
image: eshop/basket.api:latest image: eshop/basket.api:latest
environment: environment:


+ 15
- 24
src/Services/Catalog/Catalog.API/Infrastructure/CatalogContext.cs View File

@ -2,7 +2,6 @@
{ {
using EntityFrameworkCore.Metadata.Builders; using EntityFrameworkCore.Metadata.Builders;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Npgsql.EntityFrameworkCore.PostgreSQL;
public class CatalogContext : DbContext public class CatalogContext : DbContext
{ {
@ -18,32 +17,19 @@
protected override void OnModelCreating(ModelBuilder builder) protected override void OnModelCreating(ModelBuilder builder)
{ {
builder.HasSequence("idseqcatalog")
.StartsAt(1)
.IncrementsBy(1);
builder.HasSequence("idseqcatalogbrand")
.StartsAt(1)
.IncrementsBy(1);
builder.HasSequence("idseqcatalogtype")
.StartsAt(1)
.IncrementsBy(1);
builder.Entity<CatalogBrand>(ConfigureCatalogBrand); builder.Entity<CatalogBrand>(ConfigureCatalogBrand);
builder.Entity<CatalogType>(ConfigureCatalogType); builder.Entity<CatalogType>(ConfigureCatalogType);
builder.Entity<CatalogItem>(ConfigureCatalogItem); builder.Entity<CatalogItem>(ConfigureCatalogItem);
builder.HasPostgresExtension("uuid-ossp");
} }
void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder) void ConfigureCatalogItem(EntityTypeBuilder<CatalogItem> builder)
{ {
builder.ForNpgsqlToTable("catalog");
builder.ToTable("Catalog");
builder.Property(ci => ci.Id) builder.Property(ci => ci.Id)
.HasDefaultValueSql("nextval('idseqcatalog')")
.ForSqlServerUseSequenceHiLo("catalog_hilo")
.IsRequired(); .IsRequired();
builder.Property(ci => ci.Name) builder.Property(ci => ci.Name)
@ -68,11 +54,13 @@
void ConfigureCatalogBrand(EntityTypeBuilder<CatalogBrand> builder) void ConfigureCatalogBrand(EntityTypeBuilder<CatalogBrand> builder)
{ {
builder.ForNpgsqlToTable("catalogbrand");
builder.ToTable("CatalogBrand");
builder.Property(cb => cb.Id)
.HasDefaultValueSql("nextval('idseqcatalogbrand')")
.IsRequired();
builder.HasKey(ci => ci.Id);
builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_brand_hilo")
.IsRequired();
builder.Property(cb => cb.Brand) builder.Property(cb => cb.Brand)
.IsRequired() .IsRequired()
@ -81,11 +69,14 @@
void ConfigureCatalogType(EntityTypeBuilder<CatalogType> builder) void ConfigureCatalogType(EntityTypeBuilder<CatalogType> builder)
{ {
builder.ForNpgsqlToTable("catalogtype");
builder.Property(cb => cb.Id)
.HasDefaultValueSql("nextval('idseqcatalogtype')")
.IsRequired();
builder.ToTable("CatalogType");
builder.HasKey(ci => ci.Id);
builder.Property(ci => ci.Id)
.ForSqlServerUseSequenceHiLo("catalog_type_hilo")
.IsRequired();
builder.Property(cb => cb.Type) builder.Property(cb => cb.Type)
.IsRequired() .IsRequired()


+ 2
- 4
src/Services/Catalog/Catalog.API/Infrastructure/CatalogContextSeed.cs View File

@ -1,7 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure namespace Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure
{ {
using EntityFrameworkCore;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -15,9 +15,7 @@
using (context) using (context)
{ {
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
context.Database.Migrate();
if (!context.CatalogBrands.Any()) if (!context.CatalogBrands.Any())
{ {


+ 99
- 0
src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.Designer.cs View File

@ -0,0 +1,99 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
namespace Catalog.API.Infrastructure.Migrations
{
[DbContext(typeof(CatalogContext))]
[Migration("20161103152832_Initial")]
partial class Initial
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.1")
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasAnnotation("MaxLength", 100);
b.HasKey("Id");
b.ToTable("catalogbrand");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 50);
b.Property<string>("PictureUri");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("catalog");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Type")
.IsRequired()
.HasAnnotation("MaxLength", 100);
b.HasKey("Id");
b.ToTable("CatalogTypes");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", "CatalogBrand")
.WithMany()
.HasForeignKey("CatalogBrandId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", "CatalogType")
.WithMany()
.HasForeignKey("CatalogTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

+ 108
- 0
src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103152832_Initial.cs View File

@ -0,0 +1,108 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Catalog.API.Infrastructure.Migrations
{
public partial class Initial : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateSequence(
name: "catalog_brand_hilo",
incrementBy: 10);
migrationBuilder.CreateSequence(
name: "catalog_hilo",
incrementBy: 10);
migrationBuilder.CreateSequence(
name: "catalog_type_hilo",
incrementBy: 10);
migrationBuilder.CreateTable(
name: "catalogbrand",
columns: table => new
{
Id = table.Column<int>(nullable: false),
Brand = table.Column<string>(maxLength: 100, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_catalogbrand", x => x.Id);
});
migrationBuilder.CreateTable(
name: "CatalogTypes",
columns: table => new
{
Id = table.Column<int>(nullable: false),
Type = table.Column<string>(maxLength: 100, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_CatalogTypes", x => x.Id);
});
migrationBuilder.CreateTable(
name: "catalog",
columns: table => new
{
Id = table.Column<int>(nullable: false),
CatalogBrandId = table.Column<int>(nullable: false),
CatalogTypeId = table.Column<int>(nullable: false),
Description = table.Column<string>(nullable: true),
Name = table.Column<string>(maxLength: 50, nullable: false),
PictureUri = table.Column<string>(nullable: true),
Price = table.Column<decimal>(nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_catalog", x => x.Id);
table.ForeignKey(
name: "FK_catalog_catalogbrand_CatalogBrandId",
column: x => x.CatalogBrandId,
principalTable: "catalogbrand",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_catalog_CatalogTypes_CatalogTypeId",
column: x => x.CatalogTypeId,
principalTable: "CatalogTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_catalog_CatalogBrandId",
table: "catalog",
column: "CatalogBrandId");
migrationBuilder.CreateIndex(
name: "IX_catalog_CatalogTypeId",
table: "catalog",
column: "CatalogTypeId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropSequence(
name: "catalog_brand_hilo");
migrationBuilder.DropSequence(
name: "catalog_hilo");
migrationBuilder.DropSequence(
name: "catalog_type_hilo");
migrationBuilder.DropTable(
name: "catalog");
migrationBuilder.DropTable(
name: "catalogbrand");
migrationBuilder.DropTable(
name: "CatalogTypes");
}
}
}

+ 99
- 0
src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.Designer.cs View File

@ -0,0 +1,99 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
namespace Catalog.API.Infrastructure.Migrations
{
[DbContext(typeof(CatalogContext))]
[Migration("20161103153420_UpdateTableNames")]
partial class UpdateTableNames
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.1")
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasAnnotation("MaxLength", 100);
b.HasKey("Id");
b.ToTable("CatalogBrand");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 50);
b.Property<string>("PictureUri");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("Catalog");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Type")
.IsRequired()
.HasAnnotation("MaxLength", 100);
b.HasKey("Id");
b.ToTable("CatalogType");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", "CatalogBrand")
.WithMany()
.HasForeignKey("CatalogBrandId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", "CatalogType")
.WithMany()
.HasForeignKey("CatalogTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

+ 161
- 0
src/Services/Catalog/Catalog.API/Infrastructure/Migrations/20161103153420_UpdateTableNames.cs View File

@ -0,0 +1,161 @@
using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Catalog.API.Infrastructure.Migrations
{
public partial class UpdateTableNames : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_catalog_catalogbrand_CatalogBrandId",
table: "catalog");
migrationBuilder.DropForeignKey(
name: "FK_catalog_CatalogTypes_CatalogTypeId",
table: "catalog");
migrationBuilder.DropPrimaryKey(
name: "PK_CatalogTypes",
table: "CatalogTypes");
migrationBuilder.DropPrimaryKey(
name: "PK_catalog",
table: "catalog");
migrationBuilder.DropPrimaryKey(
name: "PK_catalogbrand",
table: "catalogbrand");
migrationBuilder.AddPrimaryKey(
name: "PK_CatalogType",
table: "CatalogTypes",
column: "Id");
migrationBuilder.AddPrimaryKey(
name: "PK_Catalog",
table: "catalog",
column: "Id");
migrationBuilder.AddPrimaryKey(
name: "PK_CatalogBrand",
table: "catalogbrand",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_Catalog_CatalogBrand_CatalogBrandId",
table: "catalog",
column: "CatalogBrandId",
principalTable: "catalogbrand",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_Catalog_CatalogType_CatalogTypeId",
table: "catalog",
column: "CatalogTypeId",
principalTable: "CatalogTypes",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.RenameIndex(
name: "IX_catalog_CatalogTypeId",
table: "catalog",
newName: "IX_Catalog_CatalogTypeId");
migrationBuilder.RenameIndex(
name: "IX_catalog_CatalogBrandId",
table: "catalog",
newName: "IX_Catalog_CatalogBrandId");
migrationBuilder.RenameTable(
name: "CatalogTypes",
newName: "CatalogType");
migrationBuilder.RenameTable(
name: "catalog",
newName: "Catalog");
migrationBuilder.RenameTable(
name: "catalogbrand",
newName: "CatalogBrand");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Catalog_CatalogBrand_CatalogBrandId",
table: "Catalog");
migrationBuilder.DropForeignKey(
name: "FK_Catalog_CatalogType_CatalogTypeId",
table: "Catalog");
migrationBuilder.DropPrimaryKey(
name: "PK_CatalogType",
table: "CatalogType");
migrationBuilder.DropPrimaryKey(
name: "PK_Catalog",
table: "Catalog");
migrationBuilder.DropPrimaryKey(
name: "PK_CatalogBrand",
table: "CatalogBrand");
migrationBuilder.AddPrimaryKey(
name: "PK_CatalogTypes",
table: "CatalogType",
column: "Id");
migrationBuilder.AddPrimaryKey(
name: "PK_catalog",
table: "Catalog",
column: "Id");
migrationBuilder.AddPrimaryKey(
name: "PK_catalogbrand",
table: "CatalogBrand",
column: "Id");
migrationBuilder.AddForeignKey(
name: "FK_catalog_catalogbrand_CatalogBrandId",
table: "Catalog",
column: "CatalogBrandId",
principalTable: "CatalogBrand",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.AddForeignKey(
name: "FK_catalog_CatalogTypes_CatalogTypeId",
table: "Catalog",
column: "CatalogTypeId",
principalTable: "CatalogType",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
migrationBuilder.RenameIndex(
name: "IX_Catalog_CatalogTypeId",
table: "Catalog",
newName: "IX_catalog_CatalogTypeId");
migrationBuilder.RenameIndex(
name: "IX_Catalog_CatalogBrandId",
table: "Catalog",
newName: "IX_catalog_CatalogBrandId");
migrationBuilder.RenameTable(
name: "CatalogType",
newName: "CatalogTypes");
migrationBuilder.RenameTable(
name: "Catalog",
newName: "catalog");
migrationBuilder.RenameTable(
name: "CatalogBrand",
newName: "catalogbrand");
}
}
}

+ 98
- 0
src/Services/Catalog/Catalog.API/Infrastructure/Migrations/CatalogContextModelSnapshot.cs View File

@ -0,0 +1,98 @@
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
namespace Catalog.API.Infrastructure.Migrations
{
[DbContext(typeof(CatalogContext))]
partial class CatalogContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
modelBuilder
.HasAnnotation("ProductVersion", "1.0.1")
.HasAnnotation("SqlServer:Sequence:.catalog_brand_hilo", "'catalog_brand_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_hilo", "'catalog_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:Sequence:.catalog_type_hilo", "'catalog_type_hilo', '', '1', '10', '', '', 'Int64', 'False'")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn);
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_brand_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Brand")
.IsRequired()
.HasAnnotation("MaxLength", 100);
b.HasKey("Id");
b.ToTable("CatalogBrand");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<int>("CatalogBrandId");
b.Property<int>("CatalogTypeId");
b.Property<string>("Description");
b.Property<string>("Name")
.IsRequired()
.HasAnnotation("MaxLength", 50);
b.Property<string>("PictureUri");
b.Property<decimal>("Price");
b.HasKey("Id");
b.HasIndex("CatalogBrandId");
b.HasIndex("CatalogTypeId");
b.ToTable("Catalog");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasAnnotation("SqlServer:HiLoSequenceName", "catalog_type_hilo")
.HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.SequenceHiLo);
b.Property<string>("Type")
.IsRequired()
.HasAnnotation("MaxLength", 100);
b.HasKey("Id");
b.ToTable("CatalogType");
});
modelBuilder.Entity("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogItem", b =>
{
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogBrand", "CatalogBrand")
.WithMany()
.HasForeignKey("CatalogBrandId")
.OnDelete(DeleteBehavior.Cascade);
b.HasOne("Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure.CatalogType", "CatalogType")
.WithMany()
.HasForeignKey("CatalogTypeId")
.OnDelete(DeleteBehavior.Cascade);
});
}
}
}

+ 35
- 27
src/Services/Catalog/Catalog.API/Startup.cs View File

@ -1,18 +1,14 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json.Serialization;
using System.Threading.Tasks;
namespace Microsoft.eShopOnContainers.Services.Catalog.API
namespace Microsoft.eShopOnContainers.Services.Catalog.API
{ {
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
public class Startup public class Startup
{ {
public IConfigurationRoot Configuration { get; } public IConfigurationRoot Configuration { get; }
@ -21,22 +17,20 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
{ {
var builder = new ConfigurationBuilder() var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath) .SetBasePath(env.ContentRootPath)
.AddJsonFile($"settings.{env.EnvironmentName}.json",optional:false)
.AddJsonFile($"settings.{env.EnvironmentName}.json", optional: false)
.AddEnvironmentVariables(); .AddEnvironmentVariables();
Configuration = builder.Build(); Configuration = builder.Build();
} }
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddSingleton<IConfiguration>(Configuration); services.AddSingleton<IConfiguration>(Configuration);
services.AddDbContext<CatalogContext>(c =>
services.AddDbContext<CatalogContext>(c =>
{ {
c.UseNpgsql(Configuration["ConnectionString"]);
c.UseSqlServer(Configuration["ConnectionString"]);
c.ConfigureWarnings(wb => c.ConfigureWarnings(wb =>
{ {
wb.Throw(RelationalEventId.QueryClientEvaluationWarning); wb.Throw(RelationalEventId.QueryClientEvaluationWarning);
@ -45,13 +39,24 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
// Add framework services. // Add framework services.
services.AddSwaggerGen();
services.ConfigureSwaggerGen(options =>
{
options.DescribeAllEnumsAsStrings();
options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info()
{
Title = "Values API",
Version = "v1",
Description = "An API API With Swagger for RC2",
TermsOfService = "None"
});
});
services.AddCors(); services.AddCors();
services.AddMvcCore()
.AddJsonFormatters(settings=>
{
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
});
services.AddMvc(mvcoptions =>
{
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -60,8 +65,8 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
//Configure logs //Configure logs
if(env.IsDevelopment())
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
@ -74,9 +79,12 @@ namespace Microsoft.eShopOnContainers.Services.Catalog.API
.Wait(); .Wait();
// Use frameworks // Use frameworks
app.UseCors(policyBuilder=>policyBuilder.AllowAnyOrigin());
app.UseCors(policyBuilder => policyBuilder.AllowAnyOrigin());
app.UseMvc(); app.UseMvc();
app.UseSwagger()
.UseSwaggerUi();
} }
} }
} }

+ 8
- 4
src/Services/Catalog/Catalog.API/project.json View File

@ -3,22 +3,26 @@
"Microsoft.NETCore.App": { "Microsoft.NETCore.App": {
"version": "1.0.1", "version": "1.0.1",
"type": "platform" "type": "platform"
},
},
"Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Mvc": "1.0.1",
"Microsoft.AspNetCore.Diagnostics": "1.0.0", "Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Diagnostics.Abstractions": "1.0.0", "Microsoft.AspNetCore.Diagnostics.Abstractions": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.2"
"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.EntityFrameworkCore.Relational": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.Design": "1.0.0-preview2-final",
"Swashbuckle": "6.0.0-beta902"
}, },
"tools": { "tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
}, },
"frameworks": { "frameworks": {
"netcoreapp1.0": { "netcoreapp1.0": {


+ 1
- 1
src/Services/Catalog/Catalog.API/settings.development.json View File

@ -1,5 +1,5 @@
{ {
"ConnectionString": "Server=127.0.0.1;Port=5432;Database=CatalogDB;username=postgres;password=postgres",
"ConnectionString": "Server=tcp:127.0.0.1,1455;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word",
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"LogLevel": { "LogLevel": {


+ 1
- 1
src/Services/Catalog/Catalog.API/settings.production.json View File

@ -1,5 +1,5 @@
{ {
"ConnectionString": "Server=127.0.0.1;Port=5432;Database=CatalogDB;username=postgres;password=postgres",
"ConnectionString": "Server=tcp:127.0.0.1,1455;Initial Catalog=CatalogDB;User Id=sa;Password=Pass@word",
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
"LogLevel": { "LogLevel": {


Loading…
Cancel
Save