Skip to content

Commit

Permalink
feat(user-server-domain): Added the initial code for the User domain
Browse files Browse the repository at this point in the history
Added the initial code for the User domain

Updated existing Entities to
  • Loading branch information
sullivanp-fxl committed Jan 27, 2023
1 parent 2765949 commit c252d76
Show file tree
Hide file tree
Showing 108 changed files with 4,630 additions and 897 deletions.
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ testem.log
.DS_Store
Thumbs.db

apps/*/bin
apps/*/obj
libs/*/bin
libs/*/obj
/apps/**/bin/**
/apps/**/obj/**
/libs/**/bin/**
/libs/**/obj/**

tools/**/out-test/**
tools/openapi/**/target/**
Expand Down
6 changes: 3 additions & 3 deletions .nx-dotnet.rc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"MailKit": "3.4.3",
"MimeKit": "3.4.3",
"Microsoft.EntityFrameworkCore": "7.0.2",
"System.Linq.Dynamic": "1.0.8",
"System.Linq.Dynamic.Core": "1.2.24",
"Microsoft.Extensions.Configuration": "7.0.0",
"Microsoft.Extensions.Configuration.Binder": "7.0.2",
Expand All @@ -33,6 +32,7 @@
"Ocelot": "18.0.0",
"Ocelot.Provider.Consul": "18.0.0",
"Ocelot.Administration": "18.0.0",
"Swashbuckle.AspNetCore": "6.5.0"
"Swashbuckle.AspNetCore": "6.5.0",
"Microsoft.Extensions.Logging": "7.0.0"
}
}
}
18 changes: 16 additions & 2 deletions OpenSystem.sln
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.Apis.Gateway", "
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "user", "user", "{4E8C0093-2CB7-40AF-BFFD-85901D0F7CDF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.User.Domain", "libs\user\server\domain\OpenSystem.User.Server.Domain.csproj", "{5361C1C5-5EE0-4FAC-A490-789BE10E3304}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.User.Domain", "libs\user\server\domain\OpenSystem.User.Domain.csproj", "{5361C1C5-5EE0-4FAC-A490-789BE10E3304}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shared", "shared", "{4FDDF805-0410-476D-BD0D-B79C8C798637}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.Shared.Domain", "libs\shared\server\domain\OpenSystem.Shared.Server.Domain.csproj", "{984BB7D0-144F-4631-B57E-19DF5675D9DA}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.Shared.Domain", "libs\shared\server\domain\OpenSystem.Shared.Domain.csproj", "{984BB7D0-144F-4631-B57E-19DF5675D9DA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.User.Application", "libs\user\server\application\OpenSystem.User.Application.csproj", "{2C438603-2A28-4B7F-B715-280EDEEB6D19}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenSystem.User.Server.Infrastructure", "libs\user\server\infrastructure\OpenSystem.User.Infrastructure.csproj", "{F6C742C1-252E-4D36-B16F-31849D3F6474}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -74,6 +78,14 @@ Global
{984BB7D0-144F-4631-B57E-19DF5675D9DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{984BB7D0-144F-4631-B57E-19DF5675D9DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{984BB7D0-144F-4631-B57E-19DF5675D9DA}.Release|Any CPU.Build.0 = Release|Any CPU
{2C438603-2A28-4B7F-B715-280EDEEB6D19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2C438603-2A28-4B7F-B715-280EDEEB6D19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2C438603-2A28-4B7F-B715-280EDEEB6D19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2C438603-2A28-4B7F-B715-280EDEEB6D19}.Release|Any CPU.Build.0 = Release|Any CPU
{F6C742C1-252E-4D36-B16F-31849D3F6474}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6C742C1-252E-4D36-B16F-31849D3F6474}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6C742C1-252E-4D36-B16F-31849D3F6474}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6C742C1-252E-4D36-B16F-31849D3F6474}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{B1A29E6C-6B59-429E-AB79-1F7F8AF61484} = {4F8600F6-7644-44FE-B568-FFCA0A389BEF}
Expand All @@ -87,5 +99,7 @@ Global
{5974C606-0599-4EAA-B3B9-8E31AAF57477} = {B1A29E6C-6B59-429E-AB79-1F7F8AF61484}
{4E8C0093-2CB7-40AF-BFFD-85901D0F7CDF} = {64671ADE-E909-49DC-B2E5-FAC1362B5894}
{4FDDF805-0410-476D-BD0D-B79C8C798637} = {64671ADE-E909-49DC-B2E5-FAC1362B5894}
{2C438603-2A28-4B7F-B715-280EDEEB6D19} = {4E8C0093-2CB7-40AF-BFFD-85901D0F7CDF}
{F6C742C1-252E-4D36-B16F-31849D3F6474} = {4E8C0093-2CB7-40AF-BFFD-85901D0F7CDF}
EndGlobalSection
EndGlobal
Binary file not shown.
3,206 changes: 2,648 additions & 558 deletions apps/apis/gateway/obj/Debug/net7.0/project.razor.json

Large diffs are not rendered by default.

38 changes: 38 additions & 0 deletions libs/core/dotnet/application/Behaviors/LoggingBehavior.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using OpenSystem.Core.DotNet.Application.Interfaces;
using MediatR.Pipeline;
using Microsoft.Extensions.Logging;

namespace OpenSystem.Core.DotNet.Application.Behaviors
{
public class LoggingBehavior<TRequest> : IRequestPreProcessor<TRequest> where TRequest : notnull
{
private readonly ILogger _logger;
private readonly ICurrentUserService _currentUserService;
private readonly IIdentityService _identityService;

public LoggingBehavior(ILogger<TRequest> logger, ICurrentUserService currentUserService, IIdentityService identityService)
{
_logger = logger;
_currentUserService = currentUserService;
_identityService = identityService;
}

public async Task Process(TRequest request, CancellationToken cancellationToken)
{
var requestName = typeof(TRequest).Name;
var userId = _currentUserService.UserId ?? string.Empty;
string? userName = string.Empty;

if (!string.IsNullOrEmpty(userId))
{
userName = await _identityService.GetUserNameAsync(userId);
}

_logger.LogInformation("Request: {Name} {@UserId} {@UserName} {@Request}",
requestName,
userId,
userName,
request);
}
}
}
19 changes: 10 additions & 9 deletions libs/core/dotnet/application/Behaviors/ValidationBehavior.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
using FluentValidation;
using MediatR;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace OpenSystem.Core.DotNet.Application.Behaviors
{
Expand All @@ -24,12 +20,17 @@ public async Task<TResponse> Handle(TRequest request,
{
if (_validators.Any())
{
var context = new FluentValidation.ValidationContext<TRequest>(request);
var validationResults = await Task.WhenAll(_validators.Select(v => v.ValidateAsync(context, cancellationToken)));
var failures = validationResults.SelectMany(r => r.Errors).Where(f => f != null).ToList();
var context = new ValidationContext<TRequest>(request);

if (failures.Count != 0)
throw new Exceptions.ValidationException(failures);
var validationResults = await Task.WhenAll(
_validators.Select(v =>
v.ValidateAsync(context, cancellationToken)));
var failures = validationResults.Where(r => r.Errors.Any())
.SelectMany(r => r.Errors)
.ToList();

if (failures.Count > 0)
throw new ValidationException(failures);
}

return await next();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OpenSystem.Core.DotNet.Application.Interfaces
{
public interface ICurrentUserService
{
string? UserId { get; }
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace OpenSystem.Core.DotNet.Application.Interfaces
{
public interface IGenericRepositoryAsync<T> where T : class
public interface IGenericRepository<T> where T : class
{
Task<T> GetByIdAsync(Guid id);
Task<T> GetByGuidAsync(Guid guid);

Task<IEnumerable<T>> GetAllAsync();

Task<IEnumerable<T>> GetPagedResponseAsync(int pageNumber,
Task<IEnumerable<T>> GetPagedResultAsync(int pageNumber,
int pageSize);

Task<IEnumerable<T>> GetPagedAdvancedResponseAsync(int pageNumber,
Task<IEnumerable<T>> GetPagedAdvancedResultAsync(int pageNumber,
int pageSize,
string orderBy,
string fields);
Expand Down
19 changes: 19 additions & 0 deletions libs/core/dotnet/application/Interfaces/IIdentityService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System;
using OpenSystem.Core.DotNet.Application.Models;

namespace OpenSystem.Core.DotNet.Application.Interfaces
{
public interface IIdentityService
{
Task<string?> GetUserNameAsync(string userId);

Task<bool> IsInRoleAsync(string userId, string role);

Task<bool> AuthorizeAsync(string userId, string policyName);

Task<(Result<object?> Result, string UserId)> CreateUserAsync(string userName,
string password);

Task<Result<object?>> DeleteUserAsync(string userId);
}
}
147 changes: 147 additions & 0 deletions libs/core/dotnet/application/Models/DTOs/ErrorResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Text;
using System.Text.Json;

namespace OpenSystem.Core.DotNet.Application.Models.DTOs
{
/// <summary>
/// A model for API errors inline with the [RFC 7807](https://www.rfc-editor.org/rfc/rfc7807) specification.
/// </summary>
[DataContract]
public class ErrorResponse : IEquatable<ErrorResponse>
{
/// <summary>
/// A URI reference [RFC3986](https://www.rfc-editor.org/rfc/rfc3986) that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028](https://www.rfc-editor.org/rfc/rfc7807#ref-W3C.REC-html5-20141028)). When this member is not present, its value is assumed to be &#x60;about:blank&#x60;.
/// </summary>
/// <value>A URI reference [RFC3986](https://www.rfc-editor.org/rfc/rfc3986) that identifies the problem type. This specification encourages that, when dereferenced, it provide human-readable documentation for the problem type (e.g., using HTML [W3C.REC-html5-20141028](https://www.rfc-editor.org/rfc/rfc7807#ref-W3C.REC-html5-20141028)). When this member is not present, its value is assumed to be &#x60;about:blank&#x60;.</value>
[Required]
[DataMember(Name="type", EmitDefaultValue=false)]
public string Type { get; set; } = "about:blank";

/// <summary>
/// A short, human-readable summary of the problem type. It **SHOULD NOT** change from occurrence to occurrence of the pro**blem, except for purposes of localization (e.g., using proactive content negotiation; see [RFC7231, Section 3.4](https://www.rfc-editor.org/rfc/rfc7231#section-3.4)).
/// </summary>
/// <value>A short, human-readable summary of the problem type. It **SHOULD NOT** change from occurrence to occurrence of the pro**blem, except for purposes of localization (e.g., using proactive content negotiation; see [RFC7231, Section 3.4](https://www.rfc-editor.org/rfc/rfc7231#section-3.4)).</value>
[DataMember(Name="title", EmitDefaultValue=false)]
public string Title { get; set; } = "An error occurred processing your request.";

/// <summary>
/// A human-readable explanation specific to this occurrence of the problem.
/// </summary>
/// <value>A human-readable explanation specific to this occurrence of the problem.</value>
[DataMember(Name="detail", EmitDefaultValue=false)]
public string? Detail { get; set; }

/// <summary>
/// A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.
/// </summary>
/// <value>A URI reference that identifies the specific occurrence of the problem. It may or may not yield further information if dereferenced.</value>
[DataMember(Name="instance", EmitDefaultValue=false)]
public string? Instance { get; set; }

/// <summary>
/// Returns the string presentation of the object
/// </summary>
/// <returns>String presentation of the object</returns>
public override string ToString()
{
var sb = new StringBuilder();
sb.Append("class ErrorResponse {\n");
sb.Append(" Type: ").Append(Type).Append("\n");
sb.Append(" Title: ").Append(Title).Append("\n");
sb.Append(" Detail: ").Append(Detail).Append("\n");
sb.Append(" Instance: ").Append(Instance).Append("\n");
sb.Append("}\n");
return sb.ToString();
}

/// <summary>
/// Returns the JSON string presentation of the object
/// </summary>
/// <returns>JSON string presentation of the object</returns>
public string ToJson()
{
return JsonSerializer.Serialize(this,
new JsonSerializerOptions { WriteIndented = true });
}

/// <summary>
/// Returns true if objects are equal
/// </summary>
/// <param name="obj">Object to be compared</param>
/// <returns>Boolean</returns>
public override bool Equals(object obj)
{
if (obj is null) return false;
if (ReferenceEquals(this, obj)) return true;
return obj.GetType() == GetType() && Equals((ErrorResponse)obj);
}

/// <summary>
/// Returns true if ErrorResponse instances are equal
/// </summary>
/// <param name="other">Instance of ErrorResponse to be compared</param>
/// <returns>Boolean</returns>
public bool Equals(ErrorResponse other)
{
if (other is null) return false;
if (ReferenceEquals(this, other)) return true;

return
(
Type == other.Type ||
Type != null &&
Type.Equals(other.Type)
) &&
(
Title == other.Title ||
Title != null &&
Title.Equals(other.Title)
) &&
(
Detail == other.Detail ||
Detail != null &&
Detail.Equals(other.Detail)
) &&
(
Instance == other.Instance ||
Instance != null &&
Instance.Equals(other.Instance)
);
}

/// <summary>
/// Gets the hash code
/// </summary>
/// <returns>Hash code</returns>
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
var hashCode = 41;
if (Type != null)
hashCode = hashCode * 59 + Type.GetHashCode();
if (Title != null)
hashCode = hashCode * 59 + Title.GetHashCode();
if (Detail != null)
hashCode = hashCode * 59 + Detail.GetHashCode();
if (Instance != null)
hashCode = hashCode * 59 + Instance.GetHashCode();
return hashCode;
}
}

public static bool operator ==(ErrorResponse left,
ErrorResponse right)
{
return Equals(left, right);
}

public static bool operator !=(ErrorResponse left,
ErrorResponse right)
{
return !Equals(left, right);
}
}
}
5 changes: 1 addition & 4 deletions libs/core/dotnet/application/Models/PagedDataTableResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ public class PagedDataTableResult<T> : Result<T>
public PagedDataTableResult(T data,
int pageNumber,
RecordsCount recordsCount)
: base(data)
{
this.Draw = pageNumber;
this.RecordsFiltered = recordsCount.RecordsFiltered;
this.RecordsTotal = recordsCount.RecordsTotal;
this.Data = data;
this.Message = null;
this.Succeeded = true;
this.Errors = null;
}

public int Draw { get; set; }
Expand Down
5 changes: 1 addition & 4 deletions libs/core/dotnet/application/Models/PagedResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ public PagedResult(T data,
int pageNumber,
int pageSize,
RecordsCount recordsCount)
: base(data)
{
this.PageNumber = pageNumber;
this.PageSize = pageSize;
this.RecordsFiltered = recordsCount.RecordsFiltered;
this.RecordsTotal = recordsCount.RecordsTotal;
this.Data = data;
this.Message = null;
this.Succeeded = true;
this.Errors = null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ public class ErrorDetails
/// A list of error messages that occurred during the request.
/// </summary>
public List<string> Errors { get; set; }


}
}
Loading

0 comments on commit c252d76

Please sign in to comment.