Skip to content

Commit

Permalink
246 code cleanup statistics (#367)
Browse files Browse the repository at this point in the history
* rename classes and fields to english, reorganize files

* revert raw sql change
  • Loading branch information
decembrya authored Jan 30, 2021
1 parent c57f014 commit 5eb95de
Show file tree
Hide file tree
Showing 21 changed files with 208 additions and 198 deletions.
133 changes: 60 additions & 73 deletions src/api/VoteMonitor.Api.Statistics/Controllers/StatisticsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Threading.Tasks;
using VoteMonitor.Api.Core;
using VoteMonitor.Api.Core.Options;
using VoteMonitor.Api.Statistics.Handlers;
using VoteMonitor.Api.Statistics.Models;
using VoteMonitor.Api.Statistics.Queries;

Expand All @@ -29,7 +28,7 @@ public StatisticsController(IMediator mediator, IConfiguration configuration, IO
}

private int NgoId => this.GetIdOngOrDefault(_configuration.GetValue<int>("DefaultIdOng"));
private bool Organizer => this.GetOrganizatorOrDefault(_configuration.GetValue<bool>("DefaultOrganizator"));
private bool IsOrganizer => this.GetOrganizatorOrDefault(_configuration.GetValue<bool>("DefaultOrganizator"));

/// <summary>
/// Returns top counties by observer number
Expand All @@ -39,12 +38,12 @@ public StatisticsController(IMediator mediator, IConfiguration configuration, IO
[HttpGet]
[Route("observerNumber")]
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> NumarObservatori(PagingModel model)
public async Task<ApiListResponse<SimpleStatisticsModel>> ObserverNumber(PagingModel model)
{
return await _mediator.Send(new StatisticsObserversNumberQuery
return await _mediator.Send(new StatisticsObserverNumberQuery
{
IdONG = NgoId,
Organizator = Organizer,
NgoId = NgoId,
IsOrganizer = IsOrganizer,
PageSize = model.PageSize,
Page = model.Page,
CacheHours = _cacheOptions.Hours,
Expand All @@ -57,26 +56,26 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> NumarObservatori(Pagin
/// Returns top counties or polling stations by number of irregularities
/// </summary>
/// <param name="model"> Pagination details (default Page=1, PageSize=20)
/// Grouping (0 - County | 1 - PollingStation)
/// FormCode (formeCode for which you want to retrieve statistics, use empty string "" for all forms)
/// GroupingType (0 - County | 1 - PollingStation)
/// FormCode (formCode for which you want to retrieve statistics, use empty string "" for all forms)
/// </param>
/// <returns></returns>
[HttpGet]
[Route("irregularities")]
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> Irregularities(SimpleStatisticsFilter model)
public async Task<ApiListResponse<SimpleStatisticsModel>> Irregularities(FilterStatisticsModel model)
{
if (model.GroupingType == StatisticsGroupingTypes.Sectie)
if (model.GroupingType == StatisticsGroupingTypes.PollingStation)
{
model.PageSize = PagingDefaultsConstants.DEFAULT_PAGE_SIZE;
}

return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = model.GroupingType,
Formular = model.FormCode,
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = model.GroupingType,
FormCode = model.FormCode,
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -95,12 +94,12 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> Irregularities(SimpleS
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> CountiesIrregularities(PagingModel model)
{
return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = StatisticsGroupingTypes.Judet,
Formular = null,
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = StatisticsGroupingTypes.County,
FormCode = null,
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -119,16 +118,12 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> CountiesIrregularities
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationIrregularities(PagingModel model)
{
var idONG = this.GetIdOngOrDefault(_configuration.GetValue<int>("DefaultIdOng"));
var organizator = this.GetOrganizatorOrDefault(_configuration.GetValue<bool>("DefaultOrganizator"));
model.PageSize = PagingDefaultsConstants.DEFAULT_PAGE_SIZE;

return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = StatisticsGroupingTypes.Sectie,
Formular = null,
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = StatisticsGroupingTypes.PollingStation,
FormCode = null,
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -147,12 +142,12 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationIrregula
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> CountiesOpeningIrregularities(PagingModel model)
{
return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = StatisticsGroupingTypes.Judet,
Formular = "A",
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = StatisticsGroupingTypes.County,
FormCode = "A",
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -169,18 +164,14 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> CountiesOpeningIrregul
[HttpGet]
[Route("pollingStationOpeningIrregularities")]
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationOpeningIrregularities(PagingModel model)
public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationsOpeningIrregularities(PagingModel model)
{
var idONG = this.GetIdOngOrDefault(_configuration.GetValue<int>("DefaultIdOng"));
var organizator = this.GetOrganizatorOrDefault(_configuration.GetValue<bool>("DefaultOrganizator"));
model.PageSize = PagingDefaultsConstants.DEFAULT_PAGE_SIZE;

return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = StatisticsGroupingTypes.Sectie,
Formular = "A",
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = StatisticsGroupingTypes.PollingStation,
FormCode = "A",
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -199,12 +190,12 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationOpeningI
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> CountiesByCountingIrregularities(PagingModel model)
{
return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = StatisticsGroupingTypes.Judet,
Formular = "C",
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = StatisticsGroupingTypes.County,
FormCode = "C",
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -223,16 +214,12 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> CountiesByCountingIrre
[Authorize("NgoAdmin")]
public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationsByCountingIrregularities(PagingModel model)
{
var idONG = this.GetIdOngOrDefault(_configuration.GetValue<int>("DefaultIdOng"));
var organizator = this.GetOrganizatorOrDefault(_configuration.GetValue<bool>("DefaultOrganizator"));
model.PageSize = PagingDefaultsConstants.DEFAULT_PAGE_SIZE;

return await _mediator.Send(new StatisticiTopSesizariQuery
return await _mediator.Send(new StatisticsTopIrregularitiesQuery
{
IdONG = NgoId,
Organizator = Organizer,
Grupare = StatisticsGroupingTypes.Sectie,
Formular = "C",
NgoId = NgoId,
IsOrganizer = IsOrganizer,
GroupType = StatisticsGroupingTypes.PollingStation,
FormCode = "C",
Page = model.Page,
PageSize = model.PageSize,
CacheHours = _cacheOptions.Hours,
Expand All @@ -248,15 +235,15 @@ public async Task<ApiListResponse<SimpleStatisticsModel>> PollingStationsByCount
/// <param name="model">Id - the questionId to retrieve statistics for</param>
/// <returns></returns>
[HttpGet]
[Route("RaspunsuriNumarareOptiuni")]
[Route("countAnswersByQuestion")]
[Authorize("NgoAdmin")]
public async Task<StatisticsOptionsModel> CountAnswersForQuestion(OptionsFilterModel model)
{
return await _mediator.Send(new StatisticsOptionsQuery
{
QuestionId = model.QuestionId,
IdONG = NgoId,
Organizator = Organizer,
NgoId = NgoId,
IsOrganizer = IsOrganizer,
CacheHours = _cacheOptions.Hours,
CacheMinutes = _cacheOptions.Minutes,
CacheSeconds = _cacheOptions.Seconds
Expand All @@ -268,42 +255,42 @@ public async Task<StatisticsOptionsModel> CountAnswersForQuestion(OptionsFilterM
[Route("mini/answers")]
public async Task<SimpleStatisticsModel> Answers()
{
return await _mediator.Send(new AnswersRequest());
return await _mediator.Send(new AnswersQuery());
}
[HttpGet]
[AllowAnonymous]
[Route("mini/stations")]
public async Task<SimpleStatisticsModel> StationsVisited()
{
return await _mediator.Send(new StationsVisitedRequest());
return await _mediator.Send(new StationsVisitedQuery());
}
[HttpGet]
[AllowAnonymous]
[Route("mini/counties")]
public async Task<SimpleStatisticsModel> Counties()
{
return await _mediator.Send(new CountiesVisitedRequest());
return await _mediator.Send(new CountiesVisitedQuery());
}
[HttpGet]
[AllowAnonymous]
[Route("mini/notes")]
public async Task<SimpleStatisticsModel> Notes()
{
return await _mediator.Send(new NotesUploadedRequest());
return await _mediator.Send(new NotesUploadedQuery());
}
[HttpGet]
[AllowAnonymous]
[Route("mini/loggedinobservers")]
public async Task<SimpleStatisticsModel> LoggedInObservers()
{
return await _mediator.Send(new LoggedInObserversRequest());
return await _mediator.Send(new LoggedInObserversQuery());
}
[HttpGet]
[AllowAnonymous]
[Route("mini/flaggedanswers")]
public async Task<SimpleStatisticsModel> FlaggedAnswers()
{
return await _mediator.Send(new FlaggedAnswersRequest());
return await _mediator.Send(new FlaggedAnswersQuery());
}
[HttpGet]
[AllowAnonymous]
Expand All @@ -312,12 +299,12 @@ public async Task<List<SimpleStatisticsModel>> All()
{
var list = new List<SimpleStatisticsModel>
{
await _mediator.Send(new AnswersRequest()),
await _mediator.Send(new StationsVisitedRequest()),
await _mediator.Send(new CountiesVisitedRequest()),
await _mediator.Send(new NotesUploadedRequest()),
await _mediator.Send(new LoggedInObserversRequest()),
await _mediator.Send(new FlaggedAnswersRequest())
await _mediator.Send(new AnswersQuery()),
await _mediator.Send(new StationsVisitedQuery()),
await _mediator.Send(new CountiesVisitedQuery()),
await _mediator.Send(new NotesUploadedQuery()),
await _mediator.Send(new LoggedInObserversQuery()),
await _mediator.Send(new FlaggedAnswersQuery())
};

return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
using System.Threading;
using System.Threading.Tasks;
using VoteMonitor.Api.Statistics.Models;
using VoteMonitor.Api.Statistics.Queries;
using VoteMonitor.Entities;

namespace VoteMonitor.Api.Statistics.Handlers
{
public class MiniStatisticsQueryHandler :
IRequestHandler<AnswersRequest, SimpleStatisticsModel>,
IRequestHandler<StationsVisitedRequest, SimpleStatisticsModel>,
IRequestHandler<FlaggedAnswersRequest, SimpleStatisticsModel>,
IRequestHandler<CountiesVisitedRequest, SimpleStatisticsModel>,
IRequestHandler<NotesUploadedRequest, SimpleStatisticsModel>,
IRequestHandler<LoggedInObserversRequest, SimpleStatisticsModel>
IRequestHandler<AnswersQuery, SimpleStatisticsModel>,
IRequestHandler<StationsVisitedQuery, SimpleStatisticsModel>,
IRequestHandler<FlaggedAnswersQuery, SimpleStatisticsModel>,
IRequestHandler<CountiesVisitedQuery, SimpleStatisticsModel>,
IRequestHandler<NotesUploadedQuery, SimpleStatisticsModel>,
IRequestHandler<LoggedInObserversQuery, SimpleStatisticsModel>
{
private readonly VoteMonitorContext _context;

Expand All @@ -23,7 +24,7 @@ public MiniStatisticsQueryHandler(VoteMonitorContext context)
_context = context;
}

public async Task<SimpleStatisticsModel> Handle(AnswersRequest message, CancellationToken token)
public async Task<SimpleStatisticsModel> Handle(AnswersQuery message, CancellationToken token)
{
var number = await _context.Answers
.Include(a => a.Observer)
Expand All @@ -38,7 +39,7 @@ public async Task<SimpleStatisticsModel> Handle(AnswersRequest message, Cancella
Value = number.ToString()
};
}
public async Task<SimpleStatisticsModel> Handle(StationsVisitedRequest message, CancellationToken token)
public async Task<SimpleStatisticsModel> Handle(StationsVisitedQuery message, CancellationToken token)
{
var number = await _context.Answers
.Include(a => a.Observer)
Expand All @@ -55,7 +56,7 @@ public async Task<SimpleStatisticsModel> Handle(StationsVisitedRequest message,
Value = number.ToString()
};
}
public async Task<SimpleStatisticsModel> Handle(CountiesVisitedRequest message, CancellationToken token)
public async Task<SimpleStatisticsModel> Handle(CountiesVisitedQuery message, CancellationToken token)
{
var number = await _context.Answers
.Include(a => a.Observer)
Expand All @@ -72,7 +73,7 @@ public async Task<SimpleStatisticsModel> Handle(CountiesVisitedRequest message,
Value = number.ToString()
};
}
public async Task<SimpleStatisticsModel> Handle(NotesUploadedRequest message, CancellationToken token)
public async Task<SimpleStatisticsModel> Handle(NotesUploadedQuery message, CancellationToken token)
{
var number = await _context.Notes
.Include(n => n.Observer)
Expand All @@ -87,7 +88,7 @@ public async Task<SimpleStatisticsModel> Handle(NotesUploadedRequest message, Ca
Value = number.ToString()
};
}
public async Task<SimpleStatisticsModel> Handle(LoggedInObserversRequest message, CancellationToken token)
public async Task<SimpleStatisticsModel> Handle(LoggedInObserversQuery message, CancellationToken token)
{
var number = await _context.PollingStationInfos
.Include(a => a.Observer)
Expand All @@ -104,7 +105,7 @@ public async Task<SimpleStatisticsModel> Handle(LoggedInObserversRequest message
Value = number.ToString()
};
}
public async Task<SimpleStatisticsModel> Handle(FlaggedAnswersRequest message, CancellationToken token)
public async Task<SimpleStatisticsModel> Handle(FlaggedAnswersQuery message, CancellationToken token)
{
var number = await _context.Answers
.Include(a => a.Observer)
Expand Down

This file was deleted.

Loading

0 comments on commit 5eb95de

Please sign in to comment.