-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(user-server-domain): Added the initial code for the User domain
Added the initial code for the User domain Updated existing Entities to
- Loading branch information
1 parent
2765949
commit c252d76
Showing
108 changed files
with
4,630 additions
and
897 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+359 Bytes
(100%)
apps/apis/gateway/obj/Debug/net7.0/OpenSystem.Apis.Gateway.csproj.AssemblyReference.cache
Binary file not shown.
3,206 changes: 2,648 additions & 558 deletions
3,206
apps/apis/gateway/obj/Debug/net7.0/project.razor.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
libs/core/dotnet/application/Interfaces/ICurrentUserService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
12 changes: 4 additions & 8 deletions
12
...ion/Interfaces/IGenericRepositoryAsync.cs → ...lication/Interfaces/IGenericRepository.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
libs/core/dotnet/application/Interfaces/IIdentityService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
147
libs/core/dotnet/application/Models/DTOs/ErrorResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 `about:blank`. | ||
/// </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 `about:blank`.</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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.