Browse Source

Add Marketing.API project

pull/223/head
Christian Arenas 7 years ago
parent
commit
4dc8b65e8b
18 changed files with 382 additions and 2 deletions
  1. +2
    -2
      cli-windows/add-firewall-rules-for-sts-auth-thru-docker.ps1
  2. +3
    -0
      src/Services/Marketing/Marketing.API/.dockerignore
  3. +36
    -0
      src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs
  4. +13
    -0
      src/Services/Marketing/Marketing.API/Controllers/HomeController.cs
  5. +6
    -0
      src/Services/Marketing/Marketing.API/Dockerfile
  6. +25
    -0
      src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs
  7. +20
    -0
      src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs
  8. +56
    -0
      src/Services/Marketing/Marketing.API/Marketing.API.csproj
  9. +7
    -0
      src/Services/Marketing/Marketing.API/MarketingSettings.cs
  10. +7
    -0
      src/Services/Marketing/Marketing.API/Model/Campaing.cs
  11. +21
    -0
      src/Services/Marketing/Marketing.API/Program.cs
  12. +29
    -0
      src/Services/Marketing/Marketing.API/Properties/launchSettings.json
  13. +125
    -0
      src/Services/Marketing/Marketing.API/Startup.cs
  14. +10
    -0
      src/Services/Marketing/Marketing.API/appsettings.Development.json
  15. +10
    -0
      src/Services/Marketing/Marketing.API/appsettings.json
  16. +4
    -0
      test/Services/FunctionalTests/FunctionalTests.csproj
  17. +4
    -0
      test/Services/IntegrationTests/IntegrationTests.csproj
  18. +4
    -0
      test/Services/UnitTest/UnitTest.csproj

+ 2
- 2
cli-windows/add-firewall-rules-for-sts-auth-thru-docker.ps1 View File

@ -21,6 +21,6 @@ try {
Write-Host "Rule found"
}
catch [Exception] {
New-NetFirewallRule -DisplayName eShopOnContainers-Inbound -Confirm -Description "eShopOnContainers Inbound Rule for port range 5100-5105" -LocalAddress Any -LocalPort 5100-5105 -Protocol tcp -RemoteAddress Any -RemotePort Any -Direction Inbound
New-NetFirewallRule -DisplayName eShopOnContainers-Outbound -Confirm -Description "eShopOnContainers Outbound Rule for port range 5100-5105" -LocalAddress Any -LocalPort 5100-5105 -Protocol tcp -RemoteAddress Any -RemotePort Any -Direction Outbound
New-NetFirewallRule -DisplayName eShopOnContainers-Inbound -Confirm -Description "eShopOnContainers Inbound Rule for port range 5100-5110" -LocalAddress Any -LocalPort 5100-5110 -Protocol tcp -RemoteAddress Any -RemotePort Any -Direction Inbound
New-NetFirewallRule -DisplayName eShopOnContainers-Outbound -Confirm -Description "eShopOnContainers Outbound Rule for port range 5100-5110" -LocalAddress Any -LocalPort 5100-5110 -Protocol tcp -RemoteAddress Any -RemotePort Any -Direction Outbound
}

+ 3
- 0
src/Services/Marketing/Marketing.API/.dockerignore View File

@ -0,0 +1,3 @@
*
!obj/Docker/publish/*
!obj/Docker/empty/

+ 36
- 0
src/Services/Marketing/Marketing.API/Controllers/CampaignsController.cs View File

@ -0,0 +1,36 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
{
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
[Route("api/[controller]")]
public class CampaignsController : Controller
{
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
[HttpGet("{id:int}")]
public string Get(int id)
{
return "value";
}
[HttpPost]
public void Post([FromBody]string value)
{
}
[HttpPut("{id:int}")]
public void Put(int id, [FromBody]string value)
{
}
[HttpDelete("{id:int}")]
public void Delete(int id)
{
}
}
}

+ 13
- 0
src/Services/Marketing/Marketing.API/Controllers/HomeController.cs View File

@ -0,0 +1,13 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Controllers
{
using Microsoft.AspNetCore.Mvc;
// GET: /<controller>/
public class HomeController : Controller
{
public IActionResult Index()
{
return new RedirectResult("~/swagger");
}
}
}

+ 6
- 0
src/Services/Marketing/Marketing.API/Dockerfile View File

@ -0,0 +1,6 @@
FROM microsoft/aspnetcore:1.1
ARG source
WORKDIR /app
EXPOSE 80
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Marketing.API.dll"]

+ 25
- 0
src/Services/Marketing/Marketing.API/Infrastructure/MarketingContext.cs View File

@ -0,0 +1,25 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure
{
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using Microsoft.eShopOnContainers.Services.Marketing.API.Model;
public class MarketingContext : DbContext
{
public MarketingContext(DbContextOptions options) : base(options)
{
}
public DbSet<Campaing> Campaings { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
builder.Entity<Campaing>(ConfigureCampaings);
}
void ConfigureCampaings(EntityTypeBuilder<Campaing> builder)
{
}
}
}

+ 20
- 0
src/Services/Marketing/Marketing.API/Infrastructure/MarketingContextSeed.cs View File

@ -0,0 +1,20 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure
{
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using System.Threading.Tasks;
public class MarketingContextSeed
{
public static async Task SeedAsync(IApplicationBuilder applicationBuilder, ILoggerFactory loggerFactory, int? retry = 0)
{
var context = (MarketingContext)applicationBuilder
.ApplicationServices.GetService(typeof(MarketingContext));
context.Database.Migrate();
//TODO: add model seeding
}
}
}

+ 56
- 0
src/Services/Marketing/Marketing.API/Marketing.API.csproj View File

@ -0,0 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
<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>
</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="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="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.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" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
</Project>

+ 7
- 0
src/Services/Marketing/Marketing.API/MarketingSettings.cs View File

@ -0,0 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API
{
public class MarketingSettings
{
public string ConnectionString { get; set; }
}
}

+ 7
- 0
src/Services/Marketing/Marketing.API/Model/Campaing.cs View File

@ -0,0 +1,7 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API.Model
{
public class Campaing
{
//TODO: Add Campaing properties
}
}

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

@ -0,0 +1,21 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API
{
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
}
}

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

@ -0,0 +1,29 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52058/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Marketing.API": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:52059"
}
}
}

+ 125
- 0
src/Services/Marketing/Marketing.API/Startup.cs View File

@ -0,0 +1,125 @@
namespace Microsoft.eShopOnContainers.Services.Marketing.API
{
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Marketing.API.Infrastructure;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System.Reflection;
using System;
public class Startup
{
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
if (env.IsDevelopment())
{
builder.AddUserSecrets(typeof(Startup).GetTypeInfo().Assembly);
}
builder.AddEnvironmentVariables();
Configuration = builder.Build();
}
public IConfigurationRoot Configuration { get; }
// 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();
services.AddDbContext<MarketingContext>(options =>
{
options.UseSqlServer(Configuration["ConnectionString"],
sqlServerOptionsAction: sqlOptions =>
{
sqlOptions.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name);
//Configuring Connection Resiliency: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency
sqlOptions.EnableRetryOnFailure(maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), errorNumbersToAdd: null);
});
// Changing default behavior when client evaluation occurs to throw.
// Default in EF Core would be to log a warning when client evaluation is performed.
options.ConfigureWarnings(warnings => warnings.Throw(RelationalEventId.QueryClientEvaluationWarning));
//Check Client vs. Server evaluation: https://docs.microsoft.com/en-us/ef/core/querying/client-eval
});
// Add framework services.
services.AddSwaggerGen(options =>
{
options.DescribeAllEnumsAsStrings();
options.SwaggerDoc("v1", new Swashbuckle.AspNetCore.Swagger.Info
{
Title = "Marketing HTTP API",
Version = "v1",
Description = "The Marketing Service HTTP API",
TermsOfService = "Terms Of Service"
});
});
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.AllowCredentials());
});
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseCors("CorsPolicy");
ConfigureAuth(app);
app.UseMvcWithDefaultRoute();
app.UseSwagger()
.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
//MarketingContextSeed.SeedAsync(app, loggerFactory)
// .Wait();
}
protected virtual void ConfigureAuth(IApplicationBuilder app)
{
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = identityUrl.ToString(),
ApiName = "marketing",
RequireHttpsMetadata = false
});
}
}
}

+ 10
- 0
src/Services/Marketing/Marketing.API/appsettings.Development.json View File

@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}

+ 10
- 0
src/Services/Marketing/Marketing.API/appsettings.json View File

@ -0,0 +1,10 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Warning"
}
},
"ConnectionString": "127.0.0.1",
"IdentityUrl": "http://localhost:5105"
}

+ 4
- 0
test/Services/FunctionalTests/FunctionalTests.csproj View File

@ -38,4 +38,8 @@
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

+ 4
- 0
test/Services/IntegrationTests/IntegrationTests.csproj View File

@ -46,4 +46,8 @@
</Content>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

+ 4
- 0
test/Services/UnitTest/UnitTest.csproj View File

@ -28,4 +28,8 @@
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.2" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>

Loading…
Cancel
Save