Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
jSylvestre committed Mar 8, 2024
1 parent f8b4ee1 commit 7f99330
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 5 deletions.
10 changes: 6 additions & 4 deletions Sloth.Web/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ public async Task<IActionResult> FailedTransactions()
return View("FailedTransactions", model);
}

[Route("{team}/reports/downloadabletransactions/{filter?}")]
[HttpGet]
public async Task<IActionResult> DownloadableTransactions(TransactionsFilterModel filter = null)
{
if (string.IsNullOrWhiteSpace(TeamSlug))
Expand All @@ -76,19 +78,19 @@ public async Task<IActionResult> DownloadableTransactions(TransactionsFilterMode
if (filter == null)
filter = new TransactionsFilterModel();

filter.From = filter.From = new DateTime(2023, 10, 12);
filter.To = filter.To = new DateTime(2023, 10, 15);

FilterHelpers.SanitizeTransactionsFilter(filter);

var model = new TransfersReportViewModel
{
filter = filter,
Filter = filter,
};

model.Transactions = await DbContext.Transactions.Include(a => a.Transfers).Include(a => a.Metadata)
.Where(t => t.Source.Team.Slug == TeamSlug && t.TransactionDate >= filter.From && t.TransactionDate <= filter.To).Select(TransactionWithTransfers.Projection()).ToListAsync();

var team = await DbContext.Teams.FirstAsync(t => t.Slug == TeamSlug);
ViewBag.Title = $"Transactions with Transfers - {team.Name}";

return View(model);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Sloth.Web.Models.ReportViewModels
{
public class TransfersReportViewModel
{
public TransactionsFilterModel filter { get; set; }
public TransactionsFilterModel Filter { get; set; }

public IList<TransactionWithTransfers> Transactions { get; set; }
}
Expand Down
2 changes: 2 additions & 0 deletions Sloth.Web/Sloth.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.16" />

<PackageReference Include="Serilog" Version="2.11.0" />
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
Expand Down
13 changes: 13 additions & 0 deletions Sloth.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,19 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

app.UseEndpoints(routes =>
{

//A team specific reports route (needed because this report has a filter)
//I replaced this with a route on the action
//routes.MapControllerRoute(
// name: "team-report-downloadable-transactions",
// pattern: "{team}/reports/downloadabletransactions",
// defaults: new { controller = "Reports", action = "DownloadableTransactions" },
// constraints: new
// {
// team = new CompositeRouteConstraint(new IRouteConstraint[] {
// new RegexInlineRouteConstraint(Team.SlugRegex),
// })
// });
// non team root routes
routes.MapControllerRoute(
name: "non-team-routes",
Expand Down
33 changes: 33 additions & 0 deletions Sloth.Web/Views/Reports/DownloadableTransactions.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@model Sloth.Web.Models.ReportViewModels.TransfersReportViewModel

@using Microsoft.AspNetCore.Http
@using Microsoft.AspNetCore.Routing
@inject IHttpContextAccessor HttpContextAccessor
@{
var teamSlug = HttpContextAccessor.HttpContext.GetRouteData().Values["team"] as string;
}


<div class="container">
<h2>@ViewBag.Title</h2>

<h3>Filters</h3>
<form class="row" id="transactionFilterForm" asp-controller="Reports" asp-action="DownloadableTransactions" method="get">
<div class="row justify-content-between filters-wrapper">
<div class="col-8 col-md-5">
<div id="filter-date-range" class="input-group">
<input name="from" type="text" class="form-control" placeholder="MM/DD/YYYY" asp-for="Filter.From" asp-format="{0:MM/dd/yyyy}" aria-label="" />
<span class="input-group-text">to</span>
<input name="to" type="text" class="form-control" placeholder="MM/DD/YYYY" asp-for="Filter.To" asp-format="{0:MM/dd/yyyy}" aria-label="" />
</div>

<button type="submit" class="btn btn-link mt-1">Apply filter</button>
</div>

</div>
</form>
<div>@teamSlug</div>

<div>@Model.Transactions.Count</div>

</div>

0 comments on commit 7f99330

Please sign in to comment.