Skip to content

Commit

Permalink
Use primary constructor, use ArgumentNullException.ThrowIfNull
Browse files Browse the repository at this point in the history
  • Loading branch information
volkanceylan committed Jan 4, 2025
1 parent a0ad83c commit 72ee725
Show file tree
Hide file tree
Showing 22 changed files with 95 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
using MyRow = Serene.Administration.LanguageRow;
using MyRow = Serene.Administration.LanguageRow;
using MyRequest = Serenity.Services.DeleteRequest;
using MyResponse = Serenity.Services.DeleteResponse;


namespace Serene.Administration;

public interface ILanguageDeleteHandler : IDeleteHandler<MyRow, MyRequest, MyResponse> { }

public class LanguageDeleteHandler : DeleteRequestHandler<MyRow, MyRequest, MyResponse>, ILanguageDeleteHandler
public class LanguageDeleteHandler(IRequestContext context)
: DeleteRequestHandler<MyRow, MyRequest, MyResponse>(context), ILanguageDeleteHandler
{
public LanguageDeleteHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MyRow = Serene.Administration.LanguageRow;
using MyRow = Serene.Administration.LanguageRow;
using MyRequest = Serenity.Services.ListRequest;
using MyResponse = Serenity.Services.ListResponse<Serene.Administration.LanguageRow>;

Expand All @@ -7,10 +7,7 @@ namespace Serene.Administration;

public interface ILanguageListHandler : IListHandler<MyRow, MyRequest, MyResponse> { }

public class LanguageListHandler : ListRequestHandler<MyRow, MyRequest, MyResponse>, ILanguageListHandler
public class LanguageListHandler(IRequestContext context)
: ListRequestHandler<MyRow, MyRequest, MyResponse>(context), ILanguageListHandler
{
public LanguageListHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using MyRow = Serene.Administration.LanguageRow;
using MyRow = Serene.Administration.LanguageRow;
using MyRequest = Serenity.Services.RetrieveRequest;
using MyResponse = Serenity.Services.RetrieveResponse<Serene.Administration.LanguageRow>;


namespace Serene.Administration;

public interface ILanguageRetrieveHandler : IRetrieveHandler<MyRow, MyRequest, MyResponse> { }
public class LanguageRetrieveHandler : RetrieveRequestHandler<MyRow, MyRequest, MyResponse>, ILanguageRetrieveHandler

public class LanguageRetrieveHandler(IRequestContext context)
: RetrieveRequestHandler<MyRow, MyRequest, MyResponse>(context), ILanguageRetrieveHandler
{
public LanguageRetrieveHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using MyRow = Serene.Administration.LanguageRow;
using MyRow = Serene.Administration.LanguageRow;
using MyRequest = Serenity.Services.SaveRequest<Serene.Administration.LanguageRow>;
using MyResponse = Serenity.Services.SaveResponse;


namespace Serene.Administration;

public interface ILanguageSaveHandler : ISaveHandler<MyRow, MyRequest, MyResponse> { }
public class LanguageSaveHandler : SaveRequestHandler<MyRow, MyRequest, MyResponse>, ILanguageSaveHandler

public class LanguageSaveHandler(IRequestContext context)
: SaveRequestHandler<MyRow, MyRequest, MyResponse>(context), ILanguageSaveHandler
{
public LanguageSaveHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using MyRow = Serene.Administration.RoleRow;
using MyRow = Serene.Administration.RoleRow;
using MyRequest = Serenity.Services.DeleteRequest;
using MyResponse = Serenity.Services.DeleteResponse;


namespace Serene.Administration;

public interface IRoleDeleteHandler : IDeleteHandler<MyRow, MyRequest, MyResponse> { }
public class RoleDeleteHandler : DeleteRequestHandler<MyRow, MyRequest, MyResponse>, IRoleDeleteHandler

public class RoleDeleteHandler(IRequestContext context)
: DeleteRequestHandler<MyRow, MyRequest, MyResponse>(context), IRoleDeleteHandler
{
public RoleDeleteHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using MyRow = Serene.Administration.RoleRow;
using MyRow = Serene.Administration.RoleRow;
using MyRequest = Serenity.Services.ListRequest;
using MyResponse = Serenity.Services.ListResponse<Serene.Administration.RoleRow>;

Expand All @@ -7,10 +7,7 @@ namespace Serene.Administration;

public interface IRoleListHandler : IListHandler<MyRow, MyRequest, MyResponse> { }

public class RoleListHandler : ListRequestHandler<MyRow, MyRequest, MyResponse>, IRoleListHandler
public class RoleListHandler(IRequestContext context)
: ListRequestHandler<MyRow, MyRequest, MyResponse>(context), IRoleListHandler
{
public RoleListHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using MyRow = Serene.Administration.RoleRow;
using MyRow = Serene.Administration.RoleRow;
using MyRequest = Serenity.Services.RetrieveRequest;
using MyResponse = Serenity.Services.RetrieveResponse<Serene.Administration.RoleRow>;


namespace Serene.Administration;

public interface IRoleRetrieveHandler : IRetrieveHandler<MyRow, MyRequest, MyResponse> { }
public class RoleRetrieveHandler : RetrieveRequestHandler<MyRow, MyRequest, MyResponse>, IRoleRetrieveHandler
public class RoleRetrieveHandler(IRequestContext context)
: RetrieveRequestHandler<MyRow, MyRequest, MyResponse>(context), IRoleRetrieveHandler
{
public RoleRetrieveHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using MyRow = Serene.Administration.RoleRow;
using MyRow = Serene.Administration.RoleRow;
using MyRequest = Serenity.Services.SaveRequest<Serene.Administration.RoleRow>;
using MyResponse = Serenity.Services.SaveResponse;

namespace Serene.Administration;

public interface IRoleSaveHandler : ISaveHandler<MyRow, MyRequest, MyResponse> { }
public class RoleSaveHandler : SaveRequestHandler<MyRow, MyRequest, MyResponse>, IRoleSaveHandler
{
public RoleSaveHandler(IRequestContext context)
: base(context)
{
}

public class RoleSaveHandler(IRequestContext context)
: SaveRequestHandler<MyRow, MyRequest, MyResponse>(context), IRoleSaveHandler
{
protected override void InvalidateCacheOnCommit()
{
base.InvalidateCacheOnCommit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ public static class RoleHelper
private static MyRow.RowFields Fld { get { return MyRow.Fields; } }
public static Dictionary<int, MyRow> GetRoleById(ITwoLevelCache cache, ISqlConnections sqlConnections)
{
if (cache is null)
throw new ArgumentNullException(nameof(cache));
ArgumentNullException.ThrowIfNull(cache);

return cache.GetLocalStoreOnly("RoleById", TimeSpan.Zero,
Fld.GenerationKey, () =>
{
if (sqlConnections is null)
throw new ArgumentNullException(nameof(sqlConnections));
ArgumentNullException.ThrowIfNull(sqlConnections);

using var connection = sqlConnections.NewFor<MyRow>();
return connection.List<MyRow>().ToDictionary(x => x.RoleId.Value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,22 @@

namespace Serene.Administration.Repositories;

public class RolePermissionRepository : BaseRepository
public class RolePermissionRepository(IRequestContext context) : BaseRepository(context)
{
public RolePermissionRepository(IRequestContext context)
: base(context)
{
}

private static MyRow.RowFields Fld { get { return MyRow.Fields; } }

public SaveResponse Update(IUnitOfWork uow, RolePermissionUpdateRequest request)
{
if (request is null)
throw new ArgumentNullException(nameof(request));
if (request.RoleID is null)
throw new ArgumentNullException(nameof(request.RoleID));
if (request.Permissions is null)
throw new ArgumentNullException(nameof(request.Permissions));
ArgumentNullException.ThrowIfNull(request);
ArgumentNullException.ThrowIfNull(request.RoleID);
ArgumentNullException.ThrowIfNull(request.Permissions);

var roleID = request.RoleID.Value;
var oldList = new HashSet<string>(
GetExisting(uow.Connection, roleID)
.Select(x => x.PermissionKey), StringComparer.OrdinalIgnoreCase);

var newList = new HashSet<string>(request.Permissions.ToList(),
var newList = new HashSet<string>([.. request.Permissions],
StringComparer.OrdinalIgnoreCase);

if (oldList.SetEquals(newList))
Expand Down Expand Up @@ -73,8 +65,7 @@ private List<MyRow> GetExisting(IDbConnection connection, int roleId)

public RolePermissionListResponse List(IDbConnection connection, RolePermissionListRequest request)
{
if (request is null)
throw new ArgumentNullException(nameof(request));
ArgumentNullException.ThrowIfNull(request);
if (request.RoleID is null)
throw new ArgumentNullException(nameof(request.RoleID));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ namespace Serene.Administration.Endpoints;

[Route("Services/Administration/Translation/[action]")]
[ServiceAuthorize(PermissionKeys.Translation)]
public class TranslationEndpoint : ServiceEndpoint
public class TranslationEndpoint(IWebHostEnvironment hostEnvironment,
ILocalTextRegistry localTextRegistry, ITypeSource typeSource) : ServiceEndpoint
{
protected IWebHostEnvironment HostEnvironment { get; }
protected ILocalTextRegistry LocalTextRegistry { get; }
protected ITypeSource TypeSource { get; }

public TranslationEndpoint(IWebHostEnvironment hostEnvironment,
ILocalTextRegistry localTextRegistry, ITypeSource typeSource)
{
HostEnvironment = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
LocalTextRegistry = localTextRegistry ?? throw new ArgumentNullException(nameof(localTextRegistry));
TypeSource = typeSource ?? throw new ArgumentNullException(nameof(typeSource));
}
protected IWebHostEnvironment HostEnvironment { get; } = hostEnvironment ?? throw new ArgumentNullException(nameof(hostEnvironment));
protected ILocalTextRegistry LocalTextRegistry { get; } = localTextRegistry ?? throw new ArgumentNullException(nameof(localTextRegistry));
protected ITypeSource TypeSource { get; } = typeSource ?? throw new ArgumentNullException(nameof(typeSource));

private MyRepository NewRepository()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,12 @@

namespace Serene.Administration.Repositories;

public class TranslationRepository : BaseRepository
public class TranslationRepository(IRequestContext context, IWebHostEnvironment hostEnvironment,
ILocalTextRegistry localTextRegistry, ITypeSource typeSource) : BaseRepository(context)
{
protected IWebHostEnvironment HostEnvironment { get; }
protected ILocalTextRegistry LocalTextRegistry { get; }
protected ITypeSource TypeSource { get; }

public TranslationRepository(IRequestContext context, IWebHostEnvironment hostEnvironment,
ILocalTextRegistry localTextRegistry, ITypeSource typeSource)
: base(context)
{
HostEnvironment = hostEnvironment;
LocalTextRegistry = localTextRegistry;
TypeSource = typeSource;
}
protected IWebHostEnvironment HostEnvironment { get; } = hostEnvironment;
protected ILocalTextRegistry LocalTextRegistry { get; } = localTextRegistry;
protected ITypeSource TypeSource { get; } = typeSource;

public static string GetUserTextsFilePath(IWebHostEnvironment hostEnvironment, string languageID)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,10 @@ protected LoggingRow() : base() { }
DateTimeField IUpdateLogRow.UpdateDateField => fields.UpdateDate;
}

public class LoggingRowFields : RowFieldsBase
public class LoggingRowFields(string tableName = null, string fieldPrefix = null) : RowFieldsBase(tableName, fieldPrefix)
{
public Int32Field InsertUserId;
public DateTimeField InsertDate;
public Int32Field UpdateUserId;
public DateTimeField UpdateDate;

public LoggingRowFields(string tableName = null, string fieldPrefix = null)
: base(tableName, fieldPrefix)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
using Serenity.Extensions.Entities;
using Serenity.Extensions.Entities;
using System.Data;
using MyRow = Serene.Administration.UserRow;
using MyRequest = Serenity.Services.DeleteRequest;
using MyResponse = Serenity.Services.DeleteResponse;
using MyRow = Serene.Administration.UserRow;

namespace Serene.Administration;

public interface IUserDeleteHandler : IDeleteHandler<MyRow, MyRequest, MyResponse> { }
public class UserDeleteHandler : DeleteRequestHandler<MyRow, MyRequest, MyResponse>, IUserDeleteHandler
{
private readonly IOptions<EnvironmentSettings> environmentOptions;

public UserDeleteHandler(IRequestContext context, IOptions<EnvironmentSettings> environmentOptions)
: base(context)
{
this.environmentOptions = environmentOptions ??
public class UserDeleteHandler(IRequestContext context, IOptions<EnvironmentSettings> environmentOptions)
: DeleteRequestHandler<MyRow, MyRequest, MyResponse>(context), IUserDeleteHandler
{
private readonly IOptions<EnvironmentSettings> environmentOptions = environmentOptions ??
throw new System.ArgumentNullException(nameof(environmentOptions));
}

protected override void ValidateRequest()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using MyRow = Serene.Administration.UserRow;
using MyRow = Serene.Administration.UserRow;
using MyRequest = Serene.Administration.UserListRequest;
using MyResponse = Serenity.Services.ListResponse<Serene.Administration.UserRow>;

namespace Serene.Administration;

public interface IUserListHandler : IListHandler<MyRow, MyRequest, MyResponse> { }

public class UserListHandler : ListRequestHandler<MyRow, MyRequest, MyResponse>, IUserListHandler
public class UserListHandler(IRequestContext context)
: ListRequestHandler<MyRow, MyRequest, MyResponse>(context), IUserListHandler
{
public UserListHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using MyRow = Serene.Administration.UserRow;
using MyRow = Serene.Administration.UserRow;
using MyRequest = Serenity.Services.RetrieveRequest;
using MyResponse = Serenity.Services.RetrieveResponse<Serene.Administration.UserRow>;


namespace Serene.Administration;

public interface IUserRetrieveHandler : IRetrieveHandler<MyRow, MyRequest, MyResponse> { }
public class UserRetrieveHandler : RetrieveRequestHandler<MyRow, MyRequest, MyResponse>, IUserRetrieveHandler

public class UserRetrieveHandler(IRequestContext context)
: RetrieveRequestHandler<MyRow, MyRequest, MyResponse>(context), IUserRetrieveHandler
{
public UserRetrieveHandler(IRequestContext context)
: base(context)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@
namespace Serene.Administration;

public interface IUserSaveHandler : ISaveHandler<MyRow, MyRequest, MyResponse> { }
public class UserSaveHandler : SaveRequestHandler<MyRow, MyRequest, MyResponse>, IUserSaveHandler

public class UserSaveHandler(IRequestContext context, IOptions<EnvironmentSettings> environmentOptions)
: SaveRequestHandler<MyRow, MyRequest, MyResponse>(context), IUserSaveHandler
{
private static MyRow.RowFields Fld { get { return MyRow.Fields; } }

public UserSaveHandler(IRequestContext context, IOptions<EnvironmentSettings> environmentOptions)
: base(context)
{
this.environmentOptions = environmentOptions ??
throw new System.ArgumentNullException(nameof(environmentOptions));
}

private string password;
private readonly IOptions<EnvironmentSettings> environmentOptions;
private readonly IOptions<EnvironmentSettings> environmentOptions = environmentOptions ??
throw new ArgumentNullException(nameof(environmentOptions));

protected override void GetEditableFields(HashSet<Field> editable)
{
Expand Down
Loading

0 comments on commit 72ee725

Please sign in to comment.