Skip to content

Commit

Permalink
Improve code
Browse files Browse the repository at this point in the history
  • Loading branch information
andreapier committed Oct 2, 2024
1 parent 02ae94e commit 867ea48
Show file tree
Hide file tree
Showing 23 changed files with 59 additions and 71 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Net;
using System.Threading.Tasks;

namespace CappannaHelper.Api.Common.ErrorManagement
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace CappannaHelper.Api.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class AccountController : Controller
public class AccountController : ControllerBase
{
private readonly IApplicationUserManager _userManager;
private readonly IApplicationSignInManager _signInManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace CappannaHelper.Api.Controllers
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class DashboardController : Controller
public class DashboardController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly IShiftManager _shiftManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace CappannaHelper.Api.Controllers
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class MenuDetailController : Controller
public class MenuDetailController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly IHubContext<ChHub> _hub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace CappannaHelper.Api.Controllers
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class NotificationController : Controller
public class NotificationController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly IShiftManager _shiftManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;

namespace CappannaHelper.Api.Controllers
{
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class OrderController : Controller
public class OrderController : ControllerBase
{
private readonly ApplicationDbContext _context;
private readonly IPrintService _printService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using CappannaHelper.Api.Hubs;
using CappannaHelper.Api.Hubs;
using CappannaHelper.Api.Models;
using CappannaHelper.Api.Persistence;
using CappannaHelper.Api.Persistence.Modelling;
Expand All @@ -11,6 +7,10 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace CappannaHelper.Api.Controllers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace CappannaHelper.Api.Controllers
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class SettingController : Controller
public class SettingController : ControllerBase
{
private readonly ApplicationDbContext _context;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace CappannaHelper.Api.Controllers
[Authorize]
[Route("api/[controller]")]
[ApiController]
public class StandController : Controller
public class StandController : ControllerBase
{
private readonly ApplicationDbContext _context;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.Collections.Generic;
using CappannaHelper.Api.Persistence.Modelling;
using Microsoft.AspNetCore.SignalR;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using CappannaHelper.Api.Persistence.Modelling;
using Microsoft.AspNetCore.SignalR;

namespace CappannaHelper.Api.Hubs
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using CappannaHelper.Api.Identity.DataModel;
using Microsoft.AspNetCore.Identity;
using System;
using System.Threading.Tasks;

namespace CappannaHelper.Api.Identity.ComponentModel.SignIn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;

namespace CappannaHelper.Api.Identity.ComponentModel.User
{
public interface IUserManager<TUser> where TUser : class
{
Task<IdentityResult> CreateAsync(TUser user, string password);
Task<TUser> FindByNameAsync(string userName);
}
using Microsoft.AspNetCore.Identity;
using System.Threading.Tasks;

namespace CappannaHelper.Api.Identity.ComponentModel.User
{
public interface IUserManager<TUser> where TUser : class
{
Task<IdentityResult> CreateAsync(TUser user, string password);
Task<TUser> FindByNameAsync(string userName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ApplicationRole : IdentityRole<int>

public ApplicationRole()
{
Claims = new HashSet<ApplicationRoleClaim>();
Claims = [];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ApplicationUser : IdentityUser<int>

public ApplicationUser()
{
UserRoles = new HashSet<ApplicationUserRole>();
UserRoles = [];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public class DashboardModel

public DashboardModel()
{
OrderStats = new List<OrderStat>();
WaitersStats = new List<WaiterStats>();
OrderStats = [];
WaitersStats = [];
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using CappannaHelper.Printing;

namespace CappannaHelper.Api.Models
namespace CappannaHelper.Api.Models
{
public class NotificationModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Linq;
using CappannaHelper.Api.Identity.DataModel;
using CappannaHelper.Api.Identity.Extensions;
using CappannaHelper.Api.Persistence.Mapping;
using CappannaHelper.Api.Persistence.Modelling;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System.Linq;

namespace CappannaHelper.Api.Persistence
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CappannaHelper.Api.Identity.DataModel;
using System;
using System;

namespace CappannaHelper.Api.Persistence.Modelling
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using CappannaHelper.Printing;

namespace CappannaHelper.Api.Printing {
public interface IPrinterDocumentBuilder<T>
{
IDocument Build();
IPrinterDocumentBuilder<T> SetData(T order);
}
namespace CappannaHelper.Api.Printing;

public interface IPrinterDocumentBuilder<T>
{
IDocument Build();
IPrinterDocumentBuilder<T> SetData(T order);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using CappannaHelper.Api.Printing;

public interface IPrinterDocumentBuilderFactory
{
IPrinterDocumentBuilder<T> Create<T>();
namespace CappannaHelper.Api.Printing;

public interface IPrinterDocumentBuilderFactory
{
IPrinterDocumentBuilder<T> Create<T>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ private void SetAggregate(OrderDetailsAggregateModel aggregation)
var name = aggregation.Name;
var dotsLength = 30 - aggregation.Name.Length;
var dots = string.Empty.PadLeft(dotsLength > 0 ? dotsLength : 0, '.');
var dotsSection = _document.LastPage.CreateSection();
_ = _document.LastPage.CreateSection();
var section = _document.LastPage.CreateSection();

section.SetSize(16);
section.CreateLabel().SetContent(name);
section.CreateLabel().SetContent($"{dots}");
section.CreateLabel().SetContent($"{aggregation.Quantity.ToString().PadLeft(2, ' ')}");
section.CreateLabel().SetContent($"{aggregation.Quantity,2}");
section.NewLine();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
using System;
using CappannaHelper.Printing;
using System.Threading;
using System.Threading.Tasks;
using CappannaHelper.Printing;

namespace CappannaHelper.Api.Printing
{
public class PrintService : IPrintService
public sealed class PrintService : IPrintService
{
private readonly IPrinterDocumentBuilderFactory _factory;
private readonly IPrinter _printer;
private readonly SemaphoreSlim _semaphore;

public PrintService(IPrinterDocumentBuilderFactory factory, IPrinter printer)
{
_factory = factory ?? throw new ArgumentNullException(nameof(factory));
_printer = printer ?? throw new ArgumentNullException(nameof(printer));
_factory = factory;
_printer = printer;
_semaphore = new SemaphoreSlim(1, 1);
}

public async Task PrintAsync<T>(T data)
{
if (data == null)
{
throw new ArgumentNullException(nameof(data));
}

var builder = _factory.Create<T>();
var document = builder.SetData(data).Build();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CappannaHelper.Api.Models;
using CappannaHelper.Api.Persistence.Modelling;
using System;
using System.Collections.Generic;

namespace CappannaHelper.Api.Printing
{
Expand All @@ -12,23 +11,23 @@ public IPrinterDocumentBuilder<T> Create<T>()
{
if (typeof(T) == typeof(ChOrder))
{
return (IPrinterDocumentBuilder<T>) CreateChOrderDocumentBuilder<ChOrder>();
return (IPrinterDocumentBuilder<T>) CreateChOrderDocumentBuilder();
}

if(typeof(T) == typeof(List<OrderDetailsAggregateModel>))
{
return (IPrinterDocumentBuilder<T>) CreateOrderAggregateDocumentBuilder<List<OrderDetailsAggregateModel>>();
return (IPrinterDocumentBuilder<T>) CreateOrderAggregateDocumentBuilder();
}

throw new NotImplementedException($"Document type not implemented: {typeof(T)}");
}

private OrderDocumentBuilder CreateChOrderDocumentBuilder<T>()
private static OrderDocumentBuilder CreateChOrderDocumentBuilder()
{
return new OrderDocumentBuilder();
}

private OrderDetailsAggregateDocumentBuilder CreateOrderAggregateDocumentBuilder<T>()
private static OrderDetailsAggregateDocumentBuilder CreateOrderAggregateDocumentBuilder()
{
return new OrderDetailsAggregateDocumentBuilder();
}
Expand Down

0 comments on commit 867ea48

Please sign in to comment.