Skip to content

Commit

Permalink
Merge pull request #6 from vicheanath/git-repo
Browse files Browse the repository at this point in the history
Add Test and restructure folder project
  • Loading branch information
vicheanath authored Sep 13, 2024
2 parents 1604f2c + fb91f9b commit 7521a8d
Show file tree
Hide file tree
Showing 287 changed files with 590 additions and 249 deletions.
Binary file added DDD_Bug_Tracking_ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions SearchBugs.Application.UnitTests/UnitTest1.cs

This file was deleted.

5 changes: 0 additions & 5 deletions SearchBugs.Domain/Bugs/TimeTracingId.cs

This file was deleted.

10 changes: 0 additions & 10 deletions SearchBugs.Domain/Projects/IProjectRepository.cs

This file was deleted.

10 changes: 0 additions & 10 deletions SearchBugs.Domain/Repositories/IGitRepository.cs

This file was deleted.

11 changes: 0 additions & 11 deletions SearchBugs.Infrastructure.UnitTests/UnitTest1.cs

This file was deleted.

11 changes: 0 additions & 11 deletions SearchBugs.Persistence.UnitTests/UnitTest1.cs

This file was deleted.

37 changes: 0 additions & 37 deletions SearchBugs.Persistence/Repositories/Repository.cs

This file was deleted.

238 changes: 152 additions & 86 deletions SearchBugs.sln

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.7" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.7" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.8" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

using Shared.Data;
using Shared.Data;
using Shared.Messaging;
using Shared.Results;

Expand All @@ -21,20 +20,20 @@ public Task<Result<List<BugsResponse>>> Handle(GetBugsQuery request, Cancellatio
public async Task<IEnumerable<BugsResponse>?> GetBugsByProjectIdAsync(Guid projectId) =>
await _sqlQueryExecutor.QueryAsync<BugsResponse>(@"
SELECT
b.id as Id,
b.title as Title,
b.description as Description,
s.name as Status,
p.name as Priority,
b.severity as Severity,
p.name as ProjectName,
CONCAT(u.name_first_name,' ',u.name_last_name) as Assignee,
CONCAT(u.name_first_name,' ',u.name_last_name) as Reporter,
b.created_on_utc as CreatedOnUtc,
b.modified_on_utc as UpdatedOnUtc
FROM bug b
JOIN bug_status s ON b.status_id = s.id
JOIN bug_priority p ON b.priority_id = p.id
JOIN ""user"" u ON b.assignee_id = u.id
ORDER BY b.created_on_utc DESC", new { projectId });
b.id as Id,
b.title as Title,
b.description as Description,
s.name as Status,
p.name as Priority,
b.severity as Severity,
p.name as ProjectName,
CONCAT(u.name_first_name,' ',u.name_last_name) as Assignee,
CONCAT(u.name_first_name,' ',u.name_last_name) as Reporter,
b.created_on_utc as CreatedOnUtc,
b.modified_on_utc as UpdatedOnUtc
FROM bug b
JOIN bug_status s ON b.status_id = s.id
JOIN bug_priority p ON b.priority_id = p.id
JOIN ""user"" u ON b.assignee_id = u.id
ORDER BY b.created_on_utc DESC", new { projectId });
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public static IServiceCollection AddApplication(this IServiceCollection services
{
services.AddMediatR(config =>
{
config.RegisterServicesFromAssemblyContaining<ApplicationAssemblyReference>();
config.RegisterServicesFromAssembly(ApplicationAssemblyReference.Assembly);

config.AddOpenBehavior(typeof(ValidationPipelineBehavior<,>));
});

services.AddValidatorsFromAssembly(ApplicationAssemblyReference.Assembly);
services.AddValidatorsFromAssembly(ApplicationAssemblyReference.Assembly, includeInternalTypes: true);

return services;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using FluentValidation;
using Shared.Extensions;

namespace SearchBugs.Application.Git.DeleteGitRepo;

internal sealed class DeleteGitCommandValidator : AbstractValidator<DeleteGitRepoCommand>
{
public DeleteGitCommandValidator()
{
RuleFor(x => x.Url)
.NotEmpty()
.WithError(GitValidationErrors.UrlIsRequired);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

namespace SearchBugs.Application.Git.DeleteGitRepo;

public sealed class DeleteGitRepoCommand(string Url) : ICommand;
public record DeleteGitRepoCommand(string Url) : ICommand;
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using SearchBugs.Domain;
using SearchBugs.Domain.Repositories;
using Shared.Messaging;
using Shared.Results;

namespace SearchBugs.Application.Git.DeleteGitRepo;

public sealed class DeleteGitRepoCommandHandler : ICommandHandler<DeleteGitRepoCommand>
{
private readonly IGitRepository _gitRepository;
private readonly IUnitOfWork _unitOfWork;

public DeleteGitRepoCommandHandler(IGitRepository gitRepository, IUnitOfWork unitOfWork)
{
_gitRepository = gitRepository;
_unitOfWork = unitOfWork;
}

public async Task<Result> Handle(DeleteGitRepoCommand request, CancellationToken cancellationToken)
{
var gitRepo = await _gitRepository.GetByUrlAsync(request.Url, cancellationToken);

if (gitRepo.IsFailure)
{
return Result.Failure(GitValidationErrors.GitRepoNotFound);
}

await _gitRepository.Remove(gitRepo.Value);

await _unitOfWork.SaveChangesAsync(cancellationToken);

return Result.Success();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ internal static class GitValidationErrors
internal static Error DescriptionIsRequired => new("Git.DescriptionIsRequired", "The git's description is required.");
internal static Error UrlIsRequired => new("Git.UrlIsRequired", "The git's url is required.");

internal static Error GitRepoNotFound => new("Git.GitRepoNotFound", "The git repository was not found.");

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.2" />
<PackageReference Include="MediatR" Version="12.4.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.7" />
<PackageReference Include="MediatR" Version="12.4.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SearchBugs.Domain\SearchBugs.Domain.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public UpdateUserCommandHandler(IUnitOfWork unitOfWork, IUserRepository userRepo

public async Task<Result> Handle(UpdateUserCommand request, CancellationToken cancellationToken)
{
var user = await _userRepository.GetByIdAsync(request.Id, cancellationToken);
var user = await _userRepository.GetByIdAsync(new UserId(request.Id), cancellationToken);
if (user.IsFailure)
{
return Result.Failure(user.Error);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions src/SearchBugs.Domain/Bugs/BugsErrors.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Shared.Errors;

namespace SearchBugs.Domain.Bugs;

internal static class BugsErrors
{
internal static Error TitleIsRequired => new Error("Bug.TitleIsRequired", "Title is required");
internal static Error InvalidBugStatus => new Error("Bug.InvalidStatus", "Invalid bug status");

internal static Error InvalidBugPriority => new Error("Bug.InvalidPriority", "Invalid bug priority");

internal static Error InvalidBugSeverity => new Error("Bug.InvalidSeverity", "Invalid bug severity");

internal static Error InvalidProjectId => new Error("Bug.InvalidProjectId", "Invalid project id");

internal static Error InvalidAssigneeId => new Error("Bug.InvalidAssigneeId", "Invalid assignee id");

internal static Error InvalidReporterId => new Error("Bug.InvalidReporterId", "Invalid reporter id");

internal static Error InvalidTitle => new Error("Bug.InvalidTitle", "Invalid title");
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

namespace SearchBugs.Domain.Bugs;

public interface IBugRepository
public interface IBugRepository : IRepository<Bug, BugId>
{
Task<Result<Bug>> GetByIdAsync(BugId id, CancellationToken cancellationToken);
Task Add(Bug bug);

Task<Result<BugStatus>> GetBugStatusByName(string name, CancellationToken cancellationToken);

Task<Result<BugPriority>> GetBugPriorityByName(string name, CancellationToken cancellationToken);

}
8 changes: 8 additions & 0 deletions src/SearchBugs.Domain/Bugs/TimeTracingId.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Shared.Primitives;

namespace SearchBugs.Domain.Bugs;

public record TimeTracingId(Guid Value) : IEntityId
{
public static TimeTracingId New => new(Guid.NewGuid());
}
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions src/SearchBugs.Domain/IRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Shared.Primitives;
using Shared.Results;
using System.Linq.Expressions;

namespace SearchBugs.Domain;

public interface IRepository<TEntity, TEntityId>
where TEntity : Entity<TEntityId>
where TEntityId : class, IEntityId
{
Task<Result> Add(TEntity entity);

Task<Result<TEntity>> GetByIdAsync(IEntityId id, CancellationToken cancellationToken = default, params Expression<Func<TEntity, object>>[] includes);

Task<Result> Remove(TEntity entity);

Task<Result> Update(TEntity entity);
}
File renamed without changes.
5 changes: 5 additions & 0 deletions src/SearchBugs.Domain/Projects/IProjectRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace SearchBugs.Domain.Projects;

public interface IProjectRepository : IRepository<Project, ProjectId>
{
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions src/SearchBugs.Domain/Repositories/IGitRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Shared.Results;

namespace SearchBugs.Domain.Repositories;

public interface IGitRepository : IRepository<Repository, RepositoryId>
{
Task<Result<Repository>> GetByUrlAsync(string url, CancellationToken cancellationToken = default);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
32 changes: 32 additions & 0 deletions src/SearchBugs.Domain/Services/Ensure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using Shared.Errors;

namespace SearchBugs.Domain.Services;

public static class Ensure
{
public static Error NotNull<T>(T value, Error error)
{
return value == null ? error : Error.None;
}

public static Error NotNullOrEmpty<T>(T value, Error error)
{
return value == null || string.IsNullOrEmpty(value.ToString()) ? error : Error.None;
}

public static Error NotNullOrWhiteSpace(string value, Error error)
{
return string.IsNullOrWhiteSpace(value) ? error : Error.None;
}

public static Error NotNegative<T>(T value, Error error)
{
return value switch
{
int i when i < 0 => error,
long l when l < 0 => error,
decimal d when d < 0 => error,
_ => Error.None
};
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@

namespace SearchBugs.Domain.Users;

public interface IUserRepository
public interface IUserRepository : IRepository<User, UserId>
{
Task<Result<User>> GetUserByEmailAsync(string email, CancellationToken cancellationToken);

Task Add(User user);

Task<Result<Role>> GetRoleByIdAsync(int roleId, CancellationToken cancellationToken);

Task<Result<User>> IsEmailUniqueAsync(Email email, CancellationToken cancellationToken);

Task<Result<User>> GetByIdAsync(Guid id, CancellationToken cancellationToken = default);
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7521a8d

Please sign in to comment.