-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathEventStoreController.cs
More file actions
62 lines (54 loc) · 2.33 KB
/
EventStoreController.cs
File metadata and controls
62 lines (54 loc) · 2.33 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
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Duber.Trip.API.Infrastructure.Repository;
using OpenCqrs.Store.Cosmos.Mongo.Documents;
using Microsoft.AspNetCore.Mvc;
namespace Duber.Trip.API.Controllers
{
[Route("api/v1/[controller]")]
public class EventStoreController : Controller
{
private readonly IEventStoreRepository _repository;
public EventStoreController(IEventStoreRepository repository)
{
_repository = repository ?? throw new ArgumentNullException(nameof(repository));
}
/// <summary>
/// Returns all of the Aggregates
/// </summary>
/// <returns>Returns all of the Aggregates</returns>
/// <response code="200">Returns a list of AggregateDocument object.</response>
[HttpGet("aggregates")]
[ProducesResponseType(typeof(IEnumerable<AggregateDocument>), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetAggreagates()
{
var aggregates = await _repository.GetAggregatesAsync();
if (aggregates == null)
return NotFound();
return Ok(aggregates);
}
/// <summary>
/// Returns all events that matches with the specified aggregate id.
/// </summary>
/// <param name="aggregateId"></param>
/// <returns>Returns all events that matches with the specified aggregate id.</returns>
/// <response code="200">Returns a list of EventDocument object.</response>
[HttpGet("aggregates/{aggregateId}/events")]
[ProducesResponseType(typeof(IEnumerable<EventDocument>), (int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.NotFound)]
[ProducesResponseType((int)HttpStatusCode.BadRequest)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetEventsByAggregate(Guid aggregateId)
{
var events = await _repository.GetEventsAsync(aggregateId);
if (events == null)
return NotFound();
return Ok(events);
}
}
}