From 29740709c616210a6fd48b70cb7d7f894537977b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Wed, 20 Nov 2019 17:43:30 +0100 Subject: [PATCH] Update the repository and model to have the join between the models --- Back/skydiveLogs-api.Business/StatsService.cs | 8 ++++---- Back/skydiveLogs-api.Data/LiteDbProvider.cs | 4 ++++ Back/skydiveLogs-api.Model/Jump.cs | 16 ++++++++++++---- Back/skydiveLogs-api/DataContract/GearReq.cs | 11 +++++++++++ Back/skydiveLogs-api/DataContract/GearResp.cs | 9 +++++++++ Back/skydiveLogs-api/DataContract/JumpResp.cs | 8 ++++---- Back/skydiveLogs-api/Mapper/ModelProfile.cs | 5 ++--- 7 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 Back/skydiveLogs-api/DataContract/GearReq.cs create mode 100644 Back/skydiveLogs-api/DataContract/GearResp.cs diff --git a/Back/skydiveLogs-api.Business/StatsService.cs b/Back/skydiveLogs-api.Business/StatsService.cs index 74ba612..82ef876 100644 --- a/Back/skydiveLogs-api.Business/StatsService.cs +++ b/Back/skydiveLogs-api.Business/StatsService.cs @@ -19,7 +19,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.AircraftId, + return allJumps.GroupBy(j => j.Aircraft.Id, j => j, (groupby, jumps) => new Statistic { @@ -33,7 +33,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.DropZoneId, + return allJumps.GroupBy(j => j.DropZone.Id, j => j, (groupby, jumps) => new Statistic { @@ -47,7 +47,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.JumpTypeId, + return allJumps.GroupBy(j => j.JumpType.Id, j => j, (groupby, jumps) => new Statistic { @@ -61,7 +61,7 @@ namespace skydiveLogs_api.Business { var allJumps = _jumpRepository.GetAll(); - return allJumps.GroupBy(j => j.GearId, + return allJumps.GroupBy(j => j.Gear.Id, j => j, (groupby, jumps) => new Statistic { diff --git a/Back/skydiveLogs-api.Data/LiteDbProvider.cs b/Back/skydiveLogs-api.Data/LiteDbProvider.cs index bf41e31..66bba42 100644 --- a/Back/skydiveLogs-api.Data/LiteDbProvider.cs +++ b/Back/skydiveLogs-api.Data/LiteDbProvider.cs @@ -10,6 +10,10 @@ namespace skydiveLogs_api.Data public LiteDbProvider(string connectionString) { _db = new LiteDatabase(connectionString); + BsonMapper.Global.Entity().DbRef(x => x.JumpType, "JumpType"); + BsonMapper.Global.Entity().DbRef(x => x.Aircraft, "Aircraft"); + BsonMapper.Global.Entity().DbRef(x => x.DropZone, "DropZone"); + BsonMapper.Global.Entity().DbRef(x => x.Gear, "Gear"); } public LiteCollection GetCollection() diff --git a/Back/skydiveLogs-api.Model/Jump.cs b/Back/skydiveLogs-api.Model/Jump.cs index 7873174..eb00327 100644 --- a/Back/skydiveLogs-api.Model/Jump.cs +++ b/Back/skydiveLogs-api.Model/Jump.cs @@ -6,13 +6,21 @@ namespace skydiveLogs_api.Model { public int Id { get; set; } - public int JumpTypeId { get; set; } + //public int JumpTypeId { get; set; } - public int AircraftId { get; set; } + //public int AircraftId { get; set; } - public int DropZoneId { get; set; } + //public int DropZoneId { get; set; } - public int GearId { get; set; } + //public int GearId { get; set; } + + public JumpType JumpType { get; set; } + + public Aircraft Aircraft { get; set; } + + public DropZone DropZone { get; set; } + + public Gear Gear { get; set; } public int ExitAltitude { get; set; } diff --git a/Back/skydiveLogs-api/DataContract/GearReq.cs b/Back/skydiveLogs-api/DataContract/GearReq.cs new file mode 100644 index 0000000..40c2c53 --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/GearReq.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace skydiveLogs_api.DataContract +{ + public class GearReq + { + } +} diff --git a/Back/skydiveLogs-api/DataContract/GearResp.cs b/Back/skydiveLogs-api/DataContract/GearResp.cs new file mode 100644 index 0000000..78fa22b --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/GearResp.cs @@ -0,0 +1,9 @@ +namespace skydiveLogs_api.DataContract +{ + public class GearResp + { + public int Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Back/skydiveLogs-api/DataContract/JumpResp.cs b/Back/skydiveLogs-api/DataContract/JumpResp.cs index 95dea6e..65defbc 100644 --- a/Back/skydiveLogs-api/DataContract/JumpResp.cs +++ b/Back/skydiveLogs-api/DataContract/JumpResp.cs @@ -6,13 +6,13 @@ namespace skydiveLogs_api.DataContract { public int Id { get; set; } - public int JumpTypeId { get; set; } + public JumpTypeResp JumpType { get; set; } - public int AircraftId { get; set; } + public AircraftResp Aircraft { get; set; } - public int DropZoneId { get; set; } + public DropZoneResp DropZone { get; set; } - public int GearId { get; set; } + public GearResp Gear { get; set; } public int ExitAltitude { get; set; } diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index 30f1545..0e99c05 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -1,7 +1,4 @@ using AutoMapper; -using System; -using System.Collections.Generic; -using System.Text; namespace skydiveLogs_api.Mapper { @@ -13,7 +10,9 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + CreateMap(); + CreateMap(); CreateMap(); CreateMap(); CreateMap();