Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Domain/Entities/Github/GithubProfileData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public record GithubProfileData

public int MonthsToFetchCommits { get; init; }

public DateTime UserCreatedAt { get; init; }

public DateTime CreatedAt { get; init; }

public GithubProfileData()
Expand Down Expand Up @@ -105,6 +107,7 @@ public string GetTelegramFormattedText()

var result = $"Github stats for <b>{Username}</b>\n" +
$"Name: {Name}\n" +
$"Profile created: <em>{UserCreatedAt:yyyy-MM-dd}</em>\n" +
$"<em><a href=\"{HtmlUrl}\">Profile URL</a></em>\n\n" +
$"🌟 Social stats:\n" +
$"- Followers: <b>{Followers:N0}</b>\n" +
Expand Down
8 changes: 7 additions & 1 deletion src/Infrastructure/Services/Github/GithubGraphQLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ private GithubProfileData MapToGithubProfileData(
user.ContributionsCollection?.CommitContributionsByRepository,
topLanguagesCount),
MonthsToFetchCommits = monthsToFetchCommits,
CreatedAt = user.CreatedAt
UserCreatedAt = user.CreatedAt,
CreatedAt = DateTime.UtcNow,
};
}

Expand Down Expand Up @@ -487,10 +488,15 @@ public record UserProfile
public string Id { get; set; }
public string Name { get; set; }
public string Login { get; set; }

public string Url { get; set; }

public CountInfo Followers { get; set; }

public CountInfo Following { get; set; }

public CountInfo Repositories { get; set; }

public CountInfo StarredRepositories { get; set; }
public CountInfo Issues { get; set; }
public CountInfo PullRequests { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
namespace Web.Api.Features.Github.DeleteGithubProcessingJob;

#pragma warning disable SA1313
public record DeleteGithubProcessingJobCommand(
string Username);
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Threading;
using System.Threading.Tasks;
using Infrastructure.Database;
using Infrastructure.Services.Mediator;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;

namespace Web.Api.Features.Github.DeleteGithubProcessingJob;

public class DeleteGithubProcessingJobHandler : IRequestHandler<DeleteGithubProcessingJobCommand, Nothing>
{
private readonly DatabaseContext _context;

public DeleteGithubProcessingJobHandler(DatabaseContext context)
{
_context = context;
}

public async Task<Nothing> Handle(
DeleteGithubProcessingJobCommand request,
CancellationToken cancellationToken)
{
var job = await _context.GithubProfileProcessingJobs
.FirstOrDefaultAsync(x => x.Username == request.Username, cancellationToken);

if (job == null)
{
throw new BadHttpRequestException($"Github processing job with username '{request.Username}' not found");
}

_context.GithubProfileProcessingJobs.Remove(job);
await _context.TrySaveChangesAsync(cancellationToken);

return Nothing.Value;
}
}
37 changes: 37 additions & 0 deletions src/Web.Api/Features/Github/Dtos/GithubProfileBotChatDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using Domain.Entities.Github;

namespace Web.Api.Features.Github.Dtos;

public record GithubProfileBotChatDto
{
public Guid Id { get; init; }

public long ChatId { get; init; }

public string Username { get; init; }

public bool IsAdmin { get; init; }

public int MessagesCount { get; init; }

public DateTimeOffset CreatedAt { get; init; }

public DateTimeOffset UpdatedAt { get; init; }

public GithubProfileBotChatDto()
{
}

public GithubProfileBotChatDto(
GithubProfileBotChat chat)
{
Id = chat.Id;
ChatId = chat.ChatId;
Username = chat.Username;
IsAdmin = chat.IsAdmin;
MessagesCount = chat.MessagesCount;
CreatedAt = chat.CreatedAt;
UpdatedAt = chat.UpdatedAt;
}
}
34 changes: 34 additions & 0 deletions src/Web.Api/Features/Github/Dtos/GithubProfileDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using Domain.Entities.Github;

namespace Web.Api.Features.Github.Dtos;

public record GithubProfileDto
{
public string Username { get; init; }

public int Version { get; init; }

public int RequestsCount { get; init; }

public DateTime DataSyncedAt { get; init; }

public DateTimeOffset CreatedAt { get; init; }

public DateTimeOffset UpdatedAt { get; init; }

public GithubProfileDto()
{
}

public GithubProfileDto(
GithubProfile profile)
{
Username = profile.Username;
Version = profile.Version;
RequestsCount = profile.RequestsCount;
DataSyncedAt = profile.DataSyncedAt;
CreatedAt = profile.CreatedAt;
UpdatedAt = profile.UpdatedAt;
}
}
24 changes: 24 additions & 0 deletions src/Web.Api/Features/Github/Dtos/GithubProfileProcessingJobDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Domain.Entities.Github;

namespace Web.Api.Features.Github.Dtos;

public record GithubProfileProcessingJobDto
{
public string Username { get; init; }

public DateTimeOffset CreatedAt { get; init; }

public DateTimeOffset UpdatedAt { get; init; }

public GithubProfileProcessingJobDto()
{
}

public GithubProfileProcessingJobDto(GithubProfileProcessingJob job)
{
Username = job.Username;
CreatedAt = job.CreatedAt;
UpdatedAt = job.UpdatedAt;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Infrastructure.Database;
using Infrastructure.Services.Mediator;
using Microsoft.EntityFrameworkCore;
using Web.Api.Features.Github.Dtos;

namespace Web.Api.Features.Github.GetGithubProcessingJobs;

public class GetGithubProcessingJobsHandler : IRequestHandler<Nothing, GetGithubProcessingJobsResponse>
{
private readonly DatabaseContext _context;

public GetGithubProcessingJobsHandler(DatabaseContext context)
{
_context = context;
}

public async Task<GetGithubProcessingJobsResponse> Handle(
Nothing request,
CancellationToken cancellationToken)
{
var jobs = await _context.GithubProfileProcessingJobs
.OrderByDescending(x => x.CreatedAt)
.ToListAsync(cancellationToken);

return new GetGithubProcessingJobsResponse(
jobs.Select(x => new GithubProfileProcessingJobDto(x)).ToList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using System.Collections.Generic;
using Web.Api.Features.Github.Dtos;

namespace Web.Api.Features.Github.GetGithubProcessingJobs;

#pragma warning disable SA1313
public record GetGithubProcessingJobsResponse(
IReadOnlyCollection<GithubProfileProcessingJobDto> Results);
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Infrastructure.Database;
using Infrastructure.Services.Mediator;
using Microsoft.EntityFrameworkCore;
using Web.Api.Features.Github.Dtos;

namespace Web.Api.Features.Github.GetGithubProfileChats;

public class GetGithubProfileChatsHandler
: IRequestHandler<GetGithubProfileChatsQueryParams, GetGithubProfileChatsResponse>
{
private readonly DatabaseContext _context;

public GetGithubProfileChatsHandler(DatabaseContext context)
{
_context = context;
}

public async Task<GetGithubProfileChatsResponse> Handle(
GetGithubProfileChatsQueryParams request,
CancellationToken cancellationToken)
{
var chats = await _context.GithubProfileBotChats
.OrderByDescending(x => x.MessagesCount)
.ThenByDescending(x => x.CreatedAt)
.AsPaginatedAsync(
request,
cancellationToken);

return new GetGithubProfileChatsResponse(
chats.CurrentPage,
chats.PageSize,
chats.TotalItems,
chats.Results
.Select(x => new GithubProfileBotChatDto(x))
.ToList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Domain.ValueObjects.Pagination;

namespace Web.Api.Features.Github.GetGithubProfileChats;

public record GetGithubProfileChatsQueryParams : PageModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Domain.ValueObjects.Pagination;
using Web.Api.Features.Github.Dtos;

namespace Web.Api.Features.Github.GetGithubProfileChats;

#pragma warning disable SA1313
public record GetGithubProfileChatsResponse(
int CurrentPage,
int PageSize,
int TotalItems,
IReadOnlyCollection<GithubProfileBotChatDto> Results)
: Pageable<GithubProfileBotChatDto>(CurrentPage, PageSize, TotalItems, Results);
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Infrastructure.Database;
using Infrastructure.Services.Mediator;
using Microsoft.EntityFrameworkCore;
using Web.Api.Features.Github.Dtos;

namespace Web.Api.Features.Github.GetGithubProfiles;

public class GetGithubProfilesHandler : IRequestHandler<GetGithubProfilesQueryParams, GetGithubProfilesResponse>
{
private readonly DatabaseContext _context;

public GetGithubProfilesHandler(DatabaseContext context)
{
_context = context;
}

public async Task<GetGithubProfilesResponse> Handle(
GetGithubProfilesQueryParams request,
CancellationToken cancellationToken)
{
var profiles = await _context.GithubProfiles
.OrderByDescending(x => x.CreatedAt)
.AsPaginatedAsync(
request,
cancellationToken);

return new GetGithubProfilesResponse(
profiles.CurrentPage,
profiles.PageSize,
profiles.TotalItems,
profiles.Results
.Select(x => new GithubProfileDto(x))
.ToList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Domain.ValueObjects.Pagination;

namespace Web.Api.Features.Github.GetGithubProfiles;

public record GetGithubProfilesQueryParams : PageModel
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Collections.Generic;
using Domain.ValueObjects.Pagination;
using Web.Api.Features.Github.Dtos;

namespace Web.Api.Features.Github.GetGithubProfiles;

#pragma warning disable SA1313
public record GetGithubProfilesResponse(
int CurrentPage,
int PageSize,
int TotalItems,
IReadOnlyCollection<GithubProfileDto> Results)
: Pageable<GithubProfileDto>(CurrentPage, PageSize, TotalItems, Results);
Loading