Skip to content

Commit

Permalink
Refactoring Inc.TeamAssistant.Appraiser.DataAccess
Browse files Browse the repository at this point in the history
  • Loading branch information
dyatlov-a committed Dec 12, 2024
1 parent 50e4e3a commit 2638931
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public async Task<IReadOnlyDictionary<long, int>> GetStats(
"""
SELECT
sfe.participant_id AS personid,
count(*) AS eventscount
COUNT(*) AS eventscount
FROM appraiser.story_for_estimates AS sfe
JOIN appraiser.stories AS s ON sfe.story_id = s.id
WHERE s.created > @from AND sfe.participant_id = ANY(@person_ids) AND sfe.value > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using Inc.TeamAssistant.Appraiser.Domain;
using Npgsql;

namespace Inc.TeamAssistant.Appraiser.DataAccess.Internal;
namespace Inc.TeamAssistant.Appraiser.DataAccess;

internal static class GetStoryQuery
internal static class StoryProvider
{
public static async Task<IReadOnlyCollection<Story>> Get(
NpgsqlConnection connection,
Expand Down
9 changes: 4 additions & 5 deletions src/Inc.TeamAssistant.Appraiser.DataAccess/StoryReader.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Dapper;
using Inc.TeamAssistant.Appraiser.Application.Contracts;
using Inc.TeamAssistant.Appraiser.DataAccess.Internal;
using Inc.TeamAssistant.Appraiser.Domain;
using Inc.TeamAssistant.Primitives.DataAccess;

Expand Down Expand Up @@ -37,7 +36,7 @@ public async Task<IReadOnlyCollection<Story>> GetStories(
s.rounds_count AS roundscount,
s.url AS url
FROM appraiser.stories AS s
WHERE s.team_id = @team_id AND s.created <= @before AND (@from is null OR s.created >= @from);",
WHERE s.team_id = @team_id AND s.created <= @before AND (@from IS NULL OR s.created >= @from);",
new
{
team_id = teamId,
Expand Down Expand Up @@ -74,7 +73,7 @@ FROM appraiser.stories AS s
await using var connection = _connectionFactory.Create();

var storyIds = await connection.QueryAsync<Guid>(command);
var stories = await GetStoryQuery.Get(connection, storyIds.ToArray(), token);
var stories = await StoryProvider.Get(connection, storyIds.ToArray(), token);
var results = stories.OrderBy(p => p.Created).ToArray();

return results;
Expand All @@ -86,7 +85,7 @@ FROM appraiser.stories AS s
SELECT
s.id AS id
FROM appraiser.stories AS s
WHERE s.team_id = @team_id AND total_value is null
WHERE s.team_id = @team_id AND total_value IS NULL
ORDER BY s.created
OFFSET 0
LIMIT 1;",
Expand All @@ -100,7 +99,7 @@ OFFSET 0
if (!storyId.HasValue)
return null;

var stories = await GetStoryQuery.Get(connection, new[] { storyId.Value }, token);
var stories = await StoryProvider.Get(connection, new[] { storyId.Value }, token);
return stories.SingleOrDefault();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System.Text.Json;
using Dapper;
using Inc.TeamAssistant.Appraiser.Application.Contracts;
using Inc.TeamAssistant.Appraiser.DataAccess.Internal;
using Inc.TeamAssistant.Appraiser.Domain;
using Inc.TeamAssistant.Primitives.DataAccess;

Expand All @@ -20,7 +18,7 @@ public StoryRepository(IConnectionFactory connectionFactory)
{
await using var connection = _connectionFactory.Create();

var stories = await GetStoryQuery.Get(connection, new[] { storyId }, token);
var stories = await StoryProvider.Get(connection, new[] { storyId }, token);

return stories.SingleOrDefault();
}
Expand Down

0 comments on commit 2638931

Please sign in to comment.