Skip to content
Open
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
11 changes: 7 additions & 4 deletions api/src/Feature.PollingStations/Create/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public override async Task<Results<Ok<Response>, NotFound<ProblemDetails>>> Exec
}

var userId = userProvider.GetUserId()!.Value;

var pollingStations = req.PollingStations.Select(ps => PollingStationAggregate.Create(electionRound,
var pollingStations = req.PollingStations.Select(ps => PollingStationAggregate.Create(ps.Id, electionRound,
ps.Level1,
ps.Level2,
ps.Level3,
Expand All @@ -41,12 +40,14 @@ public override async Task<Results<Ok<Response>, NotFound<ProblemDetails>>> Exec
ps.Address,
ps.DisplayOrder,
ps.Tags.ToTagsObject(),
ps.Latitude,
ps.Longitude,
timeProvider.UtcNow,
userId))
.ToArray();

await context.BulkInsertAsync(pollingStations, cancellationToken: ct);

await context.BulkInsertOrUpdateAsync(pollingStations, cancellationToken: ct);
electionRound.UpdatePollingStationsVersion();

await electionRoundRepository.UpdateAsync(electionRound, cancellationToken: ct);
Expand All @@ -68,4 +69,6 @@ public override async Task<Results<Ok<Response>, NotFound<ProblemDetails>>> Exec
}).ToArray()
});
}


}
3 changes: 3 additions & 0 deletions api/src/Feature.PollingStations/Create/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Request

public class PollingStationRequest
{
public Guid? Id { get; set; }
public string Level1 { get; set; }
public string Level2 { get; set; }
public string Level3 { get; set; }
Expand All @@ -17,5 +18,7 @@ public class PollingStationRequest
public int DisplayOrder { get; set; }
public string Address { get; set; }
public Dictionary<string, string> Tags { get; set; }
public double? Latitude { get; set; }
public double? Longitude { get; set; }
}
}
5 changes: 3 additions & 2 deletions api/src/Feature.PollingStations/FetchAll/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public override async Task<Results<Ok<Response>, NotFound>> ExecuteAsync(Request
{
var pollingStations = await context.PollingStations
.Where(x => x.ElectionRoundId == request.ElectionRoundId)
.OrderBy(x => x.DisplayOrder)
.Select(x => new PollingStationModel
{
Id = x.Id,
Expand Down Expand Up @@ -134,7 +133,9 @@ private static List<LocationNode> GetLocationNodes(List<PollingStationModel> pol
Name = ps.Address,
ParentId = parentNode!.Id,
Number = ps.Number,
PollingStationId = ps.Id
PollingStationId = ps.Id,
Latitude = ps.Latitude,
Longitude = ps.Longitude
});
}

Expand Down
6 changes: 6 additions & 0 deletions api/src/Feature.PollingStations/FetchAll/LocationNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,10 @@ public class LocationNode

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public int? DisplayOrder { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? Latitude { get; set; }

[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public double? Longitude { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public override void Configure()
public override async Task HandleAsync(CancellationToken ct)
{
const string template = """
"Level1", "Level2", "Level3", "Level4", "Level5", "Number", "Address", "DisplayOrder"
"Level1", "Level2", "Level3", "Level4", "Level5", "Number", "Address", "DisplayOrder","Latitude", "Longitude", "Tag1", "Tag2", "Tag3"
""";

var stream = GenerateStreamFromString(template);
Expand Down
2 changes: 2 additions & 0 deletions api/src/Feature.PollingStations/Import/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ public override async Task<Results<Ok<Response>, NotFound<ProblemDetails>, Probl
x.Address,
x.DisplayOrder,
x.Tags.ToTagsObject(),
x.Latitude,
x.Longitude,
timeProvider.UtcNow,
userProvider.GetUserId()!.Value))
.ToList();
Expand Down
2 changes: 2 additions & 0 deletions api/src/Feature.PollingStations/List/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public override async Task<Results<Ok<PagedResponse<PollingStationModel>>, Probl
Number = x.Number,
Address = x.Address,
DisplayOrder = x.DisplayOrder,
Latitude = x.Latitude,
Longitude = x.Longitude,
Tags = x.Tags.ToDictionary()
}).ToList();

Expand Down
2 changes: 2 additions & 0 deletions api/src/Feature.PollingStations/PollingStationModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public class PollingStationModel
public string Address { get; set; }
public int DisplayOrder { get; set; }
public Dictionary<string, string> Tags { get; set; }
public double? Latitude { get; set; }
public double? Longitude { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public class PollingStationImportModel
public string Address { get; set; }

public List<TagImportModel> Tags { get; set; }
}
public double? Latitude { get; set; }
public double? Longitude { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ public PollingStationImportModelMapper()

Map(m => m.Address).Name("Address"); // 6
Map(m => m.DisplayOrder).Name("DisplayOrder"); //7
Map(m => m.Tags).Convert(ReadTags); // 8 -> end
Map(m => m.Latitude).Name("Latitude"); //8
Map(m => m.Longitude).Name("Longitude"); //9
Map(m => m.Tags).Convert(ReadTags); // 10 -> end
}

private static List<TagImportModel> ReadTags(ConvertFromStringArgs row)
{
var tags = new List<TagImportModel>();

for (var i = 8; i < row.Row?.HeaderRecord?.Length; i++)
for (var i = 10; i < row.Row?.HeaderRecord?.Length; i++)
{
var name = row.Row.HeaderRecord[i];
var value = row.Row[i];
Expand Down
2 changes: 1 addition & 1 deletion api/src/Feature.PollingStations/Update/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override async Task<Results<NoContent, NotFound<ProblemDetails>, Conflict
return TypedResults.NotFound(new ProblemDetails(ValidationFailures));
}

pollingStation.UpdateDetails(req.Level1, req.Level2, req.Level3, req.Level4, req.Level5, req.Number, req.Address, req.DisplayOrder, req.Tags.ToTagsObject());
pollingStation.UpdateDetails(req.Level1, req.Level2, req.Level3, req.Level4, req.Level5, req.Number, req.Address, req.DisplayOrder, req.Tags.ToTagsObject(), req.Latitude,req.Longitude);
await repository.UpdateAsync(pollingStation, ct);
electionRound.UpdatePollingStationsVersion();
await electionRoundRepository.UpdateAsync(electionRound, ct);
Expand Down
4 changes: 4 additions & 0 deletions api/src/Feature.PollingStations/Update/Request.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Feature.PollingStations.Update;

public class Request
{
public Guid ElectionRoundId { get; set; }
Expand All @@ -12,4 +13,7 @@ public class Request
public int DisplayOrder { get; set; }
public string Address { get; set; }
public Dictionary<string, string> Tags { get; set; }

public double? Latitude { get; set; }
public double? Longitude { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ private PollingStation()
{
}
#pragma warning restore CS8618

internal PollingStation(ElectionRound electionRound,

public static PollingStation Create(
Guid? id,
ElectionRound electionRound,
string level1,
string level2,
string level3,
Expand All @@ -17,11 +19,24 @@ internal PollingStation(ElectionRound electionRound,
string number,
string address,
int displayOrder,
JsonDocument tags) : this(Guid.NewGuid(), electionRound, level1, level2, level3, level4, level5, number, address, displayOrder, tags)
JsonDocument tags,
double? latitude,
double? longitude,
DateTime createdOn,
Guid userId)
{
}
var pollingStation = new PollingStation(id, electionRound, level1, level2, level3, level4, level5, number, address,
displayOrder,
tags, latitude, longitude);

public static PollingStation Create(ElectionRound electionRound,
pollingStation.CreatedOn = createdOn;
pollingStation.CreatedBy = userId;

return pollingStation;
}

public static PollingStation Create(
ElectionRound electionRound,
string level1,
string level2,
string level3,
Expand All @@ -31,24 +46,20 @@ public static PollingStation Create(ElectionRound electionRound,
string address,
int displayOrder,
JsonDocument tags,
double? latitude,
double? longitude,
DateTime createdOn,
Guid userId)
{
var pollingStation = new PollingStation(electionRound, level1, level2, level3, level4, level5, number, address, displayOrder,
tags);

pollingStation.CreatedOn = createdOn;
pollingStation.CreatedBy = userId;

return pollingStation;
return Create(null, electionRound, level1, level2, level3, level4, level5, number, address,displayOrder, tags, latitude, longitude, createdOn, userId);
}

public Guid Id { get; private set; }
public ElectionRound ElectionRound { get; private set; }
public Guid ElectionRoundId { get; private set; }

internal PollingStation(
Guid id,
Guid? id,
ElectionRound electionRound,
string level1,
string level2,
Expand All @@ -58,9 +69,11 @@ internal PollingStation(
string number,
string address,
int displayOrder,
JsonDocument tags)
JsonDocument tags,
double? latitude,
double? longitude)
{
Id = id;
Id = id ?? Guid.NewGuid();
ElectionRoundId = electionRound.Id;
ElectionRound = electionRound;
Level1 = level1;
Expand All @@ -72,6 +85,8 @@ internal PollingStation(
Address = address;
DisplayOrder = displayOrder;
Tags = tags;
Latitude = latitude;
Longitude = longitude;
}

public string Level1 { get; private set; }
Expand All @@ -83,6 +98,8 @@ internal PollingStation(

public string Address { get; private set; }
public int DisplayOrder { get; private set; }
public double? Latitude { get; private set; }
public double? Longitude { get; private set; }

public JsonDocument Tags { get; private set; }

Expand All @@ -94,7 +111,9 @@ public void UpdateDetails(string level1,
string number,
string address,
int displayOrder,
JsonDocument tags)
JsonDocument tags,
double? latitude,
double? longitude)
{
Level1 = level1;
Level2 = level2;
Expand All @@ -105,7 +124,10 @@ public void UpdateDetails(string level1,
Address = address;
DisplayOrder = displayOrder;
Tags = tags;
Latitude = latitude;
Longitude = longitude;
}

public void Dispose()
{
Tags.Dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ public void Configure(EntityTypeBuilder<PollingStation> builder)
builder.Property(p => p.Id).IsRequired();
builder.Property(p => p.Address).HasMaxLength(2024).IsRequired();
builder.Property(p => p.DisplayOrder).IsRequired();
builder.Property(p => p.Tags).IsRequired(false);
builder.Property(p => p.Tags).IsRequired(false).HasDefaultValueSql("'{}'::JSONB");
builder.Property(p => p.Level1).HasMaxLength(256).IsRequired();
builder.Property(p => p.Level2).HasMaxLength(256).IsRequired(false);
builder.Property(p => p.Level3).HasMaxLength(256).IsRequired(false);
builder.Property(p => p.Level4).HasMaxLength(256).IsRequired(false);
builder.Property(p => p.Level5).HasMaxLength(256).IsRequired(false);
builder.Property(p => p.Number).HasMaxLength(256).IsRequired();
builder.Property(p => p.Latitude).IsRequired(false).HasDefaultValue(null);
builder.Property(p => p.Longitude).IsRequired(false).HasDefaultValue(null);

builder
.HasOne(x => x.ElectionRound)
Expand Down
Loading
Loading