Skip to content

Commit

Permalink
Merge pull request #15 from steve-bang/dev
Browse files Browse the repository at this point in the history
Merge CICD
  • Loading branch information
steve-bang authored Jan 1, 2025
2 parents 47233d6 + ddfb7d9 commit 7b49e9b
Show file tree
Hide file tree
Showing 802 changed files with 47,855 additions and 2,890 deletions.
Binary file modified .DS_Store
Binary file not shown.
493 changes: 493 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions RESTApi/Accounts/Auth.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@Host = https://localhost:7159/api/v1/auth


### Register
POST {{Host}}/register
Accept: application/json
Content-Type: application/json

{
"emailAddress" : "[email protected]",
"password" : "password",
"confirmPassword" : "password"
}

### Login user
POST {{Host}}/login
Accept: application/json
Content-Type: application/json

{
"emailAddress" : "[email protected]",
"password" : "password"
}

14 changes: 14 additions & 0 deletions RESTApi/Accounts/Roles.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@Host = https://localhost:7159/api/v1/roles
@UserId = a9ad6829-10f7-404e-224f-08dd2274641d


### Add new role
POST {{Host}}
Accept: application/json
Content-Type: application/json

{
"name" : "Contributor",
"description" : "Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries."
}

54 changes: 54 additions & 0 deletions RESTApi/Accounts/Users.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
@Host = https://localhost:7159/api/v1/users
@UserId = a9ad6829-10f7-404e-224f-08dd2274641d
@BearerToken = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9uYW1laWRlbnRpZmllciI6ImE5YWQ2ODI5LTEwZjctNDA0ZS0yMjRmLTA4ZGQyMjc0NjQxZCIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL2VtYWlsYWRkcmVzcyI6Im1yc3RldmVAZXhhbXBsZS5jb20iLCJleHAiOjE3MzU4NTUzNjUsImlzcyI6Imh0dHBzOi8vYXV0aHplcm8uY29tIiwiYXVkIjoiaHR0cHM6Ly9hdXRoemVyby5jb20ifQ.Rag8ymY4KWBBBLsHdbPC-M95EgrrjC4HUS7hzHihDWU


### Get user by Id
GET {{Host}}/{{UserId}}
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{BearerToken}}



### Update user's data by Id
PATCH {{Host}}/{{UserId}}
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{BearerToken}}

{
"firstName" : "Steve",
"lastName" : "Smith",
"bio": "I am a software developer",
"avatarUrl": "https://example.com/avatar.jpg"
}


### Assign roles to user
POST {{Host}}/{{UserId}}/roles
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{BearerToken}}

{
"roles": ["760a2dfc-7114-47dd-d257-08dd297fd518", "327db532-0652-479b-d258-08dd297fd518"]
}

### Get user's roles
GET {{Host}}/{{UserId}}/roles
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{BearerToken}}


### Remove roles from user
DELETE {{Host}}/{{UserId}}/roles
Accept: application/json
Content-Type: application/json
Authorization: Bearer {{BearerToken}}

{
"roles": ["760a2dfc-7114-47dd-d257-08dd297fd518"]
}

Binary file added database/data/Account.mdf
Binary file not shown.
Binary file added database/data/Account_log.ldf
Binary file not shown.
Binary file added database/data/Entropy.bin
Binary file not shown.
Binary file added database/data/master.mdf
Binary file not shown.
Binary file added database/data/mastlog.ldf
Binary file not shown.
Binary file added database/data/model.mdf
Binary file not shown.
Binary file added database/data/model_msdbdata.mdf
Binary file not shown.
Binary file added database/data/model_msdblog.ldf
Binary file not shown.
Binary file added database/data/model_replicatedmaster.ldf
Binary file not shown.
Binary file added database/data/model_replicatedmaster.mdf
Binary file not shown.
Binary file added database/data/modellog.ldf
Binary file not shown.
Binary file added database/data/msdbdata.mdf
Binary file not shown.
Binary file added database/data/msdblog.ldf
Binary file not shown.
Binary file added database/data/tempdb.mdf
Binary file not shown.
Binary file added database/data/tempdb2.ndf
Binary file not shown.
Binary file added database/data/tempdb3.ndf
Binary file not shown.
Binary file added database/data/tempdb4.ndf
Binary file not shown.
Binary file added database/data/tempdb5.ndf
Binary file not shown.
Binary file added database/data/tempdb6.ndf
Binary file not shown.
Binary file added database/data/tempdb7.ndf
Binary file not shown.
Binary file added database/data/tempdb8.ndf
Binary file not shown.
Binary file added database/data/templog.ldf
Binary file not shown.
151 changes: 151 additions & 0 deletions database/log/errorlog

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions database/log/errorlog.1

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions database/log/errorlog.2

Large diffs are not rendered by default.

153 changes: 153 additions & 0 deletions database/log/errorlog.3

Large diffs are not rendered by default.

152 changes: 152 additions & 0 deletions database/log/errorlog.4

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions database/log/errorlog.5

Large diffs are not rendered by default.

156 changes: 156 additions & 0 deletions database/log/errorlog.6

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions database/log/sqlagentstartup.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Microsoft (R) SQLServerAgent 16.0.4165.4
Copyright (C) 2022 Microsoft Corporation. All rights reserved.

SQLAgent is disabled
SQLAgent is exiting
Binary file added database/secrets/machine-key
Binary file not shown.
Binary file added redis/dump.rdb
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/AuthZero.AccountService/.DS_Store
Binary file not shown.

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="../../AuthZero.AppHost.Shared/AuthZero.AppHost.Shared.csproj" />
<ProjectReference Include="../../AuthZero.Shared/AuthZero.Shared.csproj" />
<ProjectReference Include="../AuthZero.AccountService.Domain/AuthZero.AccountService.Domain.csproj" />
<ProjectReference Include="../AuthZero.AccountService.Infrastructure/AuthZero.AccountService.Infrastructure.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Confluent.Kafka" Version="9.0.0" />
<PackageReference Include="Aspire.StackExchange.Redis.DistributedCaching" Version="9.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using AuthZero.AppHost.Shared.Constants;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace AuthZero.AccountService.Application;

public static class DependencyInjection
{
public static IHostApplicationBuilder AddApplication(this IHostApplicationBuilder builder)
{
// Add the MediatR services
builder.Services.AddMediatR(config =>
{
// Register all the handlers from the current assembly
config.RegisterServicesFromAssembly(typeof(DependencyInjection).Assembly);

// Register the ValidationBehavior
//config.AddOpenBehavior(typeof(ValidationBehaviour<,>));
});

// Add the Kafka services
builder.AddKafkaProducer<string, string>(Names.KafkaMessages);

// Add Redis services
builder.AddRedisDistributedCache("caching");

return builder;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@


using AuthZero.AccountService.Domain.Events;
using AuthZero.AppHost.Shared.Messages;
using Confluent.Kafka;


namespace AuthZero.AccountService.Application.DomainEventHandlers;



public class UserRegisterEventHandler(
IProducer<string, string> _messageProducer
) : INotificationHandler<UserRegisterEvent>
{

public async Task Handle(UserRegisterEvent notification, CancellationToken cancellationToken)
{
var message = new Message<string, string>{ Key = notification.User.Id.ToString(), Value = notification.User.EmailAddress, Timestamp = new Timestamp(DateTimeOffset.UtcNow) };

var result = await _messageProducer.ProduceAsync(Topics.UserRegisterSuccess, message);

if (result.Status != PersistenceStatus.Persisted)
{
throw new Exception("Failed to produce message");
}

Console.WriteLine($"Produced message to topic {result.Topic}, partition {result.Partition}, offset {result.Offset}");


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

namespace AuthZero.AccountService.Application.Features.Commands;

public record AddRoleCommand(
string Name,
string Description
) : IRequest<Guid>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

using AuthZero.AccountService.Domain.AggregatesModel;

namespace AuthZero.AccountService.Application.Features.Commands;

public class AddRoleCommandHandler(
IRoleRepository _roleRepository
) : IRequestHandler<AddRoleCommand, Guid>
{
public async Task<Guid> Handle(AddRoleCommand request, CancellationToken cancellationToken)
{


var role = await _roleRepository.AddAsync(new Role(request.Name, request.Description));

await _roleRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

return role.Id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

namespace AuthZero.AccountService.Application.Features.Commands;

public record AssignRoleCommand(
Guid UserId,
Guid[] Roles
) : IRequest<bool>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

using AuthZero.AccountService.Domain.AggregatesModel;
using AuthZero.Shared.Exceptions;

namespace AuthZero.AccountService.Application.Features.Commands;

public record AssignRoleCommandHandler(
IRoleRepository _roleRepository,
IUserRepository _userRepository
) : IRequestHandler<AssignRoleCommand, bool>
{

public async Task<bool> Handle(AssignRoleCommand request, CancellationToken cancellationToken)
{
var user = await _userRepository.GetByIdAsync(request.UserId);
if (user == null)
{
throw new NotFoundDataException(nameof(User), "User.NotFound");
}

var roles = await _roleRepository.GetRolesByIdsAsync(request.Roles);

if (roles == null)
{
throw new NotFoundDataException(nameof(Role), "Role.NotFound");
}

user.AssignRoles(roles);

_userRepository.Update(user);

bool result = await _userRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

namespace AuthZero.AccountService.Application.Features.Commands;

public record EditUserCommand(
Guid Id,
string AvatarUrl,
string Bio,
string FirstName,
string LastName
) : IRequest<bool>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

using AuthZero.Shared.Exceptions;

namespace AuthZero.AccountService.Application.Features.Commands;

public class EditUserCommandHandler(
IUserRepository _userRepository
) : IRequestHandler<EditUserCommand, bool>
{
public async Task<bool> Handle(EditUserCommand request, CancellationToken cancellationToken)
{
User? user = await _userRepository.GetByIdAsync(request.Id);

if(user is null)
throw new NotFoundDataException("User", "User.NotFound");

user.Edit(
avatarUrl: request.AvatarUrl,
bio: request.Bio,
firstName: request.FirstName,
lastName: request.LastName
);

await _userRepository.UnitOfWork.SaveEntitiesAsync(cancellationToken);

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

namespace AuthZero.AccountService.Application.Features.Commands;

/// <summary>
/// Login a user.
/// </summary>
/// <param name="EmailAddress">The email address of the user.</param>
/// <param name="Password">The password of the user.</param>
public record LoginUserCommand(
string EmailAddress,
string Password
) : IRequest<ResultUserLoginSuccess>;
Loading

0 comments on commit 7b49e9b

Please sign in to comment.