-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update to .NET 7 * Change github action config to use .NET 7 * Add Contributor Entity * Configure FastEndpoints for use and for swagger * Add a CreateContributor FastEndpoint * Implement DeleteContributor FastEndpoint * Implement Contributor List FastEndpoint * Implement Contributor Update FastEndpoint * Implement GetById Contributor FastEndpoint * Update all packages to stable version of .NET 7 * Update codeql-analysis.yml * Update global.json * Update DeleteContributorSevice_DeleteContributor.cs Update based on CodeQL suggestions * Update ContributorConstructor.cs Update based on CodeQL suggestions Co-authored-by: Steve Smith <steve@kentsmiths.com> Co-authored-by: Kyle McMaster <KyleMcMaster@users.noreply.github.com>
- Loading branch information
1 parent
3d245b5
commit 08d7872
Showing
45 changed files
with
637 additions
and
39 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"sdk": { | ||
"version": "6.0.300", | ||
"version": "7.0.100", | ||
"rollForward": "latestMajor" | ||
} | ||
} |
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
20 changes: 20 additions & 0 deletions
20
src/Clean.Architecture.Core/ContributorAggregate/Contributor.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,20 @@ | ||
using Ardalis.GuardClauses; | ||
using Clean.Architecture.SharedKernel; | ||
using Clean.Architecture.SharedKernel.Interfaces; | ||
|
||
namespace Clean.Architecture.Core.ContributorAggregate; | ||
|
||
public class Contributor : EntityBase, IAggregateRoot | ||
{ | ||
public string Name { get; private set; } | ||
|
||
public Contributor(string name) | ||
{ | ||
Name = Guard.Against.NullOrEmpty(name, nameof(name)); | ||
} | ||
|
||
public void UpdateName(string newName) | ||
{ | ||
Name = Guard.Against.NullOrEmpty(newName, nameof(newName)); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Clean.Architecture.Core/ContributorAggregate/Events/ContributorDeletedEvent.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,13 @@ | ||
using Clean.Architecture.SharedKernel; | ||
|
||
namespace Clean.Architecture.Core.ContributorAggregate.Events; | ||
|
||
public class ContributorDeletedEvent : DomainEventBase | ||
{ | ||
public int ContributorId { get; set; } | ||
|
||
public ContributorDeletedEvent(int contributorId) | ||
{ | ||
ContributorId = contributorId; | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/Clean.Architecture.Core/Interfaces/IDeleteContributorService.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,8 @@ | ||
using Ardalis.Result; | ||
|
||
namespace Clean.Architecture.Core.Interfaces; | ||
|
||
public interface IDeleteContributorService | ||
{ | ||
public Task<Result> DeleteContributor(int contributorId); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Clean.Architecture.Core/ProjectAggregate/Events/ContributorAddedToItemEvent.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,16 @@ | ||
using Clean.Architecture.Core.ContributorAggregate; | ||
using Clean.Architecture.SharedKernel; | ||
|
||
namespace Clean.Architecture.Core.ProjectAggregate.Events; | ||
|
||
public class ContributorAddedToItemEvent : DomainEventBase | ||
{ | ||
public int ContributorId { get; set; } | ||
public ToDoItem Item { get; set; } | ||
|
||
public ContributorAddedToItemEvent(ToDoItem item, int contributorId) | ||
{ | ||
Item = item; | ||
ContributorId = contributorId; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
src/Clean.Architecture.Core/ProjectAggregate/Handlers/ContributorDeletedHandler.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,30 @@ | ||
using Clean.Architecture.Core.ContributorAggregate.Events; | ||
using Clean.Architecture.SharedKernel.Interfaces; | ||
using Clean.Architecture.Core.ProjectAggregate.Specifications; | ||
using MediatR; | ||
|
||
namespace Clean.Architecture.Core.ProjectAggregate.Handlers; | ||
|
||
public class ContributorDeletedHandler : INotificationHandler<ContributorDeletedEvent> | ||
{ | ||
private readonly IRepository<Project> _repository; | ||
|
||
public ContributorDeletedHandler(IRepository<Project> repository) | ||
{ | ||
_repository = repository; | ||
} | ||
|
||
public async Task Handle(ContributorDeletedEvent domainEvent, CancellationToken cancellationToken) | ||
{ | ||
var projectSpec = new ProjectsWithItemsByContributorIdSpec(domainEvent.ContributorId); | ||
var projects = await _repository.ListAsync(projectSpec); | ||
foreach (var project in projects) | ||
{ | ||
project.Items | ||
.Where(item => item.ContributorId == domainEvent.ContributorId) | ||
.ToList() | ||
.ForEach(item => item.RemoveContributor()); | ||
await _repository.UpdateAsync(project); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/Clean.Architecture.Core/ProjectAggregate/Specifications/ContributorByIdSpec.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,12 @@ | ||
using Ardalis.Specification; | ||
|
||
namespace Clean.Architecture.Core.ContributorAggregate.Specifications; | ||
|
||
public class ContributorByIdSpec : Specification<Contributor>, ISingleResultSpecification | ||
{ | ||
public ContributorByIdSpec(int contributorId) | ||
{ | ||
Query | ||
.Where(contributor => contributor.Id == contributorId); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ean.Architecture.Core/ProjectAggregate/Specifications/ProjectsWithItemsByContributorId.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,13 @@ | ||
using Ardalis.Specification; | ||
|
||
namespace Clean.Architecture.Core.ProjectAggregate.Specifications; | ||
|
||
public class ProjectsWithItemsByContributorIdSpec : Specification<Project>, ISingleResultSpecification | ||
{ | ||
public ProjectsWithItemsByContributorIdSpec(int contributorId) | ||
{ | ||
Query | ||
.Where(project => project.Items.Where(item => item.ContributorId == contributorId).Any()) | ||
.Include(project => project.Items); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
src/Clean.Architecture.Core/Services/DeleteContributorService.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,31 @@ | ||
using Ardalis.Result; | ||
using Clean.Architecture.Core.ContributorAggregate; | ||
using Clean.Architecture.Core.ContributorAggregate.Events; | ||
using Clean.Architecture.Core.Interfaces; | ||
using Clean.Architecture.SharedKernel.Interfaces; | ||
using MediatR; | ||
|
||
namespace Clean.Architecture.Core.Services; | ||
|
||
public class DeleteContributorService : IDeleteContributorService | ||
{ | ||
private readonly IRepository<Contributor> _repository; | ||
private readonly IMediator _mediator; | ||
|
||
public DeleteContributorService(IRepository<Contributor> repository, IMediator mediator) | ||
{ | ||
_repository = repository; | ||
_mediator = mediator; | ||
} | ||
|
||
public async Task<Result> DeleteContributor(int contributorId) | ||
{ | ||
var aggregateToDelete = await _repository.GetByIdAsync(contributorId); | ||
if (aggregateToDelete == null) return Result.NotFound(); | ||
|
||
await _repository.DeleteAsync(aggregateToDelete); | ||
var domainEvent = new ContributorDeletedEvent(contributorId); | ||
await _mediator.Publish(domainEvent); | ||
return Result.Success(); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
src/Clean.Architecture.Infrastructure/Data/Config/ContributorConfiguration.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,15 @@ | ||
using Clean.Architecture.Core.ContributorAggregate; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Clean.Architecture.Infrastructure.Data.Config; | ||
|
||
public class ContributorConfiguration : IEntityTypeConfiguration<Contributor> | ||
{ | ||
public void Configure(EntityTypeBuilder<Contributor> builder) | ||
{ | ||
builder.Property(p => p.Name) | ||
.HasMaxLength(100) | ||
.IsRequired(); | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/Clean.Architecture.SharedKernel/Clean.Architecture.SharedKernel.csproj
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
3 changes: 3 additions & 0 deletions
3
src/Clean.Architecture.Web/Endpoints/ContributorEndpoints/ContributorRecord.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,3 @@ | ||
namespace Clean.Architecture.Web.Endpoints.ContributorEndpoints; | ||
|
||
public record ContributorRecord(int Id, string Name); |
11 changes: 11 additions & 0 deletions
11
src/Clean.Architecture.Web/Endpoints/ContributorEndpoints/Create.CreateContributorRequest.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,11 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Clean.Architecture.Web.Endpoints.ContributorEndpoints; | ||
|
||
public class CreateContributorRequest | ||
{ | ||
public const string Route = "/Contributors"; | ||
|
||
[Required] | ||
public string? Name { get; set; } | ||
} |
12 changes: 12 additions & 0 deletions
12
...Clean.Architecture.Web/Endpoints/ContributorEndpoints/Create.CreateContributorResponse.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,12 @@ | ||
namespace Clean.Architecture.Web.Endpoints.ContributorEndpoints; | ||
|
||
public class CreateContributorResponse | ||
{ | ||
public CreateContributorResponse(int id, string name) | ||
{ | ||
Id = id; | ||
Name = name; | ||
} | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
} |
Oops, something went wrong.