Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 2 issues #411

Merged
merged 1 commit into from
Oct 10, 2023
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
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
Loading