Skip to content

Commit

Permalink
🔀 Merge pull request #6 from brunovicenteb/feature/view-details-by-day
Browse files Browse the repository at this point in the history
✨ Feature view details by day
  • Loading branch information
brunovicenteb authored Mar 16, 2023
2 parents 981b0f8 + f336434 commit 02aad41
Show file tree
Hide file tree
Showing 12 changed files with 19,059 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/Application/Interfaces/IMovementAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Mttechne.Application.Interfaces;
public interface IMovementAppService
{
Task<IEnumerable<MovementViewModel>> GetAllAsync();
Task<IEnumerable<MovementViewModel>> GetTodayMovimentationAsync();
Task<IEnumerable<MovementViewModel>> GetMovimentationFromDayAsync(DateTime date);
Task<IEnumerable<MovementTypeViewModel>> GetAllTypesAsync();
Task<IEnumerable<Tuple<DateTime, decimal, int>>> GetTotalizersAsync();
Task<MovementViewModel> GetByIdAsync(int id);
Expand Down
4 changes: 2 additions & 2 deletions src/Application/Services/MovementAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public async Task<IEnumerable<MovementViewModel>> GetAllAsync()
return ConvertToModel(entities);
}

public async Task<IEnumerable<MovementViewModel>> GetTodayMovimentationAsync()
public async Task<IEnumerable<MovementViewModel>> GetMovimentationFromDayAsync(DateTime date)
{
var entities = await _repository.GetTodayMovimentationAsync();
var entities = await _repository.GetMovimentationFromDayAsync(date);
return ConvertToModel(entities);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Domain/Interfaces/IMovementRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IMovementRepository : IBaseRepository<Movement>
{
Task<IEnumerable<MovementType>> GetAllTypesAsync();

Task<IEnumerable<Movement>> GetTodayMovimentationAsync();
Task<IEnumerable<Movement>> GetMovimentationFromDayAsync(DateTime date);

Task<IEnumerable<Tuple<DateTime, decimal, int>>> GetTotalizersAsync();
}
8,913 changes: 8,913 additions & 0 deletions src/Infra/Data/Migrations/20230316144308_CreateDatabase.Designer.cs

Large diffs are not rendered by default.

1,185 changes: 1,185 additions & 0 deletions src/Infra/Data/Migrations/20230316144308_CreateDatabase.cs

Large diffs are not rendered by default.

8,910 changes: 8,910 additions & 0 deletions src/Infra/Data/Migrations/MttechneContextModelSnapshot.cs

Large diffs are not rendered by default.

9 changes: 4 additions & 5 deletions src/Infra/Data/Repository/MovementRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,12 @@ public override async Task<IEnumerable<Movement>> GetAllAsync()
.Include(o => o.MovementType)
.ToListAsync();

public async Task<IEnumerable<Movement>> GetTodayMovimentationAsync()
public async Task<IEnumerable<Movement>> GetMovimentationFromDayAsync(DateTime date)
{
var today = DateTime.Today.Date;
return await Collection
.Where(b => !b.DeletedAt.HasValue && (b.CreatedAt.Value.Year == today.Year
&& b.CreatedAt.Value.Month == today.Month
&& b.CreatedAt.Value.Day == today.Day))
.Where(b => !b.DeletedAt.HasValue && (b.CreatedAt.Value.Year == date.Year
&& b.CreatedAt.Value.Month == date.Month
&& b.CreatedAt.Value.Day == date.Day))
.OrderByDescending(o => o.CreatedAt)
.AsNoTracking()
.Include(o => o.MovementType)
Expand Down
2 changes: 1 addition & 1 deletion src/Infra/IoC/NativeInjectorBootStrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IServiceCollection RegisterServices(this IServiceCollection servic
// Infra - Data
services.AddScoped<IMovementRepository, MovementRepository>();
services.AddDbContext<MttechneContext>(opt => opt.UseNpgsql(stringConnection));
services.AddHostedService(o => new RecreateDbHostedService<MttechneContext>(true, o));
services.AddHostedService(o => new RecreateDbHostedService<MttechneContext>(false, o));
return services;
}
}
23 changes: 20 additions & 3 deletions src/Presentation/Controllers/MovementController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@
using Mttechne.Application.ViewModel;
using Mttechne.Application.Interfaces;
using Microsoft.AspNetCore.Mvc.Rendering;
using Mttechne.Toolkit;
using System.Globalization;

namespace Mttechne.UI.Web.Controllers;

public class MovementController : Controller
{
private const string _RibbonElement = "message";
private const string _DefaultNewType = "Credit";
private const string _DateFormat = "MM-dd-yyyy";
private const string _MovementNotFound = "Movement not found.";
private const string _MovementNotDelete = "Could not delete movement from database.";
private const string _MovementNotInformed = "Movement not informed.";
private const string _MovementSaved = "Movement saved successfully.";
private const string _MovementRemoved = "Movement removed successfully.";
private const string _DefaultNewType = "Credit";
private const string _InformedDateInvalid = "The informed date are not valid. You was redirect to today movimentation.";

public MovementController(IMovementAppService service)
{
Expand All @@ -35,9 +39,22 @@ private void AddRibbonMessage(string message, TypeMessage typeMesage = TypeMessa
=> TempData[_RibbonElement] = MessageModel.Serialize(message, typeMesage);

[HttpGet]
public async Task<IActionResult> Index()
public async Task<IActionResult> Index(string date = null)
{
var movements = await _service.GetTodayMovimentationAsync();
DateTime concreteDate = DateTime.Now.Date;
if (date.IsFilled())
{
if (DateTime.TryParseExact(date, _DateFormat, null, DateTimeStyles.None, out DateTime result))
concreteDate = result;
else
{
AddRibbonError(_InformedDateInvalid);
return RedirectToAction(nameof(Index));
}
}
ViewBag.IsToday = concreteDate.Date == DateTime.Now.Date;
ViewBag.Subtitle = ViewBag.IsToday ? "Daily movement:" : $"Movement of {concreteDate:MM-dd-yyyy}:";
var movements = await _service.GetMovimentationFromDayAsync(concreteDate);
return View(movements);
}

Expand Down
1 change: 1 addition & 0 deletions src/Presentation/Views/Consolidate/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<td>@item.Item1.ToString("dd/MM/yyyy")</td>
<td>@item.Item3</td>
<td><strong><span class="@(@item.Item2 >= 0 ? "text-success": "text-danger")">@item.Item2.ToEnglishString()</span></strong></td>
<td><a asp-controller="Movement" asp-route-date="@item.Item1.ToString("MM-dd-yyyy")" class="btn btn-sm btn-primary"><i class="bi bi-search" title="Details"></i></a></td>
</tr>
}
</tbody>
Expand Down
30 changes: 20 additions & 10 deletions src/Presentation/Views/Movement/Index.cshtml
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
@using Mttechne.Toolkit;
@using Mttechne.Application.ViewModel;
@model IEnumerable<MovementViewModel>
@{
ViewBag.Subtitulo = "Daily movement:";
}

<header class="d-flex justify-content-between align-items-center">
<div>
<h1 class="text-primary"><i class="bi bi-cash-coin" title="Movement"></i> @ViewBag.Subtitulo <span class="@(@Model.Sum(o=>o.Value) >= 0 ? "text-success": "text-danger")">@Model.Sum(o=>o.Value).ToEnglishString()</span></h1>
</div>
<div>
<a asp-action="Create" class="btn btn-primary">New movement</a>
<h1 class="text-primary">
<i class="bi bi-cash-coin" title="Movement"></i> @ViewBag.Subtitle
<strong>
<span class="@(@Model.Sum(o=>o.Value) >= 0 ? "text-success": "text-danger")">@Model.Sum(o=>o.Value).ToEnglishString()</span>
</strong>
@if (!ViewBag.IsToday)
{
<small class="text-muted">[readonly]</small>
}
</h1>
</div>
@if (ViewBag.IsToday)
{
<div>
<a asp-action="Create" class="btn btn-primary">New movement</a>
</div>
}
</header>
<hr>

Expand All @@ -36,9 +45,10 @@
<td>@item.Description</td>
<td><strong><span class="@(item.Value >= 0 ? "text-success": "text-danger")">@item.Value.ToEnglishString()</span></strong></td>
<td>@item.CreatedAt.ToString("dd/MM/yyyy hh:mm tt")</td>
<td>
<a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-sm btn-danger"><i class="bi-trash" title="Delete"></i></a>
</td>
@if (ViewBag.IsToday)
{
<td><a asp-action="Delete" asp-route-id="@item.Id" class="btn btn-sm btn-danger"><i class="bi-trash" title="Delete"></i></a></td>
}
</tr>
}
</tbody>
Expand Down
6 changes: 1 addition & 5 deletions src/Toolkit/OutBox/Producer/RecreateDbHostedService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using Microsoft.Extensions.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.EntityFrameworkCore.Infrastructure;

namespace Mttechne.Toolkit.OutBox.Producer;

Expand Down Expand Up @@ -34,9 +32,7 @@ await Retry.Interval(20, TimeSpan.FromSeconds(3)).Retry(async () =>
_Context = scope.ServiceProvider.GetRequiredService<T>();
if (_ForceRecreate)
await _Context.Database.EnsureDeletedAsync(cancellationToken);
var creator = _Context.Database.GetService<IDatabaseCreator>() as RelationalDatabaseCreator;
if (!creator.Exists())
await _Context.Database.EnsureCreatedAsync(cancellationToken);
await _Context.Database.MigrateAsync(cancellationToken);
_Logger.Information("Migrations completed for {DbContext}", TypeCache<T>.ShortName);
}
catch (Exception ex)
Expand Down

0 comments on commit 02aad41

Please sign in to comment.