Merge branch 'tests_merging' of codefirst.iut.uca.fr:HeartDev/API into tests_merging

WORK-KMO2
Antoine PEREDERII 1 year ago
commit 2324a9657a

@ -18,8 +18,8 @@ public class UserDto
public string? Password { get; set; } public string? Password { get; set; }
public DateTime DateOfBirth { get; set; } public DateTime DateOfBirth { get; set; }
public string ProfilePicture { get; set; } = "https://davidalmeida.site/assets/me_avatar.f77af006.png"; public string ProfilePicture { get; set; } = "https://davidalmeida.site/assets/me_avatar.f77af006.png";
public LargeImageDto Image { get; set; } public LargeImageDto Image { get; set; } = null!;
public bool IsCoach { get; set; } public bool IsCoach { get; set; }
} }

@ -12,9 +12,11 @@ public class DataSourceDto
public float Precision { get; set; } public float Precision { get; set; }
[JsonIgnore] // [TODO] [Dave] Add a property to store the athletes and the activities so maybe adapt to have a tiny DTO
[JsonIgnore]
public IEnumerable<UserDto>? Athletes { get; set; } public IEnumerable<UserDto>? Athletes { get; set; }
// [TODO] [Dave] Add a property to store the athletes and the activities so maybe adapt to have a tiny DTO
[JsonIgnore] [JsonIgnore]
public IEnumerable<ActivityDto>? Activities { get; set; } public IEnumerable<ActivityDto>? Activities { get; set; }
} }

@ -14,7 +14,6 @@ using StubAPI;
using StubbedContextLib; using StubbedContextLib;
using Swashbuckle.AspNetCore.SwaggerGen; using Swashbuckle.AspNetCore.SwaggerGen;
namespace HeartTrackAPI; namespace HeartTrackAPI;
public class AppBootstrap(IConfiguration configuration) public class AppBootstrap(IConfiguration configuration)

@ -38,7 +38,7 @@ public class ActivityController : Controller
return BadRequest("To many object is asked the max is : " + totalCount); return BadRequest("To many object is asked the max is : " + totalCount);
} }
_logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetActivities), pageRequest); _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetActivities), pageRequest);
var activities = await _activityService.GetActivities(pageRequest.Index, pageRequest.Count, ActivityOrderCriteria.None, pageRequest.Descending ?? false); var activities = await _activityService.GetActivities(pageRequest.Index, pageRequest.Count, Enum.TryParse(pageRequest.OrderingPropertyName, out ActivityOrderCriteria result) ? result : ActivityOrderCriteria.None, pageRequest.Descending ?? false);
if(activities == null) if(activities == null)
{ {
return NotFound("No activities found"); return NotFound("No activities found");

@ -27,9 +27,7 @@ public partial class DbDataManager : IDataManager
_logger.LogInformation($"GetActivities with criteria {criteria} and descending {descending}", criteria, descending); _logger.LogInformation($"GetActivities with criteria {criteria} and descending {descending}", criteria, descending);
var activities = _dataManager.DbContext.ActivitiesSet var activities = _dataManager.DbContext.ActivitiesSet
.Include(a => a.HeartRates) .IncludeStandardProperties().GetItemsWithFilterAndOrdering(b => true, index, count, criteria, descending).ToModels();
.Include(a=>a.Athlete)
.Include(a=> a.DataSource).GetItemsWithFilterAndOrdering(b => true, index, count, criteria, descending).ToModels();
_logger.LogInformation($"Retrieved {activities.Count()} activities"); _logger.LogInformation($"Retrieved {activities.Count()} activities");
return await Task.FromResult(activities); return await Task.FromResult(activities);
@ -39,7 +37,7 @@ public partial class DbDataManager : IDataManager
{ {
_logger.LogInformation($"GetActivityByIdAsync with id {id}", id); _logger.LogInformation($"GetActivityByIdAsync with id {id}", id);
var activity = _dataManager.DbContext.ActivitiesSet.GetItemsWithFilterAndOrdering(b => b.IdActivity == id, 0, 1, ActivityOrderCriteria.None, false).First().ToModel(); var activity = _dataManager.DbContext.ActivitiesSet.IncludeStandardProperties().GetItemsWithFilterAndOrdering(b => b.IdActivity == id, 0, 1, ActivityOrderCriteria.None, false).First().ToModel();
if (activity != null) if (activity != null)
_logger.LogInformation($"Retrieved activity with ID {id}"); _logger.LogInformation($"Retrieved activity with ID {id}");
@ -147,8 +145,7 @@ public partial class DbDataManager : IDataManager
try { try {
_logger.LogInformation($"Getting activities for user with ID {userId}"); _logger.LogInformation($"Getting activities for user with ID {userId}");
var activities = _dataManager.DbContext.ActivitiesSet var activities = _dataManager.DbContext.ActivitiesSet
.Include(a => a.DataSource) .IncludeStandardProperties().GetItemsWithFilterAndOrdering(b => b.AthleteId == userId, index, count, criteria, descending).ToModels();
.GetItemsWithFilterAndOrdering(b => b.AthleteId == userId, index, count, criteria, descending).ToModels();
_logger.LogInformation($"Retrieved {activities.Count()} activities for user with ID {userId}"); _logger.LogInformation($"Retrieved {activities.Count()} activities for user with ID {userId}");
return Task.FromResult(activities); return Task.FromResult(activities);
} }

@ -93,6 +93,12 @@ public static class Extensions
} }
return query; return query;
} }
public static IQueryable<ActivityEntity> IncludeStandardProperties(this IQueryable<ActivityEntity> query)
{
return query.Include(a => a.HeartRates)
.Include(a => a.Athlete)
.Include(a => a.DataSource);
}
// public static Activity ToModel(this ActivityEntity entity) // public static Activity ToModel(this ActivityEntity entity)
// { // {
// return new Activity ( // return new Activity (

Loading…
Cancel
Save