-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Opentelemetry draft * add Metrics * contract metrics * enable metrics * fix * Working opentelemetry tracing * Renames * Tracing updates * Fix sample * Updates * removed comment * removed recordException option * Fix appsettings secrets * Fixes * Removed comment * Versions Co-authored-by: Lucian Ghinet <[email protected]>
- Loading branch information
Showing
54 changed files
with
1,367 additions
and
993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 74 additions & 70 deletions
144
samples/MicroServices/NBB.Contracts/NBB.Contracts.Api/Controllers/ContractsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,78 @@ | ||
// Copyright (c) TotalSoft. | ||
// This source code is licensed under the MIT license. | ||
|
||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using NBB.Contracts.PublishedLanguage; | ||
using NBB.Contracts.ReadModel; | ||
using NBB.Messaging.Abstractions; | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBB.Contracts.Api.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ContractsController : Controller | ||
{ | ||
private readonly IQueryable<ContractReadModel> _contractReadModelQuery; | ||
private readonly IMessageBusPublisher _messageBusPublisher; | ||
|
||
public ContractsController(IMessageBusPublisher messageBusPublisher, IQueryable<ContractReadModel> contractReadModelQuery) | ||
{ | ||
_messageBusPublisher = messageBusPublisher; | ||
_contractReadModelQuery = contractReadModelQuery; | ||
} | ||
|
||
|
||
// GET api/contracts | ||
[HttpGet] | ||
public async Task<IActionResult> Get() | ||
{ | ||
var query = await _contractReadModelQuery.ToListAsync(); | ||
return Ok(query.ToList()); | ||
} | ||
|
||
// GET api/contracts/7327223E-22EA-48DC-BC44-FFF6AB3B9489 | ||
[HttpGet("{id}")] | ||
public async Task<IActionResult> Get(Guid id) | ||
{ | ||
//var contract = await _contractReadModelRepository.GetFirstOrDefaultAsync(x=> x.ContractId == id, "ContractLines"); | ||
var contract = await _contractReadModelQuery | ||
.Include(x=> x.ContractLines) | ||
.SingleOrDefaultAsync(x => x.ContractId == id, CancellationToken.None); | ||
|
||
if (contract != null) | ||
return Ok(contract); | ||
|
||
return NotFound(); | ||
} | ||
|
||
// POST api/contracts | ||
[HttpPost] | ||
public Task Post([FromBody]CreateContract command, CancellationToken cancellationToken) | ||
{ | ||
return _messageBusPublisher.PublishAsync(command, cancellationToken); | ||
} | ||
|
||
// POST api/contracts/7327223E-22EA-48DC-BC44-FFF6AB3B9489/lines | ||
[HttpPost("{id}/lines")] | ||
public Task Post([FromBody]AddContractLine command, CancellationToken cancellationToken) | ||
{ | ||
return _messageBusPublisher.PublishAsync(command, cancellationToken); | ||
} | ||
|
||
// POST api/contracts/7327223E-22EA-48DC-BC44-FFF6AB3B9489/validate | ||
[HttpPost("{id}/validate")] | ||
public Task Post([FromBody]ValidateContract command, CancellationToken cancellationToken) | ||
{ | ||
return _messageBusPublisher.PublishAsync(command, cancellationToken); | ||
} | ||
|
||
} | ||
} | ||
using NBB.Contracts.ReadModel; | ||
using NBB.Messaging.Abstractions; | ||
using System; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace NBB.Contracts.Api.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
public class ContractsController : Controller | ||
{ | ||
private readonly IQueryable<ContractReadModel> _contractReadModelQuery; | ||
private readonly ILogger<ContractsController> _logger; | ||
private readonly IMessageBusPublisher _messageBusPublisher; | ||
|
||
public ContractsController(IMessageBusPublisher messageBusPublisher, IQueryable<ContractReadModel> contractReadModelQuery, ILogger<ContractsController> logger) | ||
{ | ||
_messageBusPublisher = messageBusPublisher; | ||
_contractReadModelQuery = contractReadModelQuery; | ||
_logger = logger; | ||
} | ||
|
||
|
||
// GET api/contracts | ||
[HttpGet] | ||
public async Task<IActionResult> Get() | ||
{ | ||
var query = await _contractReadModelQuery.ToListAsync(); | ||
return Ok(query.ToList()); | ||
} | ||
|
||
// GET api/contracts/7327223E-22EA-48DC-BC44-FFF6AB3B9489 | ||
[HttpGet("{id}")] | ||
public async Task<IActionResult> Get(Guid id) | ||
{ | ||
//var contract = await _contractReadModelRepository.GetFirstOrDefaultAsync(x=> x.ContractId == id, "ContractLines"); | ||
var contract = await _contractReadModelQuery | ||
.Include(x=> x.ContractLines) | ||
.SingleOrDefaultAsync(x => x.ContractId == id, CancellationToken.None); | ||
|
||
if (contract != null) | ||
return Ok(contract); | ||
|
||
return NotFound(); | ||
} | ||
|
||
// POST api/contracts | ||
[HttpPost] | ||
public Task Post([FromBody]CreateContract command, CancellationToken cancellationToken) | ||
{ | ||
return _messageBusPublisher.PublishAsync(command, cancellationToken); | ||
} | ||
|
||
// POST api/contracts/7327223E-22EA-48DC-BC44-FFF6AB3B9489/lines | ||
[HttpPost("{id}/lines")] | ||
public Task Post([FromBody]AddContractLine command, CancellationToken cancellationToken) | ||
{ | ||
return _messageBusPublisher.PublishAsync(command, cancellationToken); | ||
} | ||
|
||
// POST api/contracts/7327223E-22EA-48DC-BC44-FFF6AB3B9489/validate | ||
[HttpPost("{id}/validate")] | ||
public Task Post([FromBody]ValidateContract command, CancellationToken cancellationToken) | ||
{ | ||
_logger.LogInformation("Validating contract"); | ||
return _messageBusPublisher.PublishAsync(command, cancellationToken); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.