diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/DatabaseTeam.razor b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/DatabaseTeam.razor
new file mode 100644
index 0000000..7194bcf
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/DatabaseTeam.razor
@@ -0,0 +1,124 @@
+@page "/databaseTeam"
+@using Kysect.GithubActivityAnalyzer.WebDemo.Shared
+@using Kysect.GithubActivityAnalyzer.Aggregators.Models
+@inject HttpClient Http
+
TestFunc
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+@if (_teamName == null && !_statsIsVisible)
+{
+ Please write group name
+}
+else
+{
+ Team name: @_teamName
+}
+@if (_usernames.Count == 0 && !_statsIsVisible)
+{
+ Add names
+}
+else
+{
+
+
+ | Имя |
+
+
+ @for (int i = 0; i < _usernames.Count; i++)
+ {
+ | @_usernames[i] |
+ }
+
+
+}
+@if (_statsIsVisible)
+{
+ All Contributions: @_team.TotalContributions
+
+
+ | Username | Contributions: |
+
+
+ @foreach (var person in _team.DetailedStatisticsList[0].DetailedStat)
+ {
+ | @person.Username | @person.MonthlyContributions |
+
+ }
+
+
+
+}
+
+@code {
+ private string _username = String.Empty;
+ private string _teamName = String.Empty;
+ private List _usernames = new List();
+ private TeamResponse _team;
+ private bool _statsIsVisible = false;
+ private bool _result;
+
+ private void ClearTeamList()
+ {
+ _usernames.Clear();
+ }
+ private void AddMember()
+ {
+ _usernames.Add(_username);
+ }
+ protected async Task GetStat()
+ {
+ Team newGroupInfo = new Team()
+ {
+ TeamName = _teamName,
+ Usernames = _usernames
+ };
+ var response = await Http.PostAsJsonAsync("Team", newGroupInfo);
+ _team = await response.Content.ReadFromJsonAsync();
+ _statsIsVisible = true;
+ }
+
+ protected async Task AddTeam()
+ {
+ Team newTeam = new Team()
+ {
+ TeamName = _teamName,
+ Usernames = _usernames
+ };
+ await Http.PostAsJsonAsync("DBTeam/addTeam", newTeam);
+ }
+ protected async Task DeleteTeam()
+ {
+ Team team = new Team()
+ {
+ TeamName = _teamName,
+ Usernames = _usernames
+ };
+ await Http.PostAsJsonAsync("DBTeam/deleteTeam", _teamName);
+ }
+ protected async Task DeleteMember()
+ {
+ await Http.PostAsJsonAsync("DBTeam/deleteMember", _username);
+ }
+
+ @*
+ protected async Task UpdateMember()
+ {
+ await Http.PostAsJsonAsync("DBTeam/updateMember");
+ }
+ protected async Task GetAllTeams()
+ {
+ }
+ protected async Task GetTeam() { }*@
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/FetchData.razor b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/FetchData.razor
deleted file mode 100644
index 43e1a0a..0000000
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/FetchData.razor
+++ /dev/null
@@ -1,46 +0,0 @@
-@page "/fetchdata"
-@using Kysect.GithubActivityAnalyzer.WebDemo.Shared
-@inject HttpClient Http
-
-Weather forecast
-
-This component demonstrates fetching data from the server.
-
-@if (forecasts == null)
-{
- Loading...
-}
-else
-{
-
-
-
- | Date |
- Temp. (C) |
- Temp. (F) |
- Summary |
-
-
-
- @foreach (var forecast in forecasts)
- {
-
- | @forecast.Date.ToShortDateString() |
- @forecast.TemperatureC |
- @forecast.TemperatureF |
- @forecast.Summary |
-
- }
-
-
-}
-
-@code {
- private WeatherForecast[] forecasts;
-
- protected override async Task OnInitializedAsync()
- {
- forecasts = await Http.GetFromJsonAsync("WeatherForecast");
- }
-
-}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/GetStudyGroup.razor b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/GetStudyGroup.razor
deleted file mode 100644
index 6284dc6..0000000
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/GetStudyGroup.razor
+++ /dev/null
@@ -1,84 +0,0 @@
-@page "/getstudyGroup"
-@using Kysect.GithubActivityAnalyzer.WebDemo.Shared
-@using Kysect.GithubActivityAnalyzer.Aggregators.Models
-@inject HttpClient Http
-TestFunc
-
-
-
-
-
-
-
-
-
-
-@if (GroupName == null && !StatsIsVisible)
-{
- Please write group name
-}
-else
-{
- Group name: @GroupName
-}
-@if (Usernames.Count == 0 && !StatsIsVisible)
-{
- Add names
-}
-else
-{
-
-
- | Имя |
-
-
- @for (int i = 0; i < Usernames.Count; i++)
- {
- | @Usernames[i] |
- }
-
-
-}
-@if (StatsIsVisible)
-{
- All Contributions: @_studyGroup.TotalContributions
-
-
- | Username | Contributions: |
-
-
- @foreach (var person in _studyGroup.DetailedStatisticsList[0].DetailedStat)
- {
- | @person.Username | @person.MonthlyContributions |
-
- }
-
-
-
-}
-
-@code {
- private string Username { get; set; } = String.Empty;
- private string GroupName { get; set; } = String.Empty;
- private List Usernames { get; set; } = new List();
- private StudyGroupResponse _studyGroup;
- private bool StatsIsVisible { get; set; } = false;
-
-
- protected async Task GetStat()
- {
- GroupStatRequest newGroupInfo = new GroupStatRequest()
- {
- GroupName = GroupName,
- usernames = Usernames
- };
- var response = await Http.PostAsJsonAsync("StudyGroup", newGroupInfo);
- _studyGroup = await response.Content.ReadFromJsonAsync();
- StatsIsVisible = true;
- }
-
- private void AddStudent()
- {
- Usernames.Add(Username);
- }
-}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/GetTeam.razor b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/GetTeam.razor
new file mode 100644
index 0000000..3f7b376
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/GetTeam.razor
@@ -0,0 +1,84 @@
+@page "/Team"
+@using Kysect.GithubActivityAnalyzer.WebDemo.Shared
+@using Kysect.GithubActivityAnalyzer.Aggregators.Models
+@inject HttpClient Http
+TestFunc
+
+
+
+
+
+
+
+
+
+
+@if (_teamName == null && !_statsIsVisible)
+{
+ Please write team name
+}
+else
+{
+ Team name: @_teamName
+}
+@if (_usernames.Count == 0 && !_statsIsVisible)
+{
+ Add names
+}
+else
+{
+
+
+ | Имя |
+
+
+ @for (int i = 0; i < _usernames.Count; i++)
+ {
+ | @_usernames[i] |
+ }
+
+
+}
+@if (_statsIsVisible)
+{
+ All Contributions: @_team.TotalContributions
+
+
+ | Username | Contributions: |
+
+
+ @foreach (var person in _team.DetailedStatisticsList[0].DetailedStat)
+ {
+ | @person.Username | @person.MonthlyContributions |
+
+ }
+
+
+
+}
+
+@code {
+ private string _username = String.Empty;
+ private string _teamName = String.Empty;
+ private List _usernames = new List();
+ private TeamResponse _team;
+ private bool _statsIsVisible = false;
+
+
+ protected async Task GetStat()
+ {
+ Team newTeamInfo = new Team()
+ {
+ TeamName = _teamName,
+ Usernames = _usernames
+ };
+ var response = await Http.PostAsJsonAsync("Team", newTeamInfo);
+ _team = await response.Content.ReadFromJsonAsync();
+ _statsIsVisible = true;
+ }
+
+ private void AddStudent()
+ {
+ _usernames.Add(_username);
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/TestPage.razor b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/TestPage.razor
index b6bbb16..5b1e9f8 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/TestPage.razor
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Pages/TestPage.razor
@@ -1,37 +1,42 @@
@page "/testpage"
-@using System.Text.Json
@using Kysect.GithubActivityAnalyzer.ApiAccessor.ApiResponses
@inject HttpClient Http
TestFunc
-
+
-
-@if(SetName == null)
+
+
+@if(_setName == null)
{
Please write name
}
else
{
- Name: @SetName
+ Name: @_setName
}
-@if (Info == null)
+@if (_info == null)
{
Please wait...
}
else
{
- Contributions: @Info.Total
+ Contributions: @_info.Total
}
@code {
- private string SetName { get; set; } = String.Empty;
- private ActivityInfo Info { get; set; }
+ private string _setName = String.Empty;
+ private ActivityInfo _info;
- protected async Task CreateClient()
+ protected async Task GetActivityFromGithub()
{
- Info = await Http.GetFromJsonAsync($"GitHubApi?username={SetName}");
+ _info = await Http.GetFromJsonAsync($"GitHubApi/fromGithub?username={_setName}");
+ }
+
+ protected async Task GetActivityFromDB()
+ {
+ _info = await Http.GetFromJsonAsync($"GitHubApi/fromDB?username={_setName}");
}
}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Shared/NavMenu.razor b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Shared/NavMenu.razor
index e2366cb..f51aaaf 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Client/Shared/NavMenu.razor
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Client/Shared/NavMenu.razor
@@ -18,18 +18,18 @@
-
- Fetch data
+
+ Test Page
-
- Test Page
+
+ Team
-
- StudyGroup
+
+ DatabaseTeam
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DBTeamController.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DBTeamController.cs
new file mode 100644
index 0000000..637d300
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DBTeamController.cs
@@ -0,0 +1,50 @@
+using Kysect.GithubActivityAnalyzer.WebDemo.Server.Services;
+using Kysect.GithubActivityAnalyzer.WebDemo.Shared;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Controllers
+{
+ [ApiController]
+ [Route("[controller]")]
+ public class DBTeamController : Controller
+ {
+ private readonly ITeamService _teamService;
+ public DBTeamController(ITeamService teamService)
+ {
+ _teamService = teamService;
+ }
+
+ [HttpPost("addTeam")]
+ public void AddTeam(Team newTeam)
+ {
+ _teamService.AddTeam(newTeam);
+ }
+
+ [HttpPost("deleteTeam")]
+ public void DeleteTeam(string teamName)
+ {
+ _teamService.DeleteTeam(teamName);
+ }
+
+ [HttpPost("deleteMember")]
+ public void DeleteMember(string username)
+ {
+ _teamService.DeleteMember(username);
+ }
+
+ [HttpPost("updateMember")]
+ public void UpdateMember()
+ {
+ }
+
+ [HttpGet("GetAllTeams")]
+ public void GetAllTeams()
+ {
+ }
+
+ [HttpGet("GetTeam")]
+ public void GetTeam()
+ {
+ }
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DetailedGroupStatController.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DetailedTeamStatController.cs
similarity index 61%
rename from Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DetailedGroupStatController.cs
rename to Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DetailedTeamStatController.cs
index 895e880..0b72ef9 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DetailedGroupStatController.cs
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/DetailedTeamStatController.cs
@@ -1,19 +1,14 @@
using Microsoft.AspNetCore.Mvc;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text.Json;
-using System.Threading.Tasks;
using Kysect.GithubActivityAnalyzer.ApiAccessor;
-using Kysect.GithubActivityAnalyzer.WebDemo.Shared;
+
namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Controllers
{
[ApiController]
[Route("[controller]")]
- public class DetailedGroupStatController : Controller
+ public class DetailedTeamStatController : Controller
{
- private GithubActivityProvider _provider = new GithubActivityProvider();
+ private readonly GithubActivityProvider _provider = new GithubActivityProvider();
/*[HttpPost]
public IEnumerable GetGroupInfos(DetaiedStatRequest request)
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/GitHubApiController.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/GitHubApiController.cs
index 466a021..d0b705a 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/GitHubApiController.cs
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/GitHubApiController.cs
@@ -1,6 +1,5 @@
-using System.Text.Json;
-using Kysect.GithubActivityAnalyzer.ApiAccessor;
-using Kysect.GithubActivityAnalyzer.ApiAccessor.ApiResponses;
+using Kysect.GithubActivityAnalyzer.ApiAccessor.ApiResponses;
+using Kysect.GithubActivityAnalyzer.WebDemo.Server.Services;
using Microsoft.AspNetCore.Mvc;
namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Controllers
@@ -9,12 +8,22 @@ namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Controllers
[Route("[controller]")]
public class GitHubApiController : Controller
{
- private GithubActivityProvider provider = new GithubActivityProvider();
+ private readonly IActivityService _activityService;
+ public GitHubApiController(IActivityService activityService)
+ {
+ _activityService = activityService;
+ }
+
+ [HttpGet("fromGithub")]
+ public ActivityInfo OnGetFromGithub(string username)
+ {
+ return _activityService.GetActivityInfoFromGithub(username).Result;
+ }
- [HttpGet]
- public ActivityInfo Get(string username)
+ [HttpGet("FromDB")]
+ public ActivityInfo OnGetFromDB(string username)
{
- return provider.GetActivityInfo(username).Result;
+ return _activityService.GetActivityInfoFromDB(username);
}
}
}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/StudyGroupController.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/TeamController.cs
similarity index 55%
rename from Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/StudyGroupController.cs
rename to Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/TeamController.cs
index 1f64bfe..8ed4b79 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/StudyGroupController.cs
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/TeamController.cs
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Mvc;
-using System.Text.Json;
using Kysect.GithubActivityAnalyzer.Aggregators;
using Kysect.GithubActivityAnalyzer.Aggregators.Models;
using Kysect.GithubActivityAnalyzer.ApiAccessor;
@@ -9,14 +8,14 @@ namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Controllers
{
[ApiController]
[Route("[controller]")]
- public class StudyGroupController : Controller
+ public class TeamController : Controller
{
- private GithubActivityProvider _provider = new GithubActivityProvider();
+ private readonly GithubActivityProvider _provider = new GithubActivityProvider();
[HttpPost]
- public StudyGroupResponse GetStudyGroup(GroupStatRequest info)
+ public TeamResponse GetStudyGroup(Shared.Team info)
{
- return new StudyGroupResponse(new StudyGroup(info.GroupName, info.usernames, _provider));
+ return new TeamResponse(new Aggregators.Team(info.TeamName, info.Usernames, _provider));
}
}
}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/WeatherForecastController.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/WeatherForecastController.cs
deleted file mode 100644
index 21430b7..0000000
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Controllers/WeatherForecastController.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-using Kysect.GithubActivityAnalyzer.WebDemo.Shared;
-
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.Extensions.Logging;
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Controllers
-{
- [ApiController]
- [Route("[controller]")]
- public class WeatherForecastController : ControllerBase
- {
- private static readonly string[] Summaries = new[]
- {
- "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
- };
-
- private readonly ILogger _logger;
-
- public WeatherForecastController(ILogger logger)
- {
- _logger = logger;
- }
-
- [HttpGet]
- public IEnumerable Get()
- {
- var rng = new Random();
- return Enumerable.Range(1, 5).Select(index => new WeatherForecast
- {
- Date = DateTime.Now.AddDays(index),
- TemperatureC = rng.Next(-20, 55),
- Summary = Summaries[rng.Next(Summaries.Length)]
- })
- .ToArray();
- }
- }
-}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Kysect.GithubActivityAnalyzer.WebDemo.Server.csproj b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Kysect.GithubActivityAnalyzer.WebDemo.Server.csproj
index 1ac373f..65b48ac 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Kysect.GithubActivityAnalyzer.WebDemo.Server.csproj
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Kysect.GithubActivityAnalyzer.WebDemo.Server.csproj
@@ -7,6 +7,7 @@
+
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Program.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Program.cs
index 47f98a9..f3280ea 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Program.cs
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Program.cs
@@ -1,13 +1,8 @@
-using Microsoft.AspNetCore.Hosting;
-using Microsoft.Extensions.Configuration;
+using Kysect.GithubActivityAnalyzer.Data.Contexts;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
-using Microsoft.Extensions.Logging;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using System.Threading.Tasks;
namespace Kysect.GithubActivityAnalyzer.WebDemo.Server
{
@@ -15,7 +10,15 @@ public class Program
{
public static void Main(string[] args)
{
- CreateHostBuilder(args).Build().Run();
+ var host = CreateHostBuilder(args).Build();
+
+ var scope = host.Services.CreateScope();
+ var activityContext = scope.ServiceProvider.GetService();
+ activityContext.Database.EnsureCreated();
+ var studentsGroupContext = scope.ServiceProvider.GetService();
+ studentsGroupContext.Database.EnsureCreated();
+
+ host.Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/ActivityService.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/ActivityService.cs
new file mode 100644
index 0000000..c597b40
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/ActivityService.cs
@@ -0,0 +1,28 @@
+using Kysect.GithubActivityAnalyzer.ApiAccessor;
+using Kysect.GithubActivityAnalyzer.ApiAccessor.ApiResponses;
+using Kysect.GithubActivityAnalyzer.Data.Repositories;
+using System.Threading.Tasks;
+
+namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Services
+{
+ public class ActivityService : IActivityService
+ {
+ private readonly GithubActivityProvider _githubActivityProvider;
+ private readonly UserCacheRepository _userСacheRepository;
+ public ActivityService(UserCacheRepository userСacheRepository, GithubActivityProvider githubActivityProvider)
+ {
+ this._userСacheRepository = userСacheRepository;
+ this._githubActivityProvider = githubActivityProvider;
+ }
+
+ public async Task GetActivityInfoFromGithub(string username)
+ {
+ return await _githubActivityProvider.GetActivityInfo(username);
+ }
+
+ public ActivityInfo GetActivityInfoFromDB(string username)
+ {
+ return _userСacheRepository.GetActivityFromUserCash(_userСacheRepository.FindByUsername(username));
+ }
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/IActivityService.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/IActivityService.cs
new file mode 100644
index 0000000..add3b58
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/IActivityService.cs
@@ -0,0 +1,14 @@
+using Kysect.GithubActivityAnalyzer.ApiAccessor.ApiResponses;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+
+namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Services
+{
+ public interface IActivityService
+ {
+ public Task GetActivityInfoFromGithub(string username);
+ public ActivityInfo GetActivityInfoFromDB(string username);
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/ITeamService.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/ITeamService.cs
new file mode 100644
index 0000000..0db47f8
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/ITeamService.cs
@@ -0,0 +1,20 @@
+using Kysect.GithubActivityAnalyzer.Data.Entities;
+using Kysect.GithubActivityAnalyzer.WebDemo.Shared;
+using System.Linq;
+
+namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Services
+{
+ public interface ITeamService
+ {
+ public void AddTeam(Team team);
+ public void DeleteTeam(string teamName);
+ public void UpdateMember(string username, string teamName);
+ public void DeleteMember(string username);
+
+ //TODO: разобраться с возвращаемым значением
+ public void GetAllTeams();
+
+ //TODO: разобраться с возвращаемым значением
+ public IQueryable GetTeam(string teamName);
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/TeamService.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/TeamService.cs
new file mode 100644
index 0000000..ed234ca
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Services/TeamService.cs
@@ -0,0 +1,45 @@
+using Kysect.GithubActivityAnalyzer.WebDemo.Shared;
+using Kysect.GithubActivityAnalyzer.Data.Repositories;
+using Kysect.GithubActivityAnalyzer.Data.Entities;
+using System.Linq;
+
+namespace Kysect.GithubActivityAnalyzer.WebDemo.Server.Services
+{
+ public class TeamService : ITeamService
+ {
+ private readonly TeamRepository _teamRepository;
+ public TeamService(TeamRepository teamRepository)
+ {
+ _teamRepository = teamRepository;
+ }
+ public void AddTeam(Team newTeam)
+ {
+ foreach (var username in newTeam.Usernames)
+ {
+ _teamRepository.Create(new Member() { Username = username, Team = newTeam.TeamName });
+ }
+ }
+ public void DeleteTeam(string teamName)
+ {
+ _teamRepository.DeleteByTeam(teamName);
+ }
+ public void UpdateMember(string username, string teamName)
+ {
+ _teamRepository.Update(new Member { Team = teamName, Username = username });
+ }
+ public void DeleteMember(string username)
+ {
+ _teamRepository.DeleteByUsername(username);
+ }
+
+ //TODO: Уточнить с ТЗ и реализовать
+ void ITeamService.GetAllTeams()
+ {
+ throw new System.NotImplementedException();
+ }
+ IQueryable ITeamService.GetTeam(string teamName)
+ {
+ throw new System.NotImplementedException();
+ }
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Startup.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Startup.cs
index bdf59c1..c5ce748 100644
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Server/Startup.cs
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Server/Startup.cs
@@ -6,6 +6,11 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
+using Kysect.GithubActivityAnalyzer.Data.Contexts;
+using Microsoft.EntityFrameworkCore;
+using Kysect.GithubActivityAnalyzer.WebDemo.Server.Services;
+using Kysect.GithubActivityAnalyzer.Data.Repositories;
+using Kysect.GithubActivityAnalyzer.ApiAccessor;
namespace Kysect.GithubActivityAnalyzer.WebDemo.Server
{
@@ -36,6 +41,23 @@ public void ConfigureServices(IServiceCollection services)
.AllowAnyHeader();
});
});
+ services.AddDbContext(options =>
+ {
+ options.UseSqlite($"Data Source= ActivityDB.db");
+ });
+ services.AddDbContext(options =>
+ {
+ options.UseSqlite($"Data Source= Teams.db");
+ });
+ services.AddScoped();
+ services.AddScoped();
+
+ services.AddScoped();
+ services.AddScoped();
+ services.AddScoped();
+
+ services.AddScoped();
+ services.AddScoped();
services.AddControllers();
}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Shared/GroupStatRequest.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Shared/GroupStatRequest.cs
deleted file mode 100644
index e4dc42d..0000000
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Shared/GroupStatRequest.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace Kysect.GithubActivityAnalyzer.WebDemo.Shared
-{
- public class GroupStatRequest
- {
- public string GroupName { get; set; }
- public List usernames { get; set; }
-
- public GroupStatRequest()
- { }
-
- public GroupStatRequest(string groupName)
- {
- GroupName = groupName;
- }
- }
-}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Shared/Team.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Shared/Team.cs
new file mode 100644
index 0000000..1803eab
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer.WebDemo/Shared/Team.cs
@@ -0,0 +1,17 @@
+using System.Collections.Generic;
+
+namespace Kysect.GithubActivityAnalyzer.WebDemo.Shared
+{
+ public class Team
+ {
+ public string TeamName { get; set; }
+ public List Usernames { get; set; }
+
+ public Team(){ }
+
+ public Team(string teamName)
+ {
+ TeamName = teamName;
+ }
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer.WebDemo/Shared/WeatherForecast.cs b/Kysect.GithubActivityAnalyzer.WebDemo/Shared/WeatherForecast.cs
deleted file mode 100644
index ea4b15d..0000000
--- a/Kysect.GithubActivityAnalyzer.WebDemo/Shared/WeatherForecast.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-
-namespace Kysect.GithubActivityAnalyzer.WebDemo.Shared
-{
- public class WeatherForecast
- {
- public DateTime Date { get; set; }
-
- public int TemperatureC { get; set; }
-
- public string Summary { get; set; }
-
- public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
- }
-}
diff --git a/Kysect.GithubActivityAnalyzer/Aggregators/Student.cs b/Kysect.GithubActivityAnalyzer/Aggregators/Member.cs
similarity index 89%
rename from Kysect.GithubActivityAnalyzer/Aggregators/Student.cs
rename to Kysect.GithubActivityAnalyzer/Aggregators/Member.cs
index 30570e0..d0b714c 100644
--- a/Kysect.GithubActivityAnalyzer/Aggregators/Student.cs
+++ b/Kysect.GithubActivityAnalyzer/Aggregators/Member.cs
@@ -4,18 +4,18 @@
namespace Kysect.GithubActivityAnalyzer.Aggregators
{
- public class Student
+ public class Member
{
public string Username { get; set; }
public ActivityInfo ActivityInfo { get; set; }
public int TotalContributions => ActivityInfo.Total;
- public Student()
+ public Member()
{
}
- public Student(string username, ActivityInfo activityInfo)
+ public Member(string username, ActivityInfo activityInfo)
{
Username = username;
ActivityInfo = activityInfo;
diff --git a/Kysect.GithubActivityAnalyzer/Aggregators/Models/MonthlyStatistics.cs b/Kysect.GithubActivityAnalyzer/Aggregators/Models/MonthlyStatistics.cs
index d0156b4..75057b9 100644
--- a/Kysect.GithubActivityAnalyzer/Aggregators/Models/MonthlyStatistics.cs
+++ b/Kysect.GithubActivityAnalyzer/Aggregators/Models/MonthlyStatistics.cs
@@ -7,23 +7,23 @@ namespace Kysect.GithubActivityAnalyzer.Aggregators.Models
public class MonthlyStatistics
{
public DateTime Month { get; set; }
- public List DetailedStat { get; set; }
- public StudentMonthlyActivity MinValueStudent { get; set; }
- public StudentMonthlyActivity MaxValueStudent { get; set; }
+ public List DetailedStat { get; set; }
+ public MemberMonthlyActivity MinValueMember { get; set; }
+ public MemberMonthlyActivity MaxValueMember { get; set; }
public double AverageValue { get; set; }
public int TotalContributions { get; set; }
- public MonthlyStatistics(DateTime date, List detailedStat)
+ public MonthlyStatistics(DateTime date, List detailedStat)
{
DetailedStat = detailedStat;
Month = date;
- MinValueStudent = DetailedStat
+ MinValueMember = DetailedStat
.OrderBy(a => a.MonthlyContributions)
.First();
- MaxValueStudent = DetailedStat
+ MaxValueMember = DetailedStat
.OrderBy(a => a.MonthlyContributions)
.Last();
@@ -37,17 +37,17 @@ public MonthlyStatistics()
}
}
- public class StudentMonthlyActivity
+ public class MemberMonthlyActivity
{
public string Username { get; set; }
public int MonthlyContributions { get; set; }
- public StudentMonthlyActivity()
+ public MemberMonthlyActivity()
{
}
- public StudentMonthlyActivity(string username, int monthlyContributions)
+ public MemberMonthlyActivity(string username, int monthlyContributions)
{
Username = username;
MonthlyContributions = monthlyContributions;
diff --git a/Kysect.GithubActivityAnalyzer/Aggregators/Models/StudyGroupResponse.cs b/Kysect.GithubActivityAnalyzer/Aggregators/Models/StudyGroupResponse.cs
deleted file mode 100644
index 208ff83..0000000
--- a/Kysect.GithubActivityAnalyzer/Aggregators/Models/StudyGroupResponse.cs
+++ /dev/null
@@ -1,37 +0,0 @@
-using System.Collections.Generic;
-using System.Linq;
-
-namespace Kysect.GithubActivityAnalyzer.Aggregators.Models
-{
- public class StudyGroupResponse
- {
- public string GroupName { get; set; }
- public List Students { get; set; }
- public List DetailedStatisticsList { get; set; }
-
- public int TotalContributions { get; set; }
-
- public StudyGroupResponse() { }
- public StudyGroupResponse(StudyGroup group)
- {
- GroupName = group.GroupName;
- TotalContributions = group.TotalContributions;
- Students = group.Students.Select(a => new ShortStudentInfo(a.Username, a.TotalContributions)).ToList();
- DetailedStatisticsList = group.Statistics;
- }
- }
-
- public class ShortStudentInfo
- {
- public string Username { get; set; }
-
- public int TotalContributions { get; set; }
-
- public ShortStudentInfo() { }
- public ShortStudentInfo(string name, int totalContributions)
- {
- Username = name;
- TotalContributions = totalContributions;
- }
- }
-}
diff --git a/Kysect.GithubActivityAnalyzer/Aggregators/Models/TeamResponse.cs b/Kysect.GithubActivityAnalyzer/Aggregators/Models/TeamResponse.cs
new file mode 100644
index 0000000..200217b
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer/Aggregators/Models/TeamResponse.cs
@@ -0,0 +1,37 @@
+using System.Collections.Generic;
+using System.Linq;
+
+namespace Kysect.GithubActivityAnalyzer.Aggregators.Models
+{
+ public class TeamResponse
+ {
+ public string TeamName { get; set; }
+ public List Members { get; set; }
+ public List DetailedStatisticsList { get; set; }
+
+ public int TotalContributions { get; set; }
+
+ public TeamResponse() { }
+ public TeamResponse(Team team)
+ {
+ TeamName = team.TeamName;
+ TotalContributions = team.TotalContributions;
+ Members = team.Members.Select(a => new ShortMemberInfo(a.Username, a.TotalContributions)).ToList();
+ DetailedStatisticsList = team.Statistics;
+ }
+ }
+
+ public class ShortMemberInfo
+ {
+ public string Username { get; set; }
+
+ public int TotalContributions { get; set; }
+
+ public ShortMemberInfo() { }
+ public ShortMemberInfo(string name, int totalContributions)
+ {
+ Username = name;
+ TotalContributions = totalContributions;
+ }
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer/Aggregators/StudyGroup.cs b/Kysect.GithubActivityAnalyzer/Aggregators/Team.cs
similarity index 62%
rename from Kysect.GithubActivityAnalyzer/Aggregators/StudyGroup.cs
rename to Kysect.GithubActivityAnalyzer/Aggregators/Team.cs
index 1d26c19..ef2848f 100644
--- a/Kysect.GithubActivityAnalyzer/Aggregators/StudyGroup.cs
+++ b/Kysect.GithubActivityAnalyzer/Aggregators/Team.cs
@@ -7,79 +7,79 @@
namespace Kysect.GithubActivityAnalyzer.Aggregators
{
- public class StudyGroup
+ public class Team
{
- public string GroupName { get; set; }
- public List Students { get; set; }
+ public string TeamName { get; set; }
+ public List Members { get; set; }
public List Statistics => GetDetailedStat();
public int TotalContributions => TotalActivity();
- public StudyGroup()
+ public Team()
{
}
- public StudyGroup(string groupName)
+ public Team(string teamName)
{
- GroupName = groupName;
- Students = new List();
+ TeamName = teamName;
+ Members = new List();
}
- public StudyGroup(string groupName, List students)
+ public Team(string teamName, List members)
{
- GroupName = groupName;
- Students = students;
+ TeamName = teamName;
+ Members = members;
}
- public StudyGroup(string groupName, List students, GithubActivityProvider provider)
+ public Team(string teamName, List members, GithubActivityProvider provider)
{
- GroupName = groupName;
- Students = new List();
- foreach ((string username, ActivityInfo activity) in provider.GetActivityInfo(students, true))
+ TeamName = teamName;
+ Members = new List();
+ foreach ((string username, ActivityInfo activity) in provider.GetActivityInfo(members, true))
{
- Students.Add(new Student(username, activity));
+ Members.Add(new Member(username, activity));
}
}
- public static List CreateFromUserList(List users, GithubActivityProvider provider)
+ public static List CreateFromUserList(List users, GithubActivityProvider provider)
{
return users
.ToLookup(user => user.Tag, user => user.Username)
- .Select(group => new StudyGroup(@group.Key, @group.ToList(), provider))
+ .Select(group => new Team(@group.Key, @group.ToList(), provider))
.ToList();
}
private int TotalActivity()
{
- return Students
+ return Members
.Select(k => k.TotalContributions)
.Sum();
}
- public void AddStudents(GithubActivityProvider provider, bool isParallel, params string[] usernames)
+ public void AddMembers(GithubActivityProvider provider, bool isParallel, params string[] usernames)
{
var listInfo = provider.GetActivityInfo(usernames, isParallel);
foreach (var item in listInfo)
{
- Students.Add(new Student(item.Username, item.Activity));
+ Members.Add(new Member(item.Username, item.Activity));
}
}
- public Student GetMinValueStudent(DateTime? from = null, DateTime? to = null)
+ public Member GetMinValueMember(DateTime? from = null, DateTime? to = null)
{
from ??= DateTime.MinValue;
to ??= DateTime.Now;
- return Students
+ return Members
.OrderBy(k => k.ActivityInfo.GetActivityForPeriod(from.GetValueOrDefault(), to.GetValueOrDefault()))
.Last();
}
- public Student GetMaxValueStudent(DateTime? from = null, DateTime? to = null)
+ public Member GetMaxValueMember(DateTime? from = null, DateTime? to = null)
{
from ??= DateTime.MinValue;
to ??= DateTime.Now;
- return Students
+ return Members
.OrderBy(k => k.ActivityInfo.GetActivityForPeriod(from.GetValueOrDefault(), to.GetValueOrDefault()))
.First();
@@ -89,7 +89,7 @@ public double GetAverageValue(DateTime? from = null, DateTime? to = null)
from ??= DateTime.MinValue;
to ??= DateTime.Now;
- return Students
+ return Members
.Select(k => k.ActivityInfo.GetActivityForPeriod(from.GetValueOrDefault(), to.GetValueOrDefault()))
.Average();
}
@@ -98,24 +98,24 @@ public Dictionary GetShortInfo()
{
Dictionary usersContributions = new Dictionary();
- foreach (var student in Students)
+ foreach (var member in Members)
{
- usersContributions.Add(student.Username, student.TotalContributions);
+ usersContributions.Add(member.Username, member.TotalContributions);
}
return usersContributions;
}
public int GetActivityForPeriod(DateTime from, DateTime to)
{
- return Students
- .Select(student => student.ActivityInfo.GetActivityForPeriod(@from, to))
+ return Members
+ .Select(member => member.ActivityInfo.GetActivityForPeriod(@from, to))
.Sum();
}
public double GetAverageMonthActivity()
{
- return Students
- .Select(student => Convert.ToInt32(student.ActivityInfo.PerMonthActivity()
+ return Members
+ .Select(member => Convert.ToInt32(member.ActivityInfo.PerMonthActivity()
.Average(c => c.Count)))
.ToList()
.Average();
@@ -123,7 +123,7 @@ public double GetAverageMonthActivity()
public double GetMovingAverage(DateTime from, DateTime to)
{
- return Students
+ return Members
.Select(s => s.GetMovingAverage(from, to))
.Average();
}
@@ -136,8 +136,8 @@ public List GetDetailedStat(DateTime? fromDate = null, DateTi
endTime = endTime ?? DateTime.Now;
for (DateTime to = from.AddMonths(1); from <= endTime || from.Month == endTime.Value.Month; to = from.AddMonths(1))
{
- var detailedStat = this.Students
- .Select(student => new StudentMonthlyActivity(student.Username, student.GetActivityForPeriod(from, to)))
+ var detailedStat = this.Members
+ .Select(member => new MemberMonthlyActivity(member.Username, member.GetActivityForPeriod(from, to)))
.ToList();
var monthStat = new MonthlyStatistics(from, detailedStat);
statistics.Add(monthStat);
diff --git a/Kysect.GithubActivityAnalyzer/Data/Contexts/ActivityContext.cs b/Kysect.GithubActivityAnalyzer/Data/Contexts/ActivityContext.cs
index 6faebe7..0c276bb 100644
--- a/Kysect.GithubActivityAnalyzer/Data/Contexts/ActivityContext.cs
+++ b/Kysect.GithubActivityAnalyzer/Data/Contexts/ActivityContext.cs
@@ -5,21 +5,13 @@ namespace Kysect.GithubActivityAnalyzer.Data.Contexts
{
public class ActivityContext : DbContext
{
+ public ActivityContext(DbContextOptions options) : base(options) { }
public DbSet UserСache { get; set; }
-
- protected override void OnConfiguring(DbContextOptionsBuilder options)
- => options.UseSqlite($"Data Source=..\\ActivityDB.db");
-
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity()
.HasKey(b => b.Username)
.HasName("PrimaryKey_Username");
}
-
- public ActivityContext()
- {
- Database.EnsureCreated();
- }
}
}
diff --git a/Kysect.GithubActivityAnalyzer/Data/Contexts/StudentsGroupContext.cs b/Kysect.GithubActivityAnalyzer/Data/Contexts/StudentsGroupContext.cs
deleted file mode 100644
index 2ec59e4..0000000
--- a/Kysect.GithubActivityAnalyzer/Data/Contexts/StudentsGroupContext.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Microsoft.EntityFrameworkCore;
-using Kysect.GithubActivityAnalyzer.Data.Entities;
-
-namespace Kysect.GithubActivityAnalyzer.Data.Contexts
-{
- public class StudentsGroupContext : DbContext
- {
- public DbSet StudentsGroup { get; set; }
-
- protected override void OnConfiguring(DbContextOptionsBuilder options)
- => options.UseSqlite($"Data Source=..\\StudentsGroup.db");
-
- protected override void OnModelCreating(ModelBuilder modelBuilder)
- {
- modelBuilder.Entity()
- .HasKey(b => b.Username)
- .HasName("PrimaryKey_Username");
- }
-
- public StudentsGroupContext()
- {
- Database.EnsureCreated();
- }
- }
-}
diff --git a/Kysect.GithubActivityAnalyzer/Data/Contexts/TeamContext.cs b/Kysect.GithubActivityAnalyzer/Data/Contexts/TeamContext.cs
new file mode 100644
index 0000000..cd8afbd
--- /dev/null
+++ b/Kysect.GithubActivityAnalyzer/Data/Contexts/TeamContext.cs
@@ -0,0 +1,18 @@
+using Microsoft.EntityFrameworkCore;
+using Kysect.GithubActivityAnalyzer.Data.Entities;
+
+namespace Kysect.GithubActivityAnalyzer.Data.Contexts
+{
+ public class TeamContext : DbContext
+ {
+ public DbSet Team { get; set; }
+ public TeamContext(DbContextOptions options) : base(options) { }
+
+ protected override void OnModelCreating(ModelBuilder modelBuilder)
+ {
+ modelBuilder.Entity()
+ .HasKey(b => b.Username)
+ .HasName("PrimaryKey_Username");
+ }
+ }
+}
diff --git a/Kysect.GithubActivityAnalyzer/Data/Entities/StudentsGroup.cs b/Kysect.GithubActivityAnalyzer/Data/Entities/Member.cs
similarity index 60%
rename from Kysect.GithubActivityAnalyzer/Data/Entities/StudentsGroup.cs
rename to Kysect.GithubActivityAnalyzer/Data/Entities/Member.cs
index 4295128..daebf28 100644
--- a/Kysect.GithubActivityAnalyzer/Data/Entities/StudentsGroup.cs
+++ b/Kysect.GithubActivityAnalyzer/Data/Entities/Member.cs
@@ -1,8 +1,8 @@
namespace Kysect.GithubActivityAnalyzer.Data.Entities
{
- public class StudentsGroup
+ public class Member
{
public string Username { get; set; }
- public string StudyGroup { get; set; }
+ public string Team { get; set; }
}
}
diff --git a/Kysect.GithubActivityAnalyzer/Data/Repositories/StudentsGroupRepository.cs b/Kysect.GithubActivityAnalyzer/Data/Repositories/TeamRepository.cs
similarity index 50%
rename from Kysect.GithubActivityAnalyzer/Data/Repositories/StudentsGroupRepository.cs
rename to Kysect.GithubActivityAnalyzer/Data/Repositories/TeamRepository.cs
index 436afc4..48ea746 100644
--- a/Kysect.GithubActivityAnalyzer/Data/Repositories/StudentsGroupRepository.cs
+++ b/Kysect.GithubActivityAnalyzer/Data/Repositories/TeamRepository.cs
@@ -1,36 +1,37 @@
using Microsoft.EntityFrameworkCore;
using System.Linq;
using Kysect.GithubActivityAnalyzer.Data.Entities;
+using Kysect.GithubActivityAnalyzer.Data.Contexts;
namespace Kysect.GithubActivityAnalyzer.Data.Repositories
{
- public class StudentsGroupRepository : IRepository
+ public class TeamRepository : IRepository
{
- readonly DbContext _context;
- readonly DbSet _dbSet;
+ readonly TeamContext _context;
+ readonly DbSet _dbSet;
- public StudentsGroupRepository(DbContext context, DbSet set)
+ public TeamRepository(TeamContext context)
{
_context = context;
- _dbSet = set;
+ _dbSet = context.Team;
}
- public StudentsGroup Create(StudentsGroup item)
+ public Member Create(Member item)
{
_dbSet.Add(item);
_context.SaveChanges();
return item;
}
- public IQueryable Get()
+ public IQueryable Get()
{
return _dbSet;
}
- public void Update(StudentsGroup item)
+ public void Update(Member item)
{
DeleteByUsername(item.Username);
Create(item);
}
- public void Delete(StudentsGroup item)
+ public void Delete(Member item)
{
_dbSet.Remove(item);
_context.SaveChanges();
@@ -39,17 +40,24 @@ public void DeleteByUsername(string username)
{
Delete(FindByUsername(username));
}
- public IQueryable GetAll()
+ public IQueryable GetAll()
{
return _dbSet;
}
- public StudentsGroup FindByUsername(string username)
+ public Member FindByUsername(string username)
{
return _dbSet.Find(username);
}
- public IQueryable GetAllByGroup(string studyGroup)
+ public IQueryable GetAllByTeam(string team)
{
- return _dbSet.Where(p => p.StudyGroup == studyGroup);
+ return _dbSet.Where(p => p.Team == team);
+ }
+ public void DeleteByTeam(string team)
+ {
+ foreach( var member in GetAllByTeam(team))
+ {
+ Delete(member);
+ }
}
}
}
diff --git "a/Kysect.GithubActivityAnalyzer/Data/Repositories/User\320\241acheRepository.cs" b/Kysect.GithubActivityAnalyzer/Data/Repositories/UserCacheRepository.cs
similarity index 64%
rename from "Kysect.GithubActivityAnalyzer/Data/Repositories/User\320\241acheRepository.cs"
rename to Kysect.GithubActivityAnalyzer/Data/Repositories/UserCacheRepository.cs
index 1dfbc1b..8faf5eb 100644
--- "a/Kysect.GithubActivityAnalyzer/Data/Repositories/User\320\241acheRepository.cs"
+++ b/Kysect.GithubActivityAnalyzer/Data/Repositories/UserCacheRepository.cs
@@ -1,20 +1,22 @@
-using System.Linq;
+using System.Collections.Generic;
+using System.Linq;
using System.Text.Json;
using Kysect.GithubActivityAnalyzer.ApiAccessor.ApiResponses;
+using Kysect.GithubActivityAnalyzer.Data.Contexts;
using Kysect.GithubActivityAnalyzer.Data.Entities;
using Microsoft.EntityFrameworkCore;
namespace Kysect.GithubActivityAnalyzer.Data.Repositories
{
- public class UserСacheRepository : IRepository
+ public class UserCacheRepository : IRepository
{
- readonly DbContext _context;
+ readonly ActivityContext _context;
readonly DbSet _dbSet;
- public UserСacheRepository(DbContext context, DbSet set)
+ public UserCacheRepository(ActivityContext context)
{
_context = context;
- _dbSet = set;
+ _dbSet = context.UserСache;
}
public IQueryable GetAll()
@@ -63,6 +65,20 @@ public ActivityInfo GetActivityFromUserCash(UserСache userCash)
var activity = JsonSerializer.Deserialize(userCash.ActivityInfo, new JsonSerializerOptions { PropertyNameCaseInsensitive = true });
return activity;
}
+ public List<(string Username, ActivityInfo Activity)> GetActivityFromUserCash(IEnumerable usernames, bool isParallel)
+ {
+ if (!isParallel)
+ {
+ return usernames
+ .Select(username => (username, GetActivityFromUserCash(FindByUsername(username))))
+ .ToList();
+ }
+ List<(string, ActivityInfo)> result = usernames
+ .AsParallel()
+ .Select(username => (username, GetActivityFromUserCash(FindByUsername(username))))
+ .ToList();
+ return result;
+ }
}
}
diff --git a/Kysect.GithubActivityAnalyzer/DataExport/ExcelExportManager.cs b/Kysect.GithubActivityAnalyzer/DataExport/ExcelExportManager.cs
index 20d29c5..d2bc1c4 100644
--- a/Kysect.GithubActivityAnalyzer/DataExport/ExcelExportManager.cs
+++ b/Kysect.GithubActivityAnalyzer/DataExport/ExcelExportManager.cs
@@ -6,15 +6,15 @@ namespace Kysect.GithubActivityAnalyzer.DataExport
{
public class ExcelExportManager
{
- public List Info { get; set; }
+ public List Info { get; set; }
private IXLWorkbook Workbook { get; }
- public ExcelExportManager(List info)
+ public ExcelExportManager(List info)
{
Info = info;
Workbook = new XLWorkbook();
}
- public ExcelExportManager(List info, IXLWorkbook workbook)
+ public ExcelExportManager(List info, IXLWorkbook workbook)
{
Info = info;
Workbook = workbook;
@@ -29,7 +29,7 @@ public IXLWorkbook ExportShortInfo()
{
foreach (var groupInfo in Info)
{
- IXLWorksheet worksheet = Workbook.Worksheets.Add($"{groupInfo.GroupName}");
+ IXLWorksheet worksheet = Workbook.Worksheets.Add($"{groupInfo.TeamName}");
worksheet.Cell(2, 1).Value = "Среднее количество коммитов за месяц:";
worksheet.Cell(3, 1).Value = "Всего коммитов за месяц:";
worksheet.Cell(4, 1).Value = "Котик месяца:";
@@ -42,9 +42,9 @@ public IXLWorkbook ExportShortInfo()
worksheet.Cell(2, column).Value = groupInfo.Statistics[column - 2].AverageValue;
worksheet.Cell(3, column).Value = groupInfo.Statistics[column - 2].TotalContributions;
worksheet.Cell(4, column).Value =
- groupInfo.Statistics[column-2].MaxValueStudent.Username + ":" + groupInfo.Statistics[column - 2].MaxValueStudent.MonthlyContributions;
+ groupInfo.Statistics[column-2].MaxValueMember.Username + ":" + groupInfo.Statistics[column - 2].MaxValueMember.MonthlyContributions;
worksheet.Cell(5, column).Value =
- groupInfo.Statistics[column - 2].MinValueStudent.Username + ":" + groupInfo.Statistics[column - 2].MinValueStudent.MonthlyContributions;
+ groupInfo.Statistics[column - 2].MinValueMember.Username + ":" + groupInfo.Statistics[column - 2].MinValueMember.MonthlyContributions;
}
worksheet.Columns().AdjustToContents();
worksheet.Rows().AdjustToContents();
@@ -56,11 +56,11 @@ public IXLWorkbook ExportDetailedInfo()
{
foreach (var info in Info)
{
- IXLWorksheet worksheetDetailed = Workbook.Worksheets.Add($"{info.GroupName}-DetailedStat");
+ IXLWorksheet worksheetDetailed = Workbook.Worksheets.Add($"{info.TeamName}-DetailedStat");
- for (int row = 2; row < info.Students.Count + 2; row++)
+ for (int row = 2; row < info.Members.Count + 2; row++)
{
- worksheetDetailed.Cell(row, 1).Value = info.Students[row - 2].Username;
+ worksheetDetailed.Cell(row, 1).Value = info.Members[row - 2].Username;
}
int column = 2;
diff --git a/Kysect.GithubActivityAnalyzer/Services/ExcelExportManager.cs b/Kysect.GithubActivityAnalyzer/Services/ExcelExportManager.cs
index dc96936..9da1198 100644
--- a/Kysect.GithubActivityAnalyzer/Services/ExcelExportManager.cs
+++ b/Kysect.GithubActivityAnalyzer/Services/ExcelExportManager.cs
@@ -7,15 +7,15 @@ namespace Kysect.GithubActivityAnalyzer.Services
{
public class ExcelExportManager
{
- public List Info { get; set; }
+ public List Info { get; set; }
private IXLWorkbook Workbook { get; }
- public ExcelExportManager(List info)
+ public ExcelExportManager(List info)
{
Info = info;
Workbook = new XLWorkbook();
}
- public ExcelExportManager(List info, IXLWorkbook workbook)
+ public ExcelExportManager(List info, IXLWorkbook workbook)
{
Info = info;
Workbook = workbook;
@@ -28,24 +28,24 @@ public void SaveExcel(string path)
public IXLWorkbook ExportShortInfo()
{
- foreach (var groupInfo in Info)
+ foreach (var teamInfo in Info)
{
- IXLWorksheet worksheet = Workbook.Worksheets.Add($"{groupInfo.GroupName}");
+ IXLWorksheet worksheet = Workbook.Worksheets.Add($"{teamInfo.TeamName}");
worksheet.Cell(2, 1).Value = "Среднее количество коммитов за месяц:";
worksheet.Cell(3, 1).Value = "Всего коммитов за месяц:";
worksheet.Cell(4, 1).Value = "Котик месяца:";
worksheet.Cell(5, 1).Value = "Кандидат на ремень по жопе:";
worksheet.Row(1).SetDataType(XLDataType.Text);
- for(int column = 2; column