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

trackpoint filtering

parent f62f1d35
Pipeline #842 passed with stages
in 1 minute and 38 seconds
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BLL.App.DTO;
using BLL.App.Mappers;
using BLL.Base.Services;
using Contracts.BLL.App.Mappers;
......@@ -15,5 +20,10 @@ namespace BLL.App.Services
public TrackPointService(IAppUnitOfWork uow) : base(uow, uow.TrackPoints, new TrackPointServiceMapper())
{
}
public virtual async Task<IEnumerable<TrackPoint>> GetAllAsync(Guid trackId, Guid? userId = null, bool noTracking = true)
{
return (await Repository.GetAllAsync(trackId, userId, noTracking)).Select(e => Mapper.Map(e));
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DAL.App.DTO;
namespace Contracts.DAL.App.Repositories
......@@ -8,6 +11,6 @@ namespace Contracts.DAL.App.Repositories
}
public interface ITrackPointRepositoryCustom<TTrackPoint>
{
Task<IEnumerable<TTrackPoint>> GetAllAsync(Guid trackId, Guid? userId = null, bool noTracking = true);
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Contracts.DAL.App.Repositories;
using Contracts.DAL.Base.Mappers;
using DAL.App.EF.Mappers;
using DAL.Base.EF.Repositories;
using DAL.Base.Mappers;
using Domain.App;
using Microsoft.EntityFrameworkCore;
using TrackPoint = DAL.App.DTO.TrackPoint;
namespace DAL.App.EF.Repositories
{
......@@ -14,5 +20,15 @@ namespace DAL.App.EF.Repositories
public TrackPointRepository(AppDbContext repoDbContext) : base(repoDbContext, new DALMapper<Domain.App.TrackPoint, DTO.TrackPoint>())
{
}
public virtual async Task<IEnumerable<TrackPoint>> GetAllAsync(Guid trackId, Guid? userId = null, bool noTracking = true)
{
var query = PrepareQuery(userId, noTracking);
query = query.Where(e => e.TrackId == trackId)
.OrderBy(e => e.PassOrder).ThenBy(e => e.CreatedAt);
var domainEntities = await query.ToListAsync();
var result = domainEntities.Select(e => Mapper.Map(e));
return result;
}
}
}
\ No newline at end of file
......@@ -44,9 +44,21 @@ namespace WebApp.ApiControllers._1._0
[Produces("application/json")]
[Consumes("application/json")]
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(IEnumerable<V1DTO.Track>))]
public async Task<ActionResult<IEnumerable<V1DTO.TrackPoint>>> GetTrackPoints()
public async Task<ActionResult<IEnumerable<V1DTO.TrackPoint>>> GetTrackPoints(Guid? trackId)
{
return Ok((await _bll.TrackPoints.GetAllAsync()).Select(e => _mapper.Map(e)));
if (trackId == null)
{
return BadRequest(new V1DTO.MessageDTO("trackId cannot be null"));
}
if (!await _bll.Tracks.ExistsAsync(trackId.Value))
{
return NotFound(new V1DTO.MessageDTO($"Track with id {trackId} was not found"));
}
return Ok((await _bll.TrackPoints.GetAllAsync(trackId.Value)).Select(e => _mapper.Map(e)));
//return Ok((await _bll.TrackPoints.GetAllAsync()).Select(e => _mapper.Map(e)));
}
/// <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