Skip to content

Commit dab1614

Browse files
committed
fix(reactions): specify proper names for reaction counters in Cypher queries
1 parent b6bbc12 commit dab1614

File tree

5 files changed

+23
-16
lines changed

5 files changed

+23
-16
lines changed

src/CrowdParlay.Social.Api/Services/GlobalExceptionHandler.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Grpc.Core;
55
using Microsoft.AspNetCore.Diagnostics;
66
using Microsoft.AspNetCore.Mvc;
7+
using static Microsoft.AspNetCore.Http.StatusCodes;
78

89
namespace CrowdParlay.Social.Api.Services;
910

@@ -28,21 +29,21 @@ public async ValueTask<bool> TryHandleAsync(HttpContext context, Exception excep
2829
};
2930

3031
context.Response.ContentType = MediaTypeNames.Application.ProblemJson;
31-
context.Response.StatusCode = problemDetails.Status ?? StatusCodes.Status500InternalServerError;
32+
context.Response.StatusCode = problemDetails.Status ?? Status500InternalServerError;
3233
await context.Response.WriteAsJsonAsync(problemDetails, GlobalSerializerOptions.SnakeCase, cancellationToken);
3334

3435
return true;
3536
}
3637

3738
private static ProblemDetails GetDefaultProblemDetails() => new()
3839
{
39-
Status = (int)HttpStatusCode.InternalServerError,
40+
Status = Status500InternalServerError,
4041
Detail = "Something went wrong. Try again later.",
4142
};
4243

4344
private static ValidationProblemDetails ConvertToProblemDetails(ValidationException exception) => new()
4445
{
45-
Status = (int)HttpStatusCode.BadRequest,
46+
Status = Status400BadRequest,
4647
Detail = "The specified data is invalid.",
4748
Errors = exception.Errors.ToDictionary(
4849
x => x.Key,
@@ -51,7 +52,7 @@ public async ValueTask<bool> TryHandleAsync(HttpContext context, Exception excep
5152

5253
private static ValidationProblemDetails ConvertToProblemDetails(FluentValidation.ValidationException exception) => new()
5354
{
54-
Status = (int)HttpStatusCode.BadRequest,
55+
Status = Status400BadRequest,
5556
Detail = "The specified data is invalid.",
5657
Errors = exception.Errors
5758
.GroupBy(failure => failure.PropertyName)
@@ -64,19 +65,19 @@ public async ValueTask<bool> TryHandleAsync(HttpContext context, Exception excep
6465

6566
private static ProblemDetails GetNotFoundProblemDetails() => new()
6667
{
67-
Status = (int)HttpStatusCode.NotFound,
68+
Status = Status404NotFound,
6869
Detail = "The requested resource doesn't exist."
6970
};
7071

7172
private static ProblemDetails GetForbiddenProblemDetails() => new()
7273
{
73-
Status = (int)HttpStatusCode.Forbidden,
74+
Status = Status403Forbidden,
7475
Detail = "You have no permission for this action."
7576
};
7677

7778
private static ProblemDetails GetUnavailableDependencyProblemDetails() => new()
7879
{
79-
Status = (int)HttpStatusCode.ServiceUnavailable,
80+
Status = Status503ServiceUnavailable,
8081
Detail = "Failed to handle the request due to an unavailable dependency. Try again later."
8182
};
8283
}

src/CrowdParlay.Social.Infrastructure.Persistence/Services/CommentsRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ELSE [] END AS firstRepliesAuthorIds
2929
COUNT(reaction) AS reactionCount
3030
3131
WITH comment, author, replyCount, firstRepliesAuthorIds, viewerReactions,
32-
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactions
32+
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactionCounters
3333
3434
RETURN {
3535
Id: comment.Id,
@@ -38,7 +38,7 @@ ELSE [] END AS firstRepliesAuthorIds
3838
CreatedAt: comment.CreatedAt,
3939
ReplyCount: replyCount,
4040
FirstRepliesAuthorIds: firstRepliesAuthorIds,
41-
Reactions: reactions,
41+
ReactionCounters: reactionCounters,
4242
ViewerReactions: viewerReactions
4343
}
4444
""",
@@ -83,11 +83,11 @@ OPTIONAL MATCH (comment)<-[viewerReaction:REACTED_TO]-(:Author { Id: $viewerId }
8383
COUNT(reaction) AS reactionCount
8484
8585
WITH author, comment, deepReplyAuthor, deepReply, viewerReactions,
86-
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactions
86+
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactionCounters
8787
8888
ORDER BY comment.CreatedAt, deepReply.CreatedAt DESC
8989
90-
WITH author, comment, viewerReactions, reactions,
90+
WITH author, comment, viewerReactions, reactionCounters,
9191
COUNT(deepReply) AS deepReplyCount,
9292
COLLECT(DISTINCT deepReplyAuthor.Id)[0..3] AS firstDeepRepliesAuthorIds
9393
@@ -100,7 +100,7 @@ OPTIONAL MATCH (comment)<-[viewerReaction:REACTED_TO]-(:Author { Id: $viewerId }
100100
CreatedAt: comment.CreatedAt,
101101
ReplyCount: deepReplyCount,
102102
FirstRepliesAuthorIds: firstDeepRepliesAuthorIds,
103-
Reactions: reactions,
103+
ReactionCounters: reactionCounters,
104104
ViewerReactions: viewerReactions
105105
})[$offset..$offset + $count]
106106
}

src/CrowdParlay.Social.Infrastructure.Persistence/Services/DiscussionsRepository.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ OPTIONAL MATCH (discussion)<-[viewerReaction:REACTED_TO]-(:Author { Id: $viewerI
2222
COUNT(reaction) AS reactionCount
2323
2424
WITH author, discussion, viewerReactions,
25-
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactions
25+
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactionCounters
2626
2727
RETURN {
2828
Id: discussion.Id,
2929
Title: discussion.Title,
3030
Description: discussion.Description,
3131
AuthorId: author.Id,
3232
CreatedAt: discussion.CreatedAt,
33-
Reactions: reactions,
33+
ReactionCounters: reactionCounters,
3434
ViewerReactions: viewerReactions
3535
}
3636
""",
@@ -64,7 +64,7 @@ OPTIONAL MATCH (discussion)<-[viewerReaction:REACTED_TO]-(:Author { Id: $viewerI
6464
COUNT(reaction) AS reactionCount
6565
6666
WITH author, discussion, viewerReactions,
67-
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactions
67+
apoc.map.fromPairs(COLLECT([reaction.Value, reactionCount])) AS reactionCounters
6868
6969
ORDER BY discussion.CreatedAt DESC
7070
@@ -76,7 +76,7 @@ ORDER BY discussion.CreatedAt DESC
7676
Description: discussion.Description,
7777
AuthorId: author.Id,
7878
CreatedAt: discussion.CreatedAt,
79-
Reactions: reactions,
79+
ReactionCounters: reactionCounters,
8080
ViewerReactions: viewerReactions
8181
})[$offset..$offset + $count]
8282
}

tests/CrowdParlay.Social.IntegrationTests/Tests/CommentsRepositoryTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ public async Task CreateComment()
3636
comment.ReplyCount.Should().Be(0);
3737
comment.FirstRepliesAuthorIds.Should().BeEmpty();
3838
comment.CreatedAt.Should().BeCloseTo(DateTime.Now, TimeSpan.FromMinutes(1));
39+
comment.ReactionCounters.Should().BeEmpty();
40+
comment.ViewerReactions.Should().BeEmpty();
3941
}
4042

4143
[Fact(DisplayName = "Search comments")]
@@ -107,6 +109,8 @@ public async Task SearchComments()
107109
page.Items.Should().HaveCount(2);
108110
page.Items.Should().BeEquivalentTo([comment1, comment2]);
109111
page.Items.First().FirstRepliesAuthorIds.Should().BeEquivalentTo([authorId4, authorId2, authorId1]);
112+
page.Items.Should().OnlyContain(comment => comment.ReactionCounters.Count == 0);
113+
page.Items.Should().OnlyContain(comment => comment.ViewerReactions.Count == 0);
110114
}
111115

112116
[Fact(DisplayName = "Get comment with unknown ID")]

tests/CrowdParlay.Social.IntegrationTests/Tests/DiscussionsRepositoryTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ await discussions.CreateAsync(authorId, "Discussion 2", "numa numa e")
2828

2929
// Assert
3030
response.Items.Should().BeEquivalentTo(expectedDiscussions.Reverse());
31+
response.Items.Should().OnlyContain(discussion => discussion.ReactionCounters.Count == 0);
32+
response.Items.Should().OnlyContain(discussion => discussion.ViewerReactions.Count == 0);
3133
}
3234

3335
[Fact(DisplayName = "Get discussions by author of no discussions")]

0 commit comments

Comments
 (0)