Skip to content

Commit

Permalink
Fully removed Automapper 🎉
Browse files Browse the repository at this point in the history
  • Loading branch information
Atulin committed Sep 6, 2024
1 parent 1f5ceab commit c0087d5
Show file tree
Hide file tree
Showing 15 changed files with 2,340 additions and 73 deletions.
6 changes: 4 additions & 2 deletions Ogma3/Api/V1/Comments/Queries/GetComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ public async ValueTask<ActionResult<CommentDto>> Handle(Query request, Cancellat
var comment = await context.Comments
.Where(c => c.Id == request.Id)
.Select(CommentMappings.ToCommentDto(_uid))
.AsNoTracking()
.FirstOrDefaultAsync(cancellationToken);

if (comment is null) return NotFound();

comment.Body = Markdown.ToHtml(comment.Body, MarkdownPipelines.Comment);
if (comment.Body is not null)
{
comment.Body = Markdown.ToHtml(comment.Body, MarkdownPipelines.Comment);
}

return Ok(comment);
}
Expand Down
7 changes: 5 additions & 2 deletions Ogma3/Api/V1/Comments/Queries/GetPaginatedComments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ public async ValueTask<ActionResult<PaginationResult<CommentDto>>> Handle(Query
.Where(c => c.CommentsThreadId == thread)
.OrderByDescending(c => c.DateTime)
.Select(CommentMappings.ToCommentDto(userService.User?.GetNumericId()))
.AsNoTracking()
.Paginate(p, ogmaConfig.CommentsPerPage)
.ToListAsync(cancellationToken);

comments.ForEach(c => c.Body = Markdown.ToHtml(c.Body, MarkdownPipelines.Comment));
foreach (var comment in comments)
{
if (comment.Body is null) continue;
comment.Body = Markdown.ToHtml(comment.Body, MarkdownPipelines.Comment);
}

return new PaginationResult<CommentDto>
{
Expand Down
20 changes: 4 additions & 16 deletions Ogma3/CompiledModels/ApplicationDbContextModelBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,17 +1148,11 @@ private IRelationalModel CreateRelationalModel()
var ogma3DataClubsClubTableBase = new TableBase("Ogma3.Data.Clubs.Club", null, relationalModel);
var creationDateColumnBase3 = new ColumnBase<ColumnMappingBase>("CreationDate", "timestamp without time zone", ogma3DataClubsClubTableBase);
ogma3DataClubsClubTableBase.Columns.Add("CreationDate", creationDateColumnBase3);
var descriptionColumnBase0 = new ColumnBase<ColumnMappingBase>("Description", "character varying(25000)", ogma3DataClubsClubTableBase)
{
IsNullable = true
};
var descriptionColumnBase0 = new ColumnBase<ColumnMappingBase>("Description", "character varying(25000)", ogma3DataClubsClubTableBase);
ogma3DataClubsClubTableBase.Columns.Add("Description", descriptionColumnBase0);
var hookColumnBase = new ColumnBase<ColumnMappingBase>("Hook", "character varying(100)", ogma3DataClubsClubTableBase);
ogma3DataClubsClubTableBase.Columns.Add("Hook", hookColumnBase);
var iconColumnBase = new ColumnBase<ColumnMappingBase>("Icon", "text", ogma3DataClubsClubTableBase)
{
IsNullable = true
};
var iconColumnBase = new ColumnBase<ColumnMappingBase>("Icon", "text", ogma3DataClubsClubTableBase);
ogma3DataClubsClubTableBase.Columns.Add("Icon", iconColumnBase);
var iconIdColumnBase = new ColumnBase<ColumnMappingBase>("IconId", "text", ogma3DataClubsClubTableBase)
{
Expand Down Expand Up @@ -1192,17 +1186,11 @@ private IRelationalModel CreateRelationalModel()
idColumn6.AddAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
var creationDateColumn3 = new Column("CreationDate", "timestamp without time zone", clubsTable);
clubsTable.Columns.Add("CreationDate", creationDateColumn3);
var descriptionColumn0 = new Column("Description", "character varying(25000)", clubsTable)
{
IsNullable = true
};
var descriptionColumn0 = new Column("Description", "character varying(25000)", clubsTable);
clubsTable.Columns.Add("Description", descriptionColumn0);
var hookColumn = new Column("Hook", "character varying(100)", clubsTable);
clubsTable.Columns.Add("Hook", hookColumn);
var iconColumn = new Column("Icon", "text", clubsTable)
{
IsNullable = true
};
var iconColumn = new Column("Icon", "text", clubsTable);
clubsTable.Columns.Add("Icon", iconColumn);
var iconIdColumn = new Column("IconId", "text", clubsTable)
{
Expand Down
4 changes: 1 addition & 3 deletions Ogma3/CompiledModels/ClubEntityType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
typeof(string),
propertyInfo: typeof(Club).GetProperty("Description", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(Club).GetField("<Description>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
nullable: true,
maxLength: 25000);
description.TypeMapping = NpgsqlStringTypeMapping.Default.Clone(
comparer: new ValueComparer<string>(
Expand Down Expand Up @@ -126,8 +125,7 @@ public static RuntimeEntityType Create(RuntimeModel model, RuntimeEntityType bas
"Icon",
typeof(string),
propertyInfo: typeof(Club).GetProperty("Icon", BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly),
fieldInfo: typeof(Club).GetField("<Icon>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly),
nullable: true);
fieldInfo: typeof(Club).GetField("<Icon>k__BackingField", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly));
icon.TypeMapping = StringTypeMapping.Default.Clone(
comparer: new ValueComparer<string>(
(string v1, string v2) => v1 == v2,
Expand Down
2 changes: 1 addition & 1 deletion Ogma3/Data/Clubs/Club.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Club : BaseModel, IReportableContent
public required string Hook { get; set; }
public required string Description { get; set; }
public required string Icon { get; set; }
public required string IconId { get; set; }
public required string? IconId { get; set; }
public DateTime CreationDate { get; set; }
public ICollection<ClubMember> ClubMembers { get; set; } = [];
public ICollection<OgmaUser> BannedUsers { get; set; } = [];
Expand Down
3 changes: 2 additions & 1 deletion Ogma3/Data/Stories/StoryMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ namespace Ogma3.Data.Stories;
[Mapper]
public static partial class StoryMapper
{
public static partial IQueryable<StoryCard> ProjectToCard(this IQueryable<Story> q);

[MapProperty(nameof(Story.Tags), nameof(StoryCard.Tags), Use = nameof(MapOrderedTags))]

Check warning on line 12 in Ogma3/Data/Stories/StoryMapper.cs

View workflow job for this annotation

GitHub Actions / build

The target type Ogma3.Data.Tags.TagDto[] of the referenced mapping MapOrderedTags does not match the expected type System.Collections.Generic.IEnumerable<Ogma3.Data.Tags.TagDto>

Check warning on line 12 in Ogma3/Data/Stories/StoryMapper.cs

View workflow job for this annotation

GitHub Actions / build

The target type Ogma3.Data.Tags.TagDto[] of the referenced mapping MapOrderedTags does not match the expected type System.Collections.Generic.IEnumerable<Ogma3.Data.Tags.TagDto>

Check warning on line 12 in Ogma3/Data/Stories/StoryMapper.cs

View workflow job for this annotation

GitHub Actions / build

The target type Ogma3.Data.Tags.TagDto[] of the referenced mapping MapOrderedTags does not match the expected type System.Collections.Generic.IEnumerable<Ogma3.Data.Tags.TagDto>

Check warning on line 12 in Ogma3/Data/Stories/StoryMapper.cs

View workflow job for this annotation

GitHub Actions / build

The target type Ogma3.Data.Tags.TagDto[] of the referenced mapping MapOrderedTags does not match the expected type System.Collections.Generic.IEnumerable<Ogma3.Data.Tags.TagDto>
public static partial StoryCard ProjectToCard(this Story story);
public static partial IQueryable<StoryCard> ProjectToCard(this IQueryable<Story> q);

private static TagDto[] MapOrderedTags(IEnumerable<Tag> tags)
=> tags.OrderByDescending(t => t.Namespace.HasValue).ThenByDescending(t => t.Namespace).Select(t => t.ToDto()).ToArray();
Expand Down
Loading

0 comments on commit c0087d5

Please sign in to comment.