Skip to content
This repository was archived by the owner on Sep 24, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
obj/
.vscode/
*.binlog
*.binlog
BreweryFull/Brewery.MVC/beers.db
5 changes: 5 additions & 0 deletions BreweryFull/Brewery.MVC/Brewery.MVC.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,9 @@
<ProjectReference Include="..\Brewery.Shared\Brewery.Shared.csproj" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.0.0" />
</ItemGroup>

</Project>
56 changes: 0 additions & 56 deletions BreweryFull/Brewery.MVC/Controllers/BeerController.cs

This file was deleted.

66 changes: 66 additions & 0 deletions BreweryFull/Brewery.MVC/Controllers/BreweryAPIController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Brewery.Shared;
using System.Linq;
using Microsoft.EntityFrameworkCore;

namespace Brewery.MVC.Controllers
{
[Route("/api/breweries")]
public class BreweryAPIController : Controller
{
private readonly BreweryContext _breweryContext;
private readonly ILogger<BreweryAPIController> _logger;

public BreweryAPIController(ILogger<BreweryAPIController> logger, BreweryContext breweryContext)
{
_breweryContext = breweryContext;
_logger = logger;
}

[Route("")]
public IActionResult GetAllBreweries()
{
return Ok(_breweryContext.Breweries);
}

[Route("full")]
public IActionResult GetAllBreweriesFull()
{
// You return a list here, "not found" is not an issue -- an empty list is still a valid list.
return Ok(_breweryContext.Breweries
.Include(brewery => brewery.Beers).ThenInclude(beer => beer.BeerType)
.Include(brewery => brewery.Owner)
);
}

[Route("{id}")]
public IActionResult GetBrewery(int id)
{
// Either you find the brewery or not. If you don't find your resource return a 404 (as per https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
var brewery = _breweryContext.Breweries.FirstOrDefault(x => x.Id == id);
return brewery == default(Shared.Brewery) ? (IActionResult)NotFound() : Ok(brewery);
}

[Route("{id}/beers")]
public IActionResult GetBreweryBeers(int id)
{
// if you don't find the brewery, return a 404. Again, an empty list is an empty list so empty list of beer is a valid result.
var brewery = _breweryContext.Breweries
.Include(brewery => brewery.Beers)
.FirstOrDefault(x => x.Id == id);
return brewery == default(Shared.Brewery) ? (IActionResult)NotFound() : Ok(brewery.Beers);
}


[Route("{breweryId}/beers/{beerId}")]
public IActionResult GetBeerDetails(int breweryId, int beerId)
{
// this can return two kinds of 404's; one for the non-existing brewery and one for the non-existing beer.
var beer = _breweryContext.Beers
.Include(beer => beer.BeerType)
.FirstOrDefault(x => x.BreweryId == breweryId && x.Id == beerId);
return beer == default(Shared.Beer) ? (IActionResult)NotFound() : Ok(beer);
}
}
}
37 changes: 0 additions & 37 deletions BreweryFull/Brewery.MVC/Controllers/HomeController.cs

This file was deleted.

53 changes: 0 additions & 53 deletions BreweryFull/Brewery.MVC/Models/BeerDatabase.cs

This file was deleted.

11 changes: 0 additions & 11 deletions BreweryFull/Brewery.MVC/Models/ErrorViewModel.cs

This file was deleted.

88 changes: 47 additions & 41 deletions BreweryFull/Brewery.MVC/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,62 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Brewery.Shared;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace Brewery.MVC
{
public class Startup
public class Startup
{
public Startup(IConfiguration configuration)
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
services.AddDbContext<BreweryContext>(options => options.UseSqlite(Configuration.GetConnectionString("BeerContext")));
services.AddScoped<IDatabaseInitializer, DatabaseInitializer>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IDatabaseInitializer databaseInitializer)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});

databaseInitializer.Initialize();
}
}
}
10 changes: 0 additions & 10 deletions BreweryFull/Brewery.MVC/Views/Beer/Delete.cshtml

This file was deleted.

16 changes: 0 additions & 16 deletions BreweryFull/Brewery.MVC/Views/Beer/Detail.cshtml

This file was deleted.

18 changes: 0 additions & 18 deletions BreweryFull/Brewery.MVC/Views/Beer/Index.cshtml

This file was deleted.

Loading