Skip to content

Commit

Permalink
Merge pull request #411 from code4romania/bugfix/fix-2-issues
Browse files Browse the repository at this point in the history
fix 2 issues
  • Loading branch information
idormenco authored Oct 10, 2023
2 parents 679d0da + 76b6277 commit 8a271ba
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 21 deletions.
18 changes: 9 additions & 9 deletions src/api/VoteMonitor.Api.Form/Models/FormDetailsModel.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace VoteMonitor.Api.Form.Models;

public class FormDetailsModel
{
[JsonProperty(PropertyName = "id")]
[JsonPropertyName("id")]
public int Id { get; set; }

[JsonProperty(PropertyName = "code")]
[JsonPropertyName("code")]
public string Code { get; set; }

[JsonProperty(PropertyName = "description")]
[JsonPropertyName("description")]
public string Description { get; set; }

[JsonProperty(PropertyName = "ver")]
[JsonPropertyName("ver")]
public int CurrentVersion { get; set; }

[JsonProperty(PropertyName = "diaspora")]
[JsonPropertyName("diaspora")]
public bool Diaspora { get; set; }

[JsonProperty(PropertyName = "order")]
[JsonPropertyName("order")]
public int Order { get; set; }

[JsonProperty(PropertyName = "draft")]
[JsonPropertyName("draft")]
public bool Draft { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,44 @@ public ActiveObserversQueryHandler(VoteMonitorContext context)
public Task<List<ObserverModel>> Handle(ActiveObserversQuery request, CancellationToken cancellationToken)
{
var results = _context.PollingStationInfos
.AsNoTracking()
.Include(pi => pi.PollingStation)
.Include(pi => pi.PollingStation.Municipality)
.ThenInclude(c => c.County)
.Include(pi => pi.Observer)
.Where(i => request.CountyCodes.Contains(i.PollingStation.Municipality.County.Code));
.ThenInclude(o=>o.Ngo)
.Select(x => new
{
ObserverId = x.Observer.Id,
ObserverName = x.Observer.Name,
ObserverPhone = x.Observer.Phone,
NgoName = x.Observer.Ngo.Name,
NgoId = x.Observer.Ngo.Id,
NumberOfNotes = x.Observer.Notes.Count,
NumberOfPollingStations = x.Observer.PollingStationInfos.Count,
DeviceRegisterDate = x.Observer.DeviceRegisterDate,
CountyCode = x.PollingStation.Municipality.County.Code,
LastAnswer = x.Observer.Answers.Any() ? x.Observer.Answers.Max(a => a.LastModified) : (DateTime?)null,
LastNote = x.Observer.Notes.Any() ? x.Observer.Notes.Max(a => a.LastModified) : (DateTime?)null,
})
.Where(x => request.CountyCodes.Contains(x.CountyCode));

if (request.NgoId > 0)
{
results = results.Where(i => i.Observer.IdNgo == request.NgoId);
results = results.Where(x => x.NgoId == request.NgoId);
}

var observers = results
.Select(i => i.Observer)
.AsEnumerable()
.Select(o => new ObserverModel
.Select(x => new ObserverModel
{
Id = o.Id,
Name = o.Name,
Phone = o.Phone,
Ngo = o.Ngo.Name,
NumberOfNotes = o.Notes.Count,
NumberOfPollingStations = o.PollingStationInfos.Count,
DeviceRegisterDate = o.DeviceRegisterDate
Id = x.ObserverId,
Name = x.ObserverName,
Phone = x.ObserverPhone,
Ngo = x.NgoName,
NumberOfNotes = x.NumberOfNotes,
NumberOfPollingStations = x.NumberOfPollingStations,
DeviceRegisterDate = x.DeviceRegisterDate,
LastSeen = (x.LastAnswer ?? DateTime.MinValue) > (x.LastNote ?? DateTime.MinValue) ? x.LastAnswer : x.LastNote,
})
.ToList();

Expand Down

0 comments on commit 8a271ba

Please sign in to comment.