-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBreweryController.cs
More file actions
78 lines (69 loc) · 2.05 KB
/
BreweryController.cs
File metadata and controls
78 lines (69 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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);
}
}
}