diff --git a/Back/skydiveLogs-api.Business/GearService.cs b/Back/skydiveLogs-api.Business/GearService.cs new file mode 100644 index 0000000..e0f56ee --- /dev/null +++ b/Back/skydiveLogs-api.Business/GearService.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.Business.Interface; +using skydiveLogs_api.Model; +using skydiveLogs_api.Data.Interface; + + +namespace skydiveLogs_api.Business +{ + public class GearService : IGearService + { + public GearService(IGearRepository gearRepository) + { + _gearRepository = gearRepository; + } + + public void AddNewGear(Gear Gear) + { + throw new NotImplementedException(); + } + + public void DeleteGearById(int id) + { + throw new NotImplementedException(); + } + + public Gear GetGearById(int id) + { + return _gearRepository.GetById(id); + } + + public IEnumerable GetAllGears() + { + return _gearRepository.GetAll(); + } + + public void UpdateGear(int id, Gear Gear) + { + throw new NotImplementedException(); + } + + private readonly IGearRepository _gearRepository; + } +} diff --git a/Back/skydiveLogs-api.Business/Interface/IGearService.cs b/Back/skydiveLogs-api.Business/Interface/IGearService.cs new file mode 100644 index 0000000..2f6f951 --- /dev/null +++ b/Back/skydiveLogs-api.Business/Interface/IGearService.cs @@ -0,0 +1,18 @@ +using System.Collections.Generic; +using skydiveLogs_api.Model; + +namespace skydiveLogs_api.Business.Interface +{ + public interface IGearService + { + IEnumerable GetAllGears(); + + Gear GetGearById(int id); + + void DeleteGearById(int id); + + void UpdateGear(int id, Gear Gear); + + void AddNewGear(Gear Gear); + } +} diff --git a/Back/skydiveLogs-api.Business/Interface/IJumpService.cs b/Back/skydiveLogs-api.Business/Interface/IJumpService.cs index eeb9ac3..dae85d7 100644 --- a/Back/skydiveLogs-api.Business/Interface/IJumpService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IJumpService.cs @@ -11,7 +11,11 @@ namespace skydiveLogs_api.Business.Interface Jump GetJumpById(int id); - void AddNewJump(Jump jump); + void AddNewJump(int aircraftId, + int dzId, + int jumpTypeId, + int gearId, + Jump jump); void UpdateJump(int id, Jump jump); diff --git a/Back/skydiveLogs-api.Business/JumpService.cs b/Back/skydiveLogs-api.Business/JumpService.cs index 548d4be..feb7911 100644 --- a/Back/skydiveLogs-api.Business/JumpService.cs +++ b/Back/skydiveLogs-api.Business/JumpService.cs @@ -10,13 +10,35 @@ namespace skydiveLogs_api.Business { public class JumpService : IJumpService { - public JumpService(IJumpRepository jumpRepository) + public JumpService(IJumpTypeService jumpTypeService, + IAircraftService aircraftService, + IDropZoneService dropZoneService, + IGearService gearService, + IJumpRepository jumpRepository) { + _jumpTypeService = jumpTypeService; + _aircraftService = aircraftService; + _dropZoneService = dropZoneService; + _gearService = gearService; _jumpRepository = jumpRepository; } - public void AddNewJump(Jump jump) + public void AddNewJump(int aircraftId, + int dzId, + int jumpTypeId, + int gearId, + Jump jump) { + var selectedGear = _gearService.GetGearById(gearId); + var selectedJumpType = _jumpTypeService.GetJumpTypeById(jumpTypeId); + var selectedAircraft = _aircraftService.GetAircraftById(aircraftId); + var selectedDropZone = _dropZoneService.GetDzById(dzId); + + jump.Aircraft = selectedAircraft; + jump.JumpType = selectedJumpType; + jump.DropZone = selectedDropZone; + jump.Gear = selectedGear; + _jumpRepository.AddJump(jump); } @@ -41,5 +63,13 @@ namespace skydiveLogs_api.Business } private readonly IJumpRepository _jumpRepository; + + private readonly IJumpTypeService _jumpTypeService; + + private readonly IAircraftService _aircraftService; + + private readonly IDropZoneService _dropZoneService; + + private readonly IGearService _gearService; } } diff --git a/Back/skydiveLogs-api.Data/JumpRepository.cs b/Back/skydiveLogs-api.Data/JumpRepository.cs index d6a344a..51eda54 100644 --- a/Back/skydiveLogs-api.Data/JumpRepository.cs +++ b/Back/skydiveLogs-api.Data/JumpRepository.cs @@ -19,7 +19,12 @@ namespace skydiveLogs_api.Data public IEnumerable GetAll() { - return _col.FindAll().ToList(); + return _col.Include(x => x.Aircraft) + .Include(x => x.DropZone) + .Include(x => x.Gear) + .Include(x => x.JumpType) + .FindAll() + .ToList(); } public Jump GetById(int id) diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index 5a53be6..df5860b 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -20,6 +20,7 @@ namespace skydiveLogs_api.Ioc //_services.AddSingleton(); _services.AddScoped(); + _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); _services.AddScoped(); diff --git a/Back/skydiveLogs-api.Model/Jump.cs b/Back/skydiveLogs-api.Model/Jump.cs index eb00327..963fd28 100644 --- a/Back/skydiveLogs-api.Model/Jump.cs +++ b/Back/skydiveLogs-api.Model/Jump.cs @@ -6,14 +6,6 @@ namespace skydiveLogs_api.Model { public int Id { get; set; } - //public int JumpTypeId { get; set; } - - //public int AircraftId { get; set; } - - //public int DropZoneId { get; set; } - - //public int GearId { get; set; } - public JumpType JumpType { get; set; } public Aircraft Aircraft { get; set; } diff --git a/Back/skydiveLogs-api/Controllers/GearController.cs b/Back/skydiveLogs-api/Controllers/GearController.cs new file mode 100644 index 0000000..6675066 --- /dev/null +++ b/Back/skydiveLogs-api/Controllers/GearController.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using AutoMapper; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using skydiveLogs_api.Business.Interface; +using skydiveLogs_api.DataContract; +using skydiveLogs_api.Model; + +namespace skydiveLogs_api.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class GearController : ControllerBase + { + public GearController(IGearService gearService, + IMapper mapper) + { + _gearService = gearService; + _mapper = mapper; + } + + // GET: api/Gear + [HttpGet] + public IEnumerable Get() + { + var result = _gearService.GetAllGears(); + return _mapper.Map>(result); + } + + // GET: api/Gear/5 + [HttpGet("{id}")] + public GearResp Get(int id) + { + var result = _gearService.GetGearById(id); + return _mapper.Map(result); + } + + // POST: api/Gear + [HttpPost] + public void Post([FromBody] GearReq value) + { + _gearService.AddNewGear(_mapper.Map(value)); + } + + // PUT: api/Gear/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] GearReq value) + { + _gearService.UpdateGear(id, _mapper.Map(value)); + } + + // DELETE: api/ApiWithActions/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + _gearService.DeleteGearById(id); + } + + private readonly IGearService _gearService; + + private readonly IMapper _mapper; + } +} diff --git a/Back/skydiveLogs-api/Controllers/JumpController.cs b/Back/skydiveLogs-api/Controllers/JumpController.cs index 5adef89..31905e1 100644 --- a/Back/skydiveLogs-api/Controllers/JumpController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpController.cs @@ -42,7 +42,11 @@ namespace skydiveLogs_api.Controllers [HttpPost] public void Post([FromBody] JumpReq value) { - _jumpService.AddNewJump(_mapper.Map(value)); + _jumpService.AddNewJump(value.AircraftId, + value.DropZoneId, + value.JumpTypeId, + value.GearId, + _mapper.Map(value)); } // PUT: api/Jump/5 diff --git a/Back/skydiveLogs-api/Data/JumpsDb-log.db b/Back/skydiveLogs-api/Data/JumpsDb-log.db deleted file mode 100644 index f08cd2d..0000000 Binary files a/Back/skydiveLogs-api/Data/JumpsDb-log.db and /dev/null differ diff --git a/Back/skydiveLogs-api/Data/JumpsDb.db b/Back/skydiveLogs-api/Data/JumpsDb.db index 4e857b2..635ee15 100644 Binary files a/Back/skydiveLogs-api/Data/JumpsDb.db and b/Back/skydiveLogs-api/Data/JumpsDb.db differ diff --git a/Back/skydiveLogs-api/Data/LiteDB.Studio.exe b/Back/skydiveLogs-api/Data/LiteDB.Studio.exe new file mode 100644 index 0000000..27cdada Binary files /dev/null and b/Back/skydiveLogs-api/Data/LiteDB.Studio.exe differ