├── .gitignore ├── docker_entrypoint.sh ├── src └── StatlerWaldorfCorp.EcommerceInventory │ ├── Persistence │ ├── ISKUStatusRepository.cs │ └── MemorySKUStatusRepository.cs │ ├── Models │ └── SKUStatus.cs │ ├── Program.cs │ ├── appsettings.json │ ├── Controllers │ └── SKUStatusController.cs │ ├── StatlerWaldorfCorp.EcommerceInventory.csproj │ └── Startup.cs └── wercker.yml /.gitignore: -------------------------------------------------------------------------------- 1 | project.lock.json 2 | *~ 3 | \#* 4 | bin 5 | obj 6 | .vscode/ 7 | -------------------------------------------------------------------------------- /docker_entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cd /pipeline/source/app/publish 3 | echo "Starting eCommerce Inventory Service" 4 | 5 | dotnet StatlerWaldorfCorp.EcommerceInventory.dll --server.urls=http://0.0.0.0:${PORT-"8080"} -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/Persistence/ISKUStatusRepository.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace StatlerWaldorfCorp.EcommerceInventory.Persistence 3 | { 4 | public interface ISKUStatusRepository 5 | { 6 | SKUStatus Get(int sku); 7 | SKUStatus Add(SKUStatus status); 8 | } 9 | } -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/Models/SKUStatus.cs: -------------------------------------------------------------------------------- 1 | namespace StatlerWaldorfCorp.EcommerceInventory 2 | { 3 | public class SKUStatus 4 | { 5 | public int SKU { get; set; } 6 | public int QtyOnHand { get; set; } 7 | public int QtyOnHold { get; set; } 8 | public int QtyAvail { get; set; } 9 | public int QtyBackOrdered { get; set; } 10 | } 11 | } -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.AspNetCore.Builder; 4 | using Microsoft.Extensions.Configuration; 5 | 6 | namespace StatlerWaldorfCorp.EcommerceInventory 7 | { 8 | public class Program 9 | { 10 | static void Main(string[] args) 11 | { 12 | IConfiguration config = new ConfigurationBuilder() 13 | .AddCommandLine(args) 14 | .Build(); 15 | 16 | var host = new WebHostBuilder() 17 | .UseKestrel() 18 | .UseStartup() 19 | .UseConfiguration(config) 20 | .Build(); 21 | 22 | host.Run(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "spring": { 3 | "application": { 4 | "name": "inventory" 5 | } 6 | }, 7 | "eureka": { 8 | "client": { 9 | "serviceUrl": "http://192.168.0.33:8080/eureka/", 10 | "shouldRegisterWithEureka": true, 11 | "shouldFetchRegistry": false, 12 | "validate_certificates": false 13 | }, 14 | "instance": { 15 | "appname": "inventory", 16 | "nonSecurePort": 5001, 17 | "port": 5001, 18 | "instanceId": "localhost:inventory:5001" 19 | } 20 | }, 21 | "Logging": { 22 | "IncludeScopes": false, 23 | "LogLevel": { 24 | "Default": "Debug", 25 | "System": "Debug", 26 | "Microsoft": "Debug", 27 | "Steeltoe": "Debug" 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/Controllers/SKUStatusController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Microsoft.AspNetCore.Mvc; 3 | using Microsoft.Extensions.Logging; 4 | using StatlerWaldorfCorp.EcommerceInventory.Persistence; 5 | 6 | namespace StatlerWaldorfCorp.EcommerceInventory.Controllers 7 | { 8 | [Route("api/skustatus")] 9 | public class SKUStatusController : Controller 10 | { 11 | private ISKUStatusRepository skuStatusRepository; 12 | 13 | private ILogger logger; 14 | 15 | public SKUStatusController(ISKUStatusRepository skuStatusRepository, ILogger logger) 16 | { 17 | this.skuStatusRepository = skuStatusRepository; 18 | this.logger = logger; 19 | } 20 | 21 | [HttpGet("{sku}")] 22 | public IActionResult Get(int sku) 23 | { 24 | logger.LogInformation("Handling request for SKU " + sku.ToString()); 25 | return this.Ok(this.skuStatusRepository.Get(sku)); 26 | } 27 | 28 | [HttpPut("{sku}")] 29 | public IActionResult Put(int sku, [FromBody]SKUStatus skuStatus) 30 | { 31 | return this.Ok(this.skuStatusRepository.Add(skuStatus)); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/Persistence/MemorySKUStatusRepository.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace StatlerWaldorfCorp.EcommerceInventory.Persistence 4 | { 5 | public class MemorySKUStatusRepository : ISKUStatusRepository 6 | { 7 | private Dictionary statuses; 8 | 9 | public MemorySKUStatusRepository() 10 | { 11 | this.statuses = new Dictionary(); 12 | 13 | 14 | statuses[123] = new SKUStatus 15 | { 16 | SKU = 123, 17 | QtyAvail = 5, 18 | QtyOnHand = 1, 19 | QtyBackOrdered = 0, 20 | QtyOnHold = 0 21 | }; 22 | statuses[456] = new SKUStatus 23 | { 24 | SKU = 456, 25 | QtyAvail = 30, 26 | QtyOnHand = 20, 27 | QtyBackOrdered = 10, 28 | QtyOnHold = 0 29 | }; 30 | } 31 | 32 | public SKUStatus Get(int sku) 33 | { 34 | return this.statuses[sku]; 35 | } 36 | 37 | public SKUStatus Add(SKUStatus status) 38 | { 39 | this.statuses.Add(status.SKU, status); 40 | return status; 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/StatlerWaldorfCorp.EcommerceInventory.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp1.1 5 | StatlerWaldorfCorp.EcommerceInventory 6 | Exe 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /wercker.yml: -------------------------------------------------------------------------------- 1 | box: microsoft/dotnet:1.1.1-sdk 2 | no-response-timeout: 10 3 | 4 | build: 5 | steps: 6 | - script: 7 | name: restore 8 | cwd: src/StatlerWaldorfCorp.EcommerceInventory 9 | code: | 10 | dotnet restore 11 | - script: 12 | name: build 13 | cwd: src/StatlerWaldorfCorp.EcommerceInventory 14 | code: | 15 | dotnet build 16 | # Packaging... 17 | 18 | - script: 19 | name: publish 20 | cwd: src/StatlerWaldorfCorp.EcommerceInventory 21 | code: | 22 | dotnet publish -o publish 23 | - script: 24 | name: copy binary 25 | cwd: src/StatlerWaldorfCorp.EcommerceInventory 26 | code: | 27 | cp -r . $WERCKER_OUTPUT_DIR/app 28 | - script: 29 | name: copy entrypoint 30 | code: | 31 | cp docker_entrypoint.sh $WERCKER_OUTPUT_DIR/app 32 | - script: 33 | name: copy config 34 | cwd: src/StatlerWaldorfCorp.EcommerceInventory 35 | code: | 36 | cp appsettings*json $WERCKER_OUTPUT_DIR/app/publish 37 | mkdir -p $WERCKER_OUTPUT_DIR/app/publish/app/tmp 38 | 39 | deploy: 40 | steps: 41 | - internal/docker-push: 42 | cwd: $WERCKER_OUTPUT_DIR/app 43 | username: $USERNAME 44 | password: $PASSWORD 45 | repository: dotnetcoreservices/ecommerce-inventory 46 | registry: https://registry.hub.docker.com 47 | entrypoint: "/pipeline/source/app/docker_entrypoint.sh" 48 | -------------------------------------------------------------------------------- /src/StatlerWaldorfCorp.EcommerceInventory/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.AspNetCore.Hosting; 3 | using Microsoft.Extensions.Configuration; 4 | using Microsoft.Extensions.DependencyInjection; 5 | using System; 6 | using Microsoft.Extensions.Logging; 7 | using System.Linq; 8 | using StatlerWaldorfCorp.EcommerceInventory.Persistence; 9 | using Steeltoe.Discovery.Client; 10 | 11 | namespace StatlerWaldorfCorp.EcommerceInventory 12 | { 13 | public class Startup 14 | { 15 | public IConfigurationRoot Configuration { get; } 16 | 17 | public Startup(IHostingEnvironment env, ILoggerFactory loggerFactory) 18 | { 19 | var builder = new ConfigurationBuilder() 20 | .SetBasePath(System.IO.Directory.GetCurrentDirectory()) 21 | .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true); 22 | 23 | Configuration = builder.Build(); 24 | 25 | loggerFactory.AddConsole(LogLevel.Information); 26 | loggerFactory.AddDebug(); 27 | } 28 | 29 | public void ConfigureServices(IServiceCollection services) 30 | { 31 | services.AddLogging(); 32 | services.AddMvc(); 33 | services.AddDiscoveryClient(Configuration); 34 | services.AddScoped(); 35 | } 36 | 37 | public void Configure(IApplicationBuilder app) 38 | { 39 | app.UseDiscoveryClient(); 40 | app.UseMvc(); 41 | } 42 | } 43 | } --------------------------------------------------------------------------------