-
Notifications
You must be signed in to change notification settings - Fork 0
/
CustomerController.cs
57 lines (50 loc) · 1.64 KB
/
CustomerController.cs
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
using System;
using System.Collections.Generic;
using Store.Domain.StoreContext.CustomerCommands.Inputs;
using Store.Domain.StoreContext.Handlers;
using Store.Domain.StoreContext.Queries;
using Store.Domain.StoreContext.Repositories;
using Store.Shared.Commands;
using Microsoft.AspNetCore.Mvc;
namespace Store.Api.Controllers
{
public class CustomerController : Controller
{
private readonly ICustomerRepository _repository;
private readonly CustomerHandler _handler;
public CustomerController(ICustomerRepository repository, CustomerHandler handler)
{
_repository = repository;
_handler = handler;
}
[HttpGet]
[Route("v1/customers")]
[ResponseCache(Duration = 15)]
public IEnumerable<ListCustomerQueryResult> Get() => _repository.Get();
[HttpGet]
[Route("v1/customers/{id}")]
public GetCustomerQueryResult GetById(Guid id)
{
return _repository.Get(id);
}
[HttpGet]
[Route("v2/customers/{document}")]
public GetCustomerQueryResult GetByDocument(Guid document)
{
return _repository.Get(document);
}
[HttpGet]
[Route("v1/customers/{id}/orders")]
public IEnumerable<ListCustomerOrdersQueryResult> GetOrders(Guid id)
{
return _repository.GetOrders(id);
}
[HttpPost]
[Route("v1/customers")]
public ICommandResult Post([FromBody]CreateCustomerCommand command)
{
var result = (CreateCustomerCommandResult)_handler.Handle(command);
return result;
}
}
}