Skip to content

Commit e60e65a

Browse files
authored
Merge pull request dotnet-architecture#1 from CESARDELATORRE/glennc
some initial dockerfiles and catalog work. Proof of concept more than…
2 parents 4a20329 + 9dd6263 commit e60e65a

32 files changed

Lines changed: 324 additions & 568 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,4 @@ paket-files/
250250
# JetBrains Rider
251251
.idea/
252252
*.sln.iml
253+
pub/

NuGet.config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="AspNetCore" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
5+
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
6+
</packageSources>
7+
</configuration>

build.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
#dotnet restore
3+
rm -rf ./pub
4+
dotnet publish "$(pwd)/src/Services/Catalog/Catalog.API/project.json" -o "$(pwd)/pub/catalog"
5+
dotnet publish "$(pwd)/src/Web/Microsoft.eShopOnContainers.WebMVC/project.json" -o "$(pwd)/pub/webMVC"
6+
7+
docker build -t eshop/web "$(pwd)/pub/webMVC"
8+
docker build -t eshop/catalog.api "$(pwd)/pub/catalog"

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
version: '2'
2+
3+
services:
4+
webmvc:
5+
image: eshop/web
6+
environment:
7+
- CatalogUrl=http://catalog.api
8+
ports:
9+
- "80:80"
10+
depends_on:
11+
- catalog.api
12+
catalog.api:
13+
image: eshop/catalog.api
14+
environment:
15+
- ConnectionString=Server=catalogdata;Port=5432;Database=postgres;username=postgres
16+
expose:
17+
- "80"
18+
depends_on:
19+
- catalogdata
20+
catalogdata:
21+
image: glennc/eshopdata

eShopOnContainers.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{932D8224-11F
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{3AF739CD-81D8-428D-A08A-0A58372DEBF6}"
99
ProjectSection(SolutionItems) = preProject
10+
docker-compose.yml = docker-compose.yml
1011
global.json = global.json
12+
NuGet.config = NuGet.config
1113
EndProjectSection
1214
EndProject
1315
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Services", "Services", "{91CF7717-08AB-4E65-B10E-0B426F01E2E8}"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Mvc;
6+
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
7+
8+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Controllers
9+
{
10+
[Route("/")]
11+
public class CatalogController : ControllerBase
12+
{
13+
private CatalogContext _context;
14+
15+
public CatalogController(CatalogContext context)
16+
{
17+
_context = context;
18+
}
19+
20+
// GET api/values
21+
[HttpGet]
22+
public IEnumerable<CatalogItem> Get()
23+
{
24+
return _context.CatalogItems.ToList();
25+
}
26+
27+
// GET api/values/5
28+
[HttpGet("{id}")]
29+
public IActionResult Get(Guid id)
30+
{
31+
var item = _context.CatalogItems.FirstOrDefault(x=> x.Id == id);
32+
33+
if(item == null)
34+
{
35+
return NotFound();
36+
}
37+
38+
return new OkObjectResult(item);
39+
}
40+
41+
// POST api/values
42+
[HttpPost]
43+
public IActionResult Post([FromBody]CatalogItem item)
44+
{
45+
try
46+
{
47+
_context.CatalogItems.Add(item);
48+
_context.SaveChanges();
49+
return Ok();
50+
}
51+
catch
52+
{
53+
return StatusCode(500, "Unable to add new catalog item");
54+
}
55+
}
56+
57+
// PUT api/values/5
58+
[HttpPut("{id}")]
59+
public IActionResult Put(int id, [FromBody]CatalogItem item)
60+
{
61+
_context.CatalogItems.Update(item);
62+
_context.SaveChanges();
63+
return Ok();
64+
}
65+
66+
// DELETE api/values/5
67+
[HttpDelete("{id}")]
68+
public IActionResult Delete(Guid id)
69+
{
70+
return Ok();
71+
}
72+
}
73+
}

src/Services/Catalog/Catalog.API/Controllers/ValuesController.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM microsoft/aspnetcore
2+
WORKDIR /app
3+
EXPOSE 80
4+
ADD . /app
5+
ENTRYPOINT dotnet Catalog.API.dll
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using Npgsql.EntityFrameworkCore.PostgreSQL;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
9+
{
10+
public class CatalogContext : DbContext
11+
{
12+
public CatalogContext(DbContextOptions options): base(options)
13+
{
14+
}
15+
16+
public DbSet<CatalogItem> CatalogItems { get; set; }
17+
18+
protected override void OnModelCreating(ModelBuilder builder)
19+
{
20+
builder.HasPostgresExtension("uuid-ossp");
21+
}
22+
}
23+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Microsoft.eShopOnContainers.Services.Catalog.API.Model
7+
{
8+
public class CatalogItem
9+
{
10+
public CatalogItem()
11+
{
12+
}
13+
14+
public Guid Id { get; set; }
15+
public string Name { get; set; }
16+
public string Description { get; set; }
17+
public decimal Price { get; set; }
18+
public int ImageCount { get; set; }
19+
}
20+
}

0 commit comments

Comments
 (0)