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
30 changes: 30 additions & 0 deletions BrewABear/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
42 changes: 42 additions & 0 deletions BrewABear/.github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Deploy app

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
-
name: Checkout
uses: actions/checkout@v3

-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASS }}

-
name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/brewabear:latest
file: Api/Dockerfile
-
name: Publish image to webapp
uses: azure/webapps-deploy@v2
with:
app-name: 'brewabear'
publish-profile: ${{ secrets.PublishProfile }}
images: 'docker.io/riebisv/brewabear:latest'
28 changes: 28 additions & 0 deletions BrewABear/.github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will build a .NET project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net

name: .NET

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
22 changes: 22 additions & 0 deletions BrewABear/Api/Api.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>1bebeb90-e52a-4370-a1c0-b9e82fc3e99d</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Application\Application.csproj" />
<ProjectReference Include="..\Data\Data.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions BrewABear/Api/Api.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@Api_HostAddress = http://localhost:5142

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

###
108 changes: 108 additions & 0 deletions BrewABear/Api/Controllers/BrewerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using Api.Services;
using Application.Commands.BrewerCommands;
using Application.DTOs;
using Application.Exceptions;
using Application.Queries.BrewerQueries;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers;
[Route("api/[controller]")]
[ApiController]
public class BrewerController(IMediator mediator, IExceptionHandlerService exceptionHandler) : ControllerBase
{
private readonly IMediator _mediator = mediator;
private readonly IExceptionHandlerService _exceptionHandler = exceptionHandler;

[HttpGet]
[Route("{id}/Beers")]
[ProducesResponseType<IList<BrewerDto>>(200)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult<IList<BeerDto>>> Beers(string id)
{
try
{
var beers = await _mediator.Send(new GetAllBeersByBrewerQuery(id));

return Ok(beers);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}

[HttpGet]
[Route("{id}/Details")]
[ProducesResponseType<BrewerDto>(200)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult<BrewerDto>> Details(string id)
{
try
{
var brewer = await _mediator.Send(new GetBrewerDetailsQuery(id));

return Ok(brewer);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}

[HttpPost]
[Route("{id}/AddBeer")]
[ProducesResponseType<BeerDto>(200)]
[ProducesResponseType<ErrorDto>(400)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult<BeerDto>> AddBeer(string id, BeerCreateDto beerCreateDto)
{
try
{
var newBeer = await _mediator.Send(new CreateBeerCommand(id, beerCreateDto));

return Ok(newBeer);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}

[HttpPut]
[Route("{id}/UpdateBeer")]
[ProducesResponseType<BeerDto>(200)]
[ProducesResponseType<ErrorDto>(400)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult<BeerDto>> UpdateBeer(string id, string beerId, BeerCreateDto beerCreateDto)
{
try
{
var updatedBeer = await _mediator.Send(new UpdateBeerCommand(id, beerId, beerCreateDto));

return Ok(updatedBeer);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}

[HttpDelete]
[Route("{id}/DeleteBeer")]
[ProducesResponseType(200)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult> DeleteBeer(string id, string beerId)
{
try
{
await _mediator.Send(new DeleteBeerCommand(id, beerId));

return Ok();
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}
}
78 changes: 78 additions & 0 deletions BrewABear/Api/Controllers/BreweryController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using Api.Services;
using Application.DTOs;
using Application.Exceptions;
using Application.Queries.BreweryQueries;
using MediatR;
using Microsoft.AspNetCore.Mvc;

namespace Api.Controllers;
[Route("api/[controller]")]
[ApiController]
public class BreweryController(IMediator mediator, IExceptionHandlerService exceptionHandler) : ControllerBase
{
private readonly IMediator _mediator = mediator;
private readonly IExceptionHandlerService _exceptionHandler = exceptionHandler;

[HttpGet]
[Route("All")]
public async Task<IList<BreweryDto>> All()
{
var breweries = await _mediator.Send(new GetAllBreweriesQuery());

return breweries;
}

[HttpGet]
[Route("{id}/Details")]
[ProducesResponseType<BreweryDto>(200)]
[ProducesResponseType<EmptyResult>(404)]
public async Task<ActionResult<BreweryDto>> Details(string id)
{
try
{
var brewery = await _mediator.Send(new GetBreweryDetailsQuery(id));

return Ok(brewery);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}

[HttpGet]
[Route("{id}/Beers")]
[ProducesResponseType<IList<BeerDto>>(200)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult<IList<BeerDto>>> Beers(string id)
{
try
{
var beers = await _mediator.Send(new GetAllBeersInBreweryQuery(id));

return Ok(beers);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}

[HttpGet]
[Route("{id}/Brewers")]
[ProducesResponseType<IList<BrewerDto>>(200)]
[ProducesResponseType<ErrorDto>(404)]
public async Task<ActionResult<IList<BrewerDto>>> Brewers(string id)
{
try
{
var brewers = await _mediator.Send(new GetAllBrewersInBreweryQuery(id));

return Ok(brewers);
}
catch (Exception ex)
{
return _exceptionHandler.HandleException(ex);
}
}
}
Loading