-
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.
- Loading branch information
1 parent
1a0fd74
commit a1a712e
Showing
27 changed files
with
873 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.17" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Domain\Domain.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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 Domain.Applications; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Application.Abstractions.DataAccess; | ||
|
||
public interface IDatabaseContext | ||
{ | ||
DbSet<ApplicationActivity> ApplicationActivities { get; set; } | ||
DbSet<UnsubmittedApplication> UnsubmittedApplications { get; set; } | ||
DbSet<SubmittedApplication> SubmittedApplications { get; set; } | ||
|
||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Domain.Applications; | ||
using FluentValidation; | ||
|
||
namespace Domain.Validators; | ||
|
||
public class ApplicationActivityValidator : AbstractValidator<ApplicationActivity> | ||
{ | ||
private const int MaxNameLength = 100; | ||
private const int MaxDescriptionLength = 300; | ||
|
||
public ApplicationActivityValidator() | ||
{ | ||
RuleFor(x => x.Id) | ||
.NotEmpty(); | ||
|
||
RuleFor(x => x.Name) | ||
.NotEmpty() | ||
.MaximumLength(MaxNameLength); | ||
|
||
RuleFor(x => x.Description) | ||
.NotEmpty() | ||
.MaximumLength(MaxDescriptionLength); | ||
} | ||
} |
This file was deleted.
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,34 @@ | ||
using Domain.Applications; | ||
using FluentValidation; | ||
|
||
namespace Domain.Validators; | ||
|
||
public class SubmittedApplicationValidator : AbstractValidator<SubmittedApplication> | ||
{ | ||
private const int MaxNameLength = 100; | ||
private const int MaxDescriptionLength = 300; | ||
private const int MaxPlanLength = 1000; | ||
|
||
public SubmittedApplicationValidator() | ||
{ | ||
RuleFor(x => x.Id) | ||
.NotEmpty(); | ||
|
||
RuleFor(x => x.UserId) | ||
.NotEmpty(); | ||
|
||
RuleFor(x => x.Name) | ||
.NotEmpty() | ||
.MaximumLength(MaxNameLength); | ||
|
||
RuleFor(x => x.Description) | ||
.MaximumLength(MaxDescriptionLength); | ||
|
||
RuleFor(x => x.Plan) | ||
.NotEmpty() | ||
.MaximumLength(MaxPlanLength); | ||
|
||
RuleFor(x => x.CreatedDateTime) | ||
.NotEmpty(); | ||
} | ||
} |
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,36 @@ | ||
using Domain.Applications; | ||
using FluentValidation; | ||
|
||
namespace Domain.Validators; | ||
|
||
public class UnsubmittedApplicationValidator : AbstractValidator<UnsubmittedApplication> | ||
{ | ||
private const int MaxNameLength = 100; | ||
private const int MaxDescriptionLength = 300; | ||
private const int MaxPlanLength = 1000; | ||
|
||
public UnsubmittedApplicationValidator() | ||
{ | ||
RuleFor(x => x.Id) | ||
.NotEmpty(); | ||
|
||
RuleFor(x => x.UserId) | ||
.NotEmpty(); | ||
|
||
RuleFor(x => x.Name) | ||
.MaximumLength(MaxNameLength); | ||
|
||
RuleFor(x => x.Description) | ||
.MaximumLength(MaxDescriptionLength); | ||
|
||
RuleFor(x => x.Plan) | ||
.MaximumLength(MaxPlanLength); | ||
|
||
RuleFor(x => x) | ||
.Must(x => x.Name is not null || x.Description is not null || x.Plan is not null) | ||
.WithMessage("Not all required fields are filled in application to submit"); | ||
|
||
RuleFor(x => x.CreatedDateTime) | ||
.NotEmpty(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Infrastructure.DataAccess/Configurations/ApplicationActivityConfiguration.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,18 @@ | ||
using Domain.Applications; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Infrastructure.DataAccess.Configurations; | ||
|
||
public class ApplicationActivityConfiguration : IEntityTypeConfiguration<ApplicationActivity> | ||
{ | ||
public void Configure(EntityTypeBuilder<ApplicationActivity> builder) | ||
{ | ||
builder.HasKey(x => x.Id); | ||
|
||
builder.HasIndex(x => x.Name) | ||
.IsUnique(); | ||
|
||
builder.Property(x => x.Description); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Infrastructure.DataAccess/Configurations/SubmittedApplicationConfiguration.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,23 @@ | ||
using Domain.Applications; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Infrastructure.DataAccess.Configurations; | ||
|
||
public class SubmittedApplicationConfiguration : IEntityTypeConfiguration<SubmittedApplication> | ||
{ | ||
public void Configure(EntityTypeBuilder<SubmittedApplication> builder) | ||
{ | ||
builder.HasKey(x => x.Id); | ||
|
||
builder.HasIndex(x => x.UserId); | ||
|
||
builder.Property(x => x.Name); | ||
builder.Property(x => x.Description); | ||
builder.Property(x => x.Plan); | ||
builder.Property(x => x.CreatedDateTime); | ||
|
||
builder.HasOne(x => x.Activity) | ||
.WithMany(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Infrastructure.DataAccess/Configurations/UnsumbittedApplicationConfiguration.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,24 @@ | ||
using Domain.Applications; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Metadata.Builders; | ||
|
||
namespace Infrastructure.DataAccess.Configurations; | ||
|
||
public class UnsumbittedApplicationConfiguration : IEntityTypeConfiguration<UnsubmittedApplication> | ||
{ | ||
public void Configure(EntityTypeBuilder<UnsubmittedApplication> builder) | ||
{ | ||
builder.HasKey(x => x.Id); | ||
|
||
builder.HasIndex(x => x.UserId) | ||
.IsUnique(); | ||
|
||
builder.Property(x => x.Name); | ||
builder.Property(x => x.Description); | ||
builder.Property(x => x.Plan); | ||
builder.Property(x => x.CreatedDateTime); | ||
|
||
builder.HasOne(x => x.Activity) | ||
.WithMany(); | ||
} | ||
} |
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,22 @@ | ||
using Application.Abstractions.DataAccess; | ||
using Domain.Applications; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Infrastructure.DataAccess; | ||
|
||
public class DatabaseContext : DbContext, IDatabaseContext | ||
{ | ||
public DatabaseContext(DbContextOptions<DatabaseContext> options) : base(options) | ||
{ | ||
Database.EnsureCreated(); | ||
} | ||
|
||
public DbSet<ApplicationActivity> ApplicationActivities { get; set; } | ||
public DbSet<UnsubmittedApplication> UnsubmittedApplications { get; set; } | ||
public DbSet<SubmittedApplication> SubmittedApplications { get; set; } | ||
|
||
protected override void OnModelCreating(ModelBuilder modelBuilder) | ||
{ | ||
modelBuilder.ApplyConfigurationsFromAssembly(typeof(IAssemblyMarker).Assembly); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
Infrastructure.DataAccess/Extensions/ServiceCollectionExtensions.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,18 @@ | ||
using Application.Abstractions.DataAccess; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Infrastructure.DataAccess.Extensions; | ||
|
||
public static class ServiceCollectionExtensions | ||
{ | ||
public static IServiceCollection AddDataAccess( | ||
this IServiceCollection collection, | ||
Action<DbContextOptionsBuilder> configuration) | ||
{ | ||
collection.AddDbContext<DatabaseContext>(configuration); | ||
collection.AddScoped<IDatabaseContext>(x => x.GetRequiredService<DatabaseContext>()); | ||
|
||
return collection; | ||
} | ||
} |
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 Infrastructure.DataAccess; | ||
|
||
public interface IAssemblyMarker { } |
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.