MongoDB repository service implementation for Trading Position Modeler.
- General Tooling
- Configurations
- Coding Standards
- Solutions
- Projects
- Building
- Package & Deployment
- Versioning
dotnet add package TradingToolbox.Trading.Modeler.Data.NoSql.MongoDB.Services
Note
For complete usage, see TradingToolbox.Applications.Trading.Modeler.ServiceApp
namespace TradingToolbox.Applications.Trading.Modeler.ServiceApp.Controllers
{
/// <summary>
/// Controller for trading position modeling.
/// </summary>
/// <seealso cref="Microsoft.AspNetCore.Mvc.ControllerBase" />
[ApiController]
[Route("api/tradingtoolbox/trading/[controller]")]
public class ModelerController : ControllerBase
{
private readonly IMongoDbService _mongoDbService;
/// <summary>
/// Initializes a new instance of the <see cref="ModelerController" /> class.
/// </summary>
/// <param name="mongoDbService">The mongo database service to do DB operstaions.</param>
public ModelerController(IMongoDbService mongoDbService)
{
_mongoDbService = mongoDbService;
}
/// <summary>
/// Gets all of the position documents from the DB
/// </summary>
/// <returns>List of position documents.</returns>
[HttpGet("positions")]
public async Task<IActionResult> GetAll()
{
IEnumerable<PositionModelDocument> items = new List<PositionModelDocument>();
try
{
// For now, just force sort to be by ListPosition and do here...can move to FindAsync later...
// TODO - Add sort capability to FindAsync in TeqBench.System.Data.NoSql.MongoDb.Repository
items = (await _mongoDbService.PositionModelRepository.FindAsync(_ => true)).OrderBy(item => item.ListPosition);
}
catch (Exception e)
{
return StatusCode(StatusCodes.Status500InternalServerError, e);
}
return Ok(items);
}
}
}