Skip to content
Open
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
63 changes: 63 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
###############################################################################
# Set default behavior to automatically normalize line endings.
###############################################################################
* text=auto

###############################################################################
# Set default behavior for command prompt diff.
#
# This is need for earlier builds of msysgit that does not have it on by
# default for csharp files.
# Note: This is only used by command line
###############################################################################
#*.cs diff=csharp

###############################################################################
# Set the merge driver for project and solution files
#
# Merging from the command prompt will add diff markers to the files if there
# are conflicts (Merging from VS is not affected by the settings below, in VS
# the diff markers are never inserted). Diff markers may cause the following
# file extensions to fail to load in VS. An alternative would be to treat
# these files as binary and thus will always conflict and require user
# intervention with every merge. To do so, just uncomment the entries below
###############################################################################
#*.sln merge=binary
#*.csproj merge=binary
#*.vbproj merge=binary
#*.vcxproj merge=binary
#*.vcproj merge=binary
#*.dbproj merge=binary
#*.fsproj merge=binary
#*.lsproj merge=binary
#*.wixproj merge=binary
#*.modelproj merge=binary
#*.sqlproj merge=binary
#*.wwaproj merge=binary

###############################################################################
# behavior for image files
#
# image files are treated as binary by default.
###############################################################################
#*.jpg binary
#*.png binary
#*.gif binary

###############################################################################
# diff behavior for common document formats
#
# Convert binary document formats to text before diffing them. This feature
# is only available from the command line. Turn it on by uncommenting the
# entries below.
###############################################################################
#*.doc diff=astextplain
#*.DOC diff=astextplain
#*.docx diff=astextplain
#*.DOCX diff=astextplain
#*.dot diff=astextplain
#*.DOT diff=astextplain
#*.pdf diff=astextplain
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs

FrontEnd\BreweryAppAngular\.angular\cache\

# Mono auto generated files
mono_crash.*

Expand Down Expand Up @@ -475,3 +477,4 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk
/FrontEnd/BreweryAppAngular/.angular/cache/17.0.6
26 changes: 26 additions & 0 deletions Brewery/BreweryApi.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<InvariantGlobalization>false</InvariantGlobalization>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.QuickGrid.EntityFrameworkAdapter" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.SqlServer.Server" Version="1.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Brewery/BreweryApi.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@BreweryApi_HostAddress = http://localhost:5099

GET {{BreweryApi_HostAddress}}/weatherforecast/
Accept: application/json

###
96 changes: 96 additions & 0 deletions Brewery/Controllers/BeersController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using BreweryApi.Models;
using BreweryApi.Models.DTOs;
using BreweryApi.Services;

namespace BreweryApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BeersController : ControllerBase
{
private readonly BeerService _beerService;

public BeersController(BeerService beerService)
{
_beerService = beerService;
}

// GET: api/Beers
[HttpGet]
public async Task<ActionResult<IEnumerable<BeerDTO>>> GetBeer()
{
return _beerService.GetBeers();
}

// GET: api/Beers/5
[HttpGet("{id}")]
public async Task<ActionResult<BeerDTO>> GetBeer(int id)
{
var result = _beerService.GetBeerDTO(id);

if ( result == null) { return NotFound(); }

return result;

}

// PUT: api/Beers/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutBeer(int id, Beer beer)
{
if (id != beer.Id)
{
return BadRequest();
}

_beerService.UpdateBeer(beer);

try
{
_beerService.SaveDb();
}
catch (DbUpdateConcurrencyException)
{
if (!_beerService.BeerExsists(id))
{
return NotFound();
}
else
{
throw;
}
}

return NoContent();
}

// POST: api/Beers
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Beer>> PostBeer(Beer beer)
{
_beerService.InsertBeer(beer);

return CreatedAtAction(nameof(GetBeer), new { id = beer.Id }, beer);
}

// DELETE: api/Beers/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteBeer(int id)
{
var beer = _beerService.GetBeer(id);

if (beer == null)
{
return NotFound();
}

_beerService.DeleteBeer(beer);

return NoContent();
}
}
}
97 changes: 97 additions & 0 deletions Brewery/Controllers/BreweriesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
using BreweryApi.Models;
using BreweryApi.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace BreweryApi.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class BreweriesController : ControllerBase
{
private BreweryService _breweryService;

public BreweriesController( BreweryService breweryService )
{
_breweryService = breweryService;
}

// GET: api/Breweries
[HttpGet]
public async Task<ActionResult<IEnumerable<Brewery>>> GetBrewery()
{
return _breweryService.GetBreweries();
}

// GET: api/Breweries/5
[HttpGet("{id}")]
public async Task<ActionResult<Brewery>> GetBrewery(int id)
{
var brewery = _breweryService.GetBrewery(id);

if (brewery == null)
{
return NotFound();
}

return brewery;
}

// PUT: api/Breweries/5
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPut("{id}")]
public async Task<IActionResult> PutBrewery(int id, Brewery brewery)
{
if (id != brewery.Id)
{
return BadRequest();
}

_breweryService.UpdateBrewery(brewery);

try
{
_breweryService.SaveDb();
}
catch (DbUpdateConcurrencyException)
{
if (!_breweryService.BreweryExsists(id))
{
return NotFound();
}
else
{
throw;
}
}

return NoContent();
}

// POST: api/Breweries
// To protect from overposting attacks, see https://go.microsoft.com/fwlink/?linkid=2123754
[HttpPost]
public async Task<ActionResult<Brewery>> PostBrewery(Brewery brewery)
{
_breweryService.InsertBrewery(brewery);

return CreatedAtAction("GetBrewery", new { id = brewery.Id }, brewery);
}

// DELETE: api/Breweries/5
[HttpDelete("{id}")]
public async Task<IActionResult> DeleteBrewery(int id)
{
var brewery = _breweryService.GetBrewery(id);

if (brewery == null)
{
return NotFound();
}

_breweryService.DeleteBrewery(brewery);

return NoContent();
}
}
}
Loading