-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expressed realms 169 - Implemented Expression Section Repository (#171)
- Created Copy of the expression table repo, and renamed things to say text section - Moved logic for page load into sub section stuff - Creating an expression section should now be fully in place - Edit should now be in place - Delete should now be updated - Fully implemented getting expression details This includes getting possible parents - Create and Edit now handle Parent Id Fixed recursion issues - Split out the options stuff into separate call It now is compatible with both create and edit actions
- Loading branch information
1 parent
0ef3e74
commit 4aa1f6b
Showing
20 changed files
with
1,626 additions
and
2 deletions.
There are no files selected for viewing
1,032 changes: 1,032 additions & 0 deletions
1,032
...xpressedRealms.DB/Migrations/20241016050633_MakeExpressionSectionsSoftDeletes.Designer.cs
Large diffs are not rendered by default.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
api/ExpressedRealms.DB/Migrations/20241016050633_MakeExpressionSectionsSoftDeletes.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,58 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace ExpressedRealms.DB.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class MakeExpressionSectionsSoftDeletes : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.AlterColumn<int>( | ||
name: "PublishStatusId", | ||
table: "Expressions", | ||
type: "integer", | ||
nullable: false, | ||
defaultValue: 1, | ||
oldClrType: typeof(int), | ||
oldType: "integer"); | ||
|
||
migrationBuilder.AddColumn<DateTimeOffset>( | ||
name: "DeletedAt", | ||
table: "ExpressionSections", | ||
type: "timestamp with time zone", | ||
nullable: true); | ||
|
||
migrationBuilder.AddColumn<bool>( | ||
name: "IsDeleted", | ||
table: "ExpressionSections", | ||
type: "boolean", | ||
nullable: false, | ||
defaultValue: false); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropColumn( | ||
name: "DeletedAt", | ||
table: "ExpressionSections"); | ||
|
||
migrationBuilder.DropColumn( | ||
name: "IsDeleted", | ||
table: "ExpressionSections"); | ||
|
||
migrationBuilder.AlterColumn<int>( | ||
name: "PublishStatusId", | ||
table: "Expressions", | ||
type: "integer", | ||
nullable: false, | ||
oldClrType: typeof(int), | ||
oldType: "integer", | ||
oldDefaultValue: 1); | ||
} | ||
} | ||
} |
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
5 changes: 4 additions & 1 deletion
5
api/ExpressedRealms.DB/Models/Expressions/ExpressionSection.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
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
10 changes: 10 additions & 0 deletions
10
...ms.Repositories.Expressions/ExpressionTextSections/DTOs/CreateExpressionTextSectionDto.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,10 @@ | ||
namespace ExpressedRealms.Repositories.Expressions.Expressions.DTOs; | ||
|
||
public record CreateExpressionTextSectionDto | ||
{ | ||
public string Name { get; set; } = null!; | ||
public string Content { get; set; } = null!; | ||
public int ExpressionId { get; set; } | ||
public int SectionTypeId { get; set; } | ||
public int? ParentId { get; set; } | ||
} |
58 changes: 58 additions & 0 deletions
58
...tories.Expressions/ExpressionTextSections/DTOs/CreateExpressionTextSectionDtoValidator.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,58 @@ | ||
using ExpressedRealms.DB; | ||
using ExpressedRealms.Repositories.Expressions.ExpressionTextSections.Helpers; | ||
using FluentValidation; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ExpressedRealms.Repositories.Expressions.Expressions.DTOs; | ||
|
||
public class CreateExpressionTextSectionDtoValidator | ||
: AbstractValidator<CreateExpressionTextSectionDto> | ||
{ | ||
public CreateExpressionTextSectionDtoValidator(ExpressedRealmsDbContext dbContext) | ||
{ | ||
RuleFor(x => x.Name).MaximumLength(50).NotEmpty(); | ||
RuleFor(x => x.Content).NotEmpty(); | ||
RuleFor(x => x.SectionTypeId) | ||
.MustAsync( | ||
async (sectionTypeId, cancellationToken) => | ||
{ | ||
return await dbContext.ExpressionSectionTypes.AnyAsync( | ||
x => x.Id == sectionTypeId, | ||
cancellationToken | ||
); | ||
} | ||
) | ||
.WithMessage("This is not a valid Section Type"); | ||
RuleFor(x => x.ExpressionId) | ||
.MustAsync( | ||
async (expressionId, cancellationToken) => | ||
{ | ||
return await dbContext.Expressions.AnyAsync( | ||
x => x.Id == expressionId, | ||
cancellationToken | ||
); | ||
} | ||
) | ||
.WithMessage("This is not a valid Expression Id"); | ||
RuleFor(x => x) | ||
.MustAsync( | ||
async (expressionSection, cancellationToken) => | ||
{ | ||
var expressionSections = await dbContext | ||
.ExpressionSections.Where(x => | ||
x.ExpressionId == expressionSection.ExpressionId | ||
) | ||
.ToListAsync(); | ||
|
||
var validParentIds = RecursiveFunctions.GetValidParentIds( | ||
expressionSections, | ||
null, | ||
0 | ||
); | ||
return validParentIds.Contains(expressionSection.ParentId.Value); | ||
} | ||
) | ||
.When(x => x.ParentId != null) | ||
.WithMessage("This is not a valid Parent Id"); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...alms.Repositories.Expressions/ExpressionTextSections/DTOs/EditExpressionTextSectionDto.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 @@ | ||
namespace ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public record EditExpressionTextSectionDto | ||
{ | ||
public int Id { get; init; } | ||
public string Name { get; set; } = null!; | ||
public string Content { get; set; } = null!; | ||
public int ExpressionId { get; set; } | ||
public int SectionTypeId { get; set; } | ||
public int? ParentId { get; set; } | ||
} |
58 changes: 58 additions & 0 deletions
58
...sitories.Expressions/ExpressionTextSections/DTOs/EditExpressionTextSectionDtoValidator.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,58 @@ | ||
using ExpressedRealms.DB; | ||
using ExpressedRealms.Repositories.Expressions.ExpressionTextSections.Helpers; | ||
using FluentValidation; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class EditExpressionTextSectionDtoValidator : AbstractValidator<EditExpressionTextSectionDto> | ||
{ | ||
public EditExpressionTextSectionDtoValidator(ExpressedRealmsDbContext dbContext) | ||
{ | ||
RuleFor(x => x.Id).NotEmpty().GreaterThan(0); | ||
RuleFor(x => x.Name).MaximumLength(50).NotEmpty(); | ||
RuleFor(x => x.Content).NotEmpty(); | ||
RuleFor(x => x.SectionTypeId) | ||
.MustAsync( | ||
async (sectionTypeId, cancellationToken) => | ||
{ | ||
return await dbContext.ExpressionSectionTypes.AnyAsync( | ||
x => x.Id == sectionTypeId, | ||
cancellationToken | ||
); | ||
} | ||
) | ||
.WithMessage("This is not a valid Section Type"); | ||
RuleFor(x => x.ExpressionId) | ||
.MustAsync( | ||
async (expressionId, cancellationToken) => | ||
{ | ||
return await dbContext.Expressions.AnyAsync( | ||
x => x.Id == expressionId, | ||
cancellationToken | ||
); | ||
} | ||
) | ||
.WithMessage("This is not a valid Expression Id"); | ||
RuleFor(x => x) | ||
.MustAsync( | ||
async (expressionSection, cancellationToken) => | ||
{ | ||
var expressionSections = await dbContext | ||
.ExpressionSections.Where(x => | ||
x.ExpressionId == expressionSection.ExpressionId | ||
) | ||
.ToListAsync(); | ||
|
||
var validParentIds = RecursiveFunctions.GetValidParentIds( | ||
expressionSections, | ||
null, | ||
0 | ||
); | ||
return validParentIds.Contains(expressionSection.ParentId.Value); | ||
} | ||
) | ||
.When(x => x.ParentId != null) | ||
.WithMessage("This is not a valid Parent Id"); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...ressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/ExpressionSectionDto.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,9 @@ | ||
namespace ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class ExpressionSectionDto | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } | ||
public string Content { get; set; } | ||
public List<ExpressionSectionDto> SubSections { get; set; } = new(); | ||
} |
8 changes: 8 additions & 0 deletions
8
...edRealms.Repositories.Expressions/ExpressionTextSections/DTOs/ExpressionTextSectionDto.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 @@ | ||
namespace ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public record ExpressionTextSectionDto | ||
{ | ||
public string Name { get; set; } = null!; | ||
public string ShortDescription { get; set; } = null!; | ||
public string NavMenuImage { get; set; } = null!; | ||
} |
7 changes: 7 additions & 0 deletions
7
...alms.Repositories.Expressions/ExpressionTextSections/DTOs/ExpressionTextSectionOptions.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 ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class ExpressionTextSectionOptions | ||
{ | ||
public List<ExpressionSectionDto> AvailableParents { get; set; } = null!; | ||
public List<SectionTypeDto> ExpressionSectionTypes { get; set; } = null!; | ||
} |
12 changes: 12 additions & 0 deletions
12
api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/GetExpressionDto.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 ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class GetExpressionTextSectionDto | ||
{ | ||
public int Id { get; init; } | ||
public string Name { get; set; } = null!; | ||
public string Content { get; set; } | ||
public int? ParentId { get; set; } | ||
public int SectionTypeId { get; set; } | ||
public List<SectionTypeDto> SectionTypes { get; set; } = null!; | ||
public List<ExpressionSectionDto> AvailableParents { get; set; } | ||
} |
7 changes: 7 additions & 0 deletions
7
...epositories.Expressions/ExpressionTextSections/DTOs/GetExpressionTestSectionOptionsDto.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 ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class GetExpressionTestSectionOptionsDto | ||
{ | ||
public int ExpressionId { get; set; } | ||
public int? SectionId { get; set; } | ||
} |
36 changes: 36 additions & 0 deletions
36
...ories.Expressions/ExpressionTextSections/DTOs/GetExpressionTestSectionOptionsValidator.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,36 @@ | ||
using ExpressedRealms.DB; | ||
using FluentValidation; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class GetExpressionTestSectionOptionsValidator | ||
: AbstractValidator<GetExpressionTestSectionOptionsDto> | ||
{ | ||
public GetExpressionTestSectionOptionsValidator(ExpressedRealmsDbContext dbContext) | ||
{ | ||
RuleFor(x => x.SectionId) | ||
.MustAsync( | ||
async (sectionId, cancellationToken) => | ||
{ | ||
return await dbContext.ExpressionSections.AnyAsync( | ||
x => x.Id == sectionId, | ||
cancellationToken | ||
); | ||
} | ||
) | ||
.When(x => x.SectionId is not null) | ||
.WithMessage("This is not a valid Section"); | ||
RuleFor(x => x.ExpressionId) | ||
.MustAsync( | ||
async (expressionId, cancellationToken) => | ||
{ | ||
return await dbContext.Expressions.AnyAsync( | ||
x => x.Id == expressionId, | ||
cancellationToken | ||
); | ||
} | ||
) | ||
.WithMessage("This is not a valid Expression Id"); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
api/ExpressedRealms.Repositories.Expressions/ExpressionTextSections/DTOs/SectionTypeDto.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 @@ | ||
namespace ExpressedRealms.Repositories.Expressions.ExpressionTextSections.DTOs; | ||
|
||
public class SectionTypeDto | ||
{ | ||
public int Id { get; set; } | ||
public string Name { get; set; } = null!; | ||
public string? Description { get; set; } | ||
} |
Oops, something went wrong.