Commit 3b5879b1 authored by Andres Käver's avatar Andres Käver
Browse files

locations bulk upload

parent 9eb59e33
using System;
namespace PublicApi.DTO.v1
{
public class GpsLocationCreate
{
public DateTime RecordedAt { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Accuracy { get; set; }
public double Altitude { get; set; }
public double VerticalAccuracy { get; set; }
public Guid GpsLocationTypeId { get; set; }
}
}
\ No newline at end of file
using System;
namespace PublicApi.DTO.v1
{
public class GpsLocationCreateBulkResponse
{
public int LocationsAdded { get; set; }
public int LocationsReceived { get; set; }
public Guid GpsSessionId { get; set; }
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BLL.App.DTO;
using Contracts.BLL.App;
using Extensions;
using Microsoft.AspNetCore.Authentication.JwtBearer;
......@@ -130,12 +131,53 @@ namespace WebApp.ApiControllers._1._0
_bll.GpsLocations.Add(bllEntity);
await _bll.SaveChangesAsync();
gpsLocation.Id = bllEntity.Id;
return CreatedAtAction("GetGpsLocation",
new {id = gpsLocation.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0"},
gpsLocation);
}
/// <summary>
/// Create/add a GpsLocation collection
/// </summary>
/// <param name="gpsSessionId">Id of session where to add the locations</param>
/// <param name="gpsLocations">Collection of Location info-s</param>
/// <returns></returns>
[Produces("application/json")]
[Consumes("application/json")]
[ProducesResponseType(StatusCodes.Status201Created, Type = typeof(V1DTO.GpsLocationCreateBulkResponse))]
[HttpPost("bulkupload/{gpsSessionId}")]
public async Task<ActionResult<V1DTO.GpsLocation>> PostBulkGpsLocation(Guid gpsSessionId,
V1DTO.GpsLocationCreate[] gpsLocations)
{
foreach (var gpsLocation in gpsLocations)
{
if (gpsLocation.RecordedAt == DateTime.MinValue)
{
continue;
}
var bllGpsLocation = new GpsLocation()
{
RecordedAt = gpsLocation.RecordedAt,
AppUserId = User.UserId(),
Latitude = gpsLocation.Latitude,
Longitude = gpsLocation.Longitude,
Accuracy = gpsLocation.Accuracy,
Altitude = gpsLocation.Altitude,
VerticalAccuracy = gpsLocation.VerticalAccuracy,
GpsSessionId = gpsSessionId,
GpsLocationTypeId = gpsLocation.GpsLocationTypeId
};
_bll.GpsLocations.Add(bllGpsLocation);
}
var resultCount = await _bll.SaveChangesAsync();
return Ok(new V1DTO.GpsLocationCreateBulkResponse() {LocationsAdded = resultCount, LocationsReceived = gpsLocations.Length, GpsSessionId = gpsSessionId});
}
/// <summary>
/// Deletes the GpsLocation
/// </summary>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment