From a477b43f57a79dc11fabef7a225f2d03fe7c8b75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Fri, 12 Mar 2021 18:01:15 +0100 Subject: [PATCH] Rename directories and projects --- Back/skydiveLogs-api.Domain/Aircraft.cs | 11 + .../skydiveLogs-api.Domain/DatabaseOptions.cs | 7 + Back/skydiveLogs-api.Domain/DropZone.cs | 25 ++ Back/skydiveLogs-api.Domain/Gear.cs | 23 ++ Back/skydiveLogs-api.Domain/Jump.cs | 29 +++ Back/skydiveLogs-api.Domain/JumpType.cs | 9 + Back/skydiveLogs-api.Domain/SimpleSummary.cs | 11 + Back/skydiveLogs-api.Domain/Statistic.cs | 9 + Back/skydiveLogs-api.Domain/User.cs | 17 ++ Back/skydiveLogs-api.Domain/UserImage.cs | 13 + .../skydiveLogs-api.Domain.csproj | 8 + .../AircraftService.cs | 45 ++++ .../DropZoneService.cs | 47 ++++ .../GearService.cs | 47 ++++ .../InitDbService.cs | 83 ++++++ .../Interfaces/IAircraftService.cs | 20 ++ .../Interfaces/IDropZoneService.cs | 20 ++ .../Interfaces/IGearService.cs | 20 ++ .../Interfaces/IInitDbService.cs | 7 + .../Interfaces/IJumpService.cs | 25 ++ .../Interfaces/IJumpTypeService.cs | 20 ++ .../Interfaces/IStatsService.cs | 30 +++ .../Interfaces/IUserImageService.cs | 20 ++ .../Interfaces/IUserService.cs | 13 + .../JumpService.cs | 77 ++++++ .../JumpTypeService.cs | 45 ++++ .../StatsService.cs | 237 ++++++++++++++++++ .../UserImageService.cs | 46 ++++ .../UserService.cs | 74 ++++++ .../skydiveLogs-api.DomainBusiness.csproj | 13 + .../AircraftRepository.cs | 56 +++++ .../DropZoneRepository.cs | 56 +++++ .../GearRepository.cs | 63 +++++ .../Interfaces/IDataProvider.cs | 28 +++ .../JumpRepository.cs | 67 +++++ .../JumpTypeRepository.cs | 56 +++++ .../LiteDbProvider.cs | 52 ++++ .../UserImageRepository.cs | 63 +++++ .../UserRepository.cs | 61 +++++ .../skydiveLogs-api.Infrastructure.csproj | 17 ++ Back/skydiveLogs-api.Ioc/IocService.cs | 4 +- .../skydiveLogs-api.Ioc.csproj | 4 +- Back/skydiveLogs-api.sln | 6 +- .../Controllers/AircraftController.cs | 2 +- .../Controllers/DropZoneController.cs | 2 +- .../Controllers/GearController.cs | 2 +- .../Controllers/ImageController.cs | 2 +- .../Controllers/JumpController.cs | 2 +- .../Controllers/JumpTypeController.cs | 2 +- .../Controllers/StatsController.cs | 2 +- .../Controllers/UserController.cs | 2 +- Back/skydiveLogs-api/Startup.cs | 2 +- Back/skydiveLogs-api/skydiveLogs-api.csproj | 4 +- 53 files changed, 1588 insertions(+), 18 deletions(-) create mode 100644 Back/skydiveLogs-api.Domain/Aircraft.cs create mode 100644 Back/skydiveLogs-api.Domain/DatabaseOptions.cs create mode 100644 Back/skydiveLogs-api.Domain/DropZone.cs create mode 100644 Back/skydiveLogs-api.Domain/Gear.cs create mode 100644 Back/skydiveLogs-api.Domain/Jump.cs create mode 100644 Back/skydiveLogs-api.Domain/JumpType.cs create mode 100644 Back/skydiveLogs-api.Domain/SimpleSummary.cs create mode 100644 Back/skydiveLogs-api.Domain/Statistic.cs create mode 100644 Back/skydiveLogs-api.Domain/User.cs create mode 100644 Back/skydiveLogs-api.Domain/UserImage.cs create mode 100644 Back/skydiveLogs-api.Domain/skydiveLogs-api.Domain.csproj create mode 100644 Back/skydiveLogs-api.DomainBusiness/AircraftService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/GearService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/InitDbService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IDropZoneService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/JumpService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/JumpTypeService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/StatsService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/UserImageService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/UserService.cs create mode 100644 Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj create mode 100644 Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/GearRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/JumpRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/UserRepository.cs create mode 100644 Back/skydiveLogs-api.Infrastructure/skydiveLogs-api.Infrastructure.csproj diff --git a/Back/skydiveLogs-api.Domain/Aircraft.cs b/Back/skydiveLogs-api.Domain/Aircraft.cs new file mode 100644 index 0000000..019e73e --- /dev/null +++ b/Back/skydiveLogs-api.Domain/Aircraft.cs @@ -0,0 +1,11 @@ +namespace skydiveLogs_api.Domain +{ + public class Aircraft + { + public int Id { get; set; } + + public string Name { get; set; } + + public string ImageData { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/DatabaseOptions.cs b/Back/skydiveLogs-api.Domain/DatabaseOptions.cs new file mode 100644 index 0000000..670c418 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/DatabaseOptions.cs @@ -0,0 +1,7 @@ +namespace skydiveLogs_api.Domain +{ + public class DatabaseOptions + { + public string ConnectionString { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/DropZone.cs b/Back/skydiveLogs-api.Domain/DropZone.cs new file mode 100644 index 0000000..71d8038 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/DropZone.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +namespace skydiveLogs_api.Domain +{ + public class DropZone + { + public int Id { get; set; } + + public string Latitude { get; set; } + + public string Longitude { get; set; } + + public string Name { get; set; } + + public string Address { get; set; } + + public string Website { get; set; } + + public string Email { get; set; } + + public IEnumerable Type { get; set; } + + public bool IsFavorite { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/Gear.cs b/Back/skydiveLogs-api.Domain/Gear.cs new file mode 100644 index 0000000..141ea74 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/Gear.cs @@ -0,0 +1,23 @@ +namespace skydiveLogs_api.Domain +{ + public class Gear + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Manufacturer { get; set; } + + public int MinSize { get; set; } + + public int MaxSize { get; set; } + + public string Aad { get; set; } + + public string MainCanopy { get; set; } + + public string ReserveCanopy { get; set; } + + public User User { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/Jump.cs b/Back/skydiveLogs-api.Domain/Jump.cs new file mode 100644 index 0000000..6d76752 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/Jump.cs @@ -0,0 +1,29 @@ +using System; + +namespace skydiveLogs_api.Domain +{ + public class Jump + { + public int Id { get; set; } + + public JumpType JumpType { get; set; } + + public Aircraft Aircraft { get; set; } + + public DropZone DropZone { get; set; } + + public Gear Gear { get; set; } + + public User User { get; set; } + + public int ExitAltitude { get; set; } + + public int DeployAltitude { get; set; } + + public bool WithCutaway { get; set; } + + public string Notes { get; set; } + + public DateTime JumpDate { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/JumpType.cs b/Back/skydiveLogs-api.Domain/JumpType.cs new file mode 100644 index 0000000..60a5279 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/JumpType.cs @@ -0,0 +1,9 @@ +namespace skydiveLogs_api.Domain +{ + public class JumpType + { + public int Id { get; set; } + + public string Name { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/SimpleSummary.cs b/Back/skydiveLogs-api.Domain/SimpleSummary.cs new file mode 100644 index 0000000..44f6abd --- /dev/null +++ b/Back/skydiveLogs-api.Domain/SimpleSummary.cs @@ -0,0 +1,11 @@ +namespace skydiveLogs_api.Domain +{ + public class SimpleSummary + { + public int TotalJumps { get; set; } + + public int TotalCutaways { get; set; } + + public Jump LastJump { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/Statistic.cs b/Back/skydiveLogs-api.Domain/Statistic.cs new file mode 100644 index 0000000..4506743 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/Statistic.cs @@ -0,0 +1,9 @@ +namespace skydiveLogs_api.Domain +{ + public class Statistic + { + public string Label { get; set; } + + public int Nb { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/User.cs b/Back/skydiveLogs-api.Domain/User.cs new file mode 100644 index 0000000..9f6e320 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/User.cs @@ -0,0 +1,17 @@ +namespace skydiveLogs_api.Domain +{ + public class User + { + public int Id { get; set; } + + public string Email { get; set; } + + public string FirstName { get; set; } + + public string LastName { get; set; } + + public string Login { get; set; } + + public string Password { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/UserImage.cs b/Back/skydiveLogs-api.Domain/UserImage.cs new file mode 100644 index 0000000..3f8cbda --- /dev/null +++ b/Back/skydiveLogs-api.Domain/UserImage.cs @@ -0,0 +1,13 @@ +namespace skydiveLogs_api.Domain +{ + public class UserImage + { + public int Id { get; set; } + + public string Comment { get; set; } + + public string Data { get; set; } + + public User User { get; set; } + } +} diff --git a/Back/skydiveLogs-api.Domain/skydiveLogs-api.Domain.csproj b/Back/skydiveLogs-api.Domain/skydiveLogs-api.Domain.csproj new file mode 100644 index 0000000..46a0374 --- /dev/null +++ b/Back/skydiveLogs-api.Domain/skydiveLogs-api.Domain.csproj @@ -0,0 +1,8 @@ + + + + net5.0 + skydiveLogs_api.Domain + + + diff --git a/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs new file mode 100644 index 0000000..659f917 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/AircraftService.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class AircraftService : IAircraftService + { + public AircraftService(IAircraftRepository aircraftRepository) + { + _aircraftRepository = aircraftRepository; + } + + public void AddNewAircraft(Aircraft newAircraft) + { + _aircraftRepository.Add(newAircraft); + } + + public void DeleteAircraftById(int id) + { + throw new NotImplementedException(); + } + + public Aircraft GetAircraftById(int id) + { + return _aircraftRepository.GetById(id); + } + + public IEnumerable GetAllAircrafts() + { + return _aircraftRepository.GetAll(); + } + + public void UpdateAircraft(int id, Aircraft aircraft) + { + throw new NotImplementedException(); + } + + private readonly IAircraftRepository _aircraftRepository; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs b/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs new file mode 100644 index 0000000..45290f0 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/DropZoneService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class DropZoneService : IDropZoneService + { + public DropZoneService(IDropZoneRepository dropZoneRepository) + { + _dropZoneRepository = dropZoneRepository; + } + + public void AddNewDz(DropZone newdropZone) + { + _dropZoneRepository.Add(newdropZone); + } + + public void DeleteDzById(int id) + { + throw new NotImplementedException(); + } + + public IEnumerable GetAllDzs() + { + return _dropZoneRepository.GetAll(); + } + + public DropZone GetDzById(int id) + { + return _dropZoneRepository.GetById(id); + } + + public bool UpdateDz(int id, DropZone dropZone) + { + dropZone.Id = id; + + return _dropZoneRepository.Update(dropZone); + } + + private readonly IDropZoneRepository _dropZoneRepository; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/GearService.cs b/Back/skydiveLogs-api.DomainBusiness/GearService.cs new file mode 100644 index 0000000..9cde48a --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/GearService.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class GearService : IGearService + { + public GearService(IGearRepository gearRepository) + { + _gearRepository = gearRepository; + } + + public void AddNewGear(Gear newGear, + User connectedUser) + { + newGear.User = connectedUser; + _gearRepository.Add(newGear); + } + + public void DeleteGearById(int id) + { + throw new NotImplementedException(); + } + + public Gear GetGearById(int id) + { + return _gearRepository.GetById(id); + } + + public IEnumerable GetAllGears(User connectedUser) + { + return _gearRepository.GetAll(connectedUser); + } + + public void UpdateGear(int id, Gear Gear) + { + throw new NotImplementedException(); + } + + private readonly IGearRepository _gearRepository; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs b/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs new file mode 100644 index 0000000..7145d05 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/InitDbService.cs @@ -0,0 +1,83 @@ +using System.Collections.Generic; +using System.IO; +using System.Text.Json; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class InitDbService : IInitDbService + { + public InitDbService(IAircraftService aircraftService, + IJumpTypeService jumpTypeService, + IDropZoneService dropZoneService) + { + _aircraftService = aircraftService; + _jumpTypeService = jumpTypeService; + _dropZoneService = dropZoneService; + } + + public void GenerateDb() + { + LoadAircrafts(); + LoadDropZones(); + LoadJumpTypes(); + } + + private void LoadDropZones() + { + var jsonString = File.ReadAllText("Init/dropZone.json"); + var options = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true + }; + var jsonModel = JsonSerializer.Deserialize>(jsonString, options); + + foreach (var item in jsonModel) + { + _dropZoneService.AddNewDz(item); + } + } + + private void LoadJumpTypes() + { + var jsonString = File.ReadAllText("Init/jumpType.json"); + var options = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true + }; + var jsonModel = JsonSerializer.Deserialize>(jsonString, options); + + foreach (var item in jsonModel) + { + _jumpTypeService.AddNewJumpType(item); + } + } + + private void LoadAircrafts() + { + var jsonString = File.ReadAllText("Init/aircraft.json"); + var options = new JsonSerializerOptions + { + PropertyNamingPolicy = JsonNamingPolicy.CamelCase, + WriteIndented = true + }; + var jsonModel = JsonSerializer.Deserialize>(jsonString, options); + + foreach (var item in jsonModel) + { + _aircraftService.AddNewAircraft(item); + } + } + + private readonly IAircraftService _aircraftService; + + private readonly IJumpTypeService _jumpTypeService; + + private readonly IDropZoneService _dropZoneService; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs new file mode 100644 index 0000000..4120ef3 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IAircraftService + { + IEnumerable GetAllAircrafts(); + + Aircraft GetAircraftById(int id); + + void AddNewAircraft(Aircraft aircraft); + + void UpdateAircraft(int id, Aircraft aircraft); + + void DeleteAircraftById(int id); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IDropZoneService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IDropZoneService.cs new file mode 100644 index 0000000..d1656e4 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IDropZoneService.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IDropZoneService + { + IEnumerable GetAllDzs(); + + DropZone GetDzById(int id); + + void DeleteDzById(int id); + + bool UpdateDz(int id, DropZone dropZone); + + void AddNewDz(DropZone dropZone); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs new file mode 100644 index 0000000..73276be --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IGearService.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IGearService + { + IEnumerable GetAllGears(User connectedUser); + + Gear GetGearById(int id); + + void DeleteGearById(int id); + + void UpdateGear(int id, Gear gear); + + void AddNewGear(Gear gear, User connectedUser); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs new file mode 100644 index 0000000..85717ec --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs @@ -0,0 +1,7 @@ +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IInitDbService + { + public void GenerateDb(); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs new file mode 100644 index 0000000..9b597b6 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs @@ -0,0 +1,25 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IJumpService + { + IEnumerable GetAllJumps(User connectedUser); + + Jump GetJumpById(int id); + + void AddNewJump(int aircraftId, + int dzId, + int jumpTypeId, + int gearId, + Jump jump, + User connectedUser); + + void UpdateJump(int id, Jump jump); + + void DeleteJumpById(int id); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs new file mode 100644 index 0000000..0045884 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IJumpTypeService + { + IEnumerable GetAllJumpTypes(); + + JumpType GetJumpTypeById(int id); + + void AddNewJumpType(JumpType value); + + void UpdateJumpType(int id, JumpType value); + + void DeleteJumpTypeById(int id); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs new file mode 100644 index 0000000..18ad624 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IStatsService.cs @@ -0,0 +1,30 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IStatsService + { + IEnumerable GetStatsByDz(User connectedUser); + + IEnumerable GetStatsByAircraft(User connectedUser); + + IEnumerable GetStatsByJumpType(User connectedUser); + + IEnumerable GetStatsByGear(User connectedUser); + + IEnumerable GetStatsByYear(User connectedUser); + + IEnumerable GetStatsForLastYearByDz(User connectedUser); + + IEnumerable GetStatsForLastYearByJumpType(User connectedUser); + + IEnumerable GetStatsForLastMonthByDz(User connectedUser); + + IEnumerable GetStatsForLastMonthByJumpType(User connectedUser); + + SimpleSummary GetSimpleSummary(User connectedUser); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs new file mode 100644 index 0000000..e5c6c29 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IUserImageService + { + IEnumerable GetAllImages(User connectedUser); + + UserImage GetImageById(int id); + + void AddNewImage(UserImage image, User connectedUser); + + void UpdateImage(int id, UserImage image); + + void DeleteImageById(int id); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs new file mode 100644 index 0000000..a513320 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs @@ -0,0 +1,13 @@ +using skydiveLogs_api.Domain; + +namespace skydiveLogs_api.DomainBusiness.Interfaces +{ + public interface IUserService + { + User GetByLogin(string login, string password); + + User GetById(int userId); + + bool AddNewUser(User user); + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs new file mode 100644 index 0000000..15bd2af --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class JumpService : IJumpService + { + 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(int aircraftId, + int dzId, + int jumpTypeId, + int gearId, + Jump jump, + User connectedUser) + { + 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; + jump.User = connectedUser; + + _jumpRepository.Add(jump); + } + + public void DeleteJumpById(int id) + { + throw new NotImplementedException(); + } + + public IEnumerable GetAllJumps(User connectedUser) + { + return _jumpRepository.GetAll(connectedUser); + } + + public Jump GetJumpById(int id) + { + return _jumpRepository.GetById(id); + } + + public void UpdateJump(int id, Jump jump) + { + throw new NotImplementedException(); + } + + 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.DomainBusiness/JumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/JumpTypeService.cs new file mode 100644 index 0000000..d3d4855 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/JumpTypeService.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class JumpTypeService : IJumpTypeService + { + public JumpTypeService(IJumpTypeRepository jumpTypeRepository) + { + _jumpTypeRepository = jumpTypeRepository; + } + + public void AddNewJumpType(JumpType newJumpType) + { + _jumpTypeRepository.Add(newJumpType); + } + + public void DeleteJumpTypeById(int id) + { + throw new NotImplementedException(); + } + + public IEnumerable GetAllJumpTypes() + { + return _jumpTypeRepository.GetAll(); + } + + public JumpType GetJumpTypeById(int id) + { + return _jumpTypeRepository.GetById(id); + } + + public void UpdateJumpType(int id, JumpType value) + { + throw new NotImplementedException(); + } + + private readonly IJumpTypeRepository _jumpTypeRepository; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/StatsService.cs b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs new file mode 100644 index 0000000..fbc58ef --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/StatsService.cs @@ -0,0 +1,237 @@ +using System.Collections.Generic; +using System.Linq; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class StatsService : IStatsService + { + public StatsService(IJumpService jumpService) + { + _jumpService = jumpService; + } + + public IEnumerable GetStatsByAircraft(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.Aircraft.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsByDz(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsByJumpType(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsByGear(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.Gear.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsByYear(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + results = allJumps.GroupBy(j => j.JumpDate.Year, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsForLastYearByDz(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsForLastYearByJumpType(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + + results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsForLastMonthByDz(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.DropZone.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public IEnumerable GetStatsForLastMonthByJumpType(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new List(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + var yearOfLastJump = lastJump.JumpDate.Year; + var monthOfLastJump = lastJump.JumpDate.Month; + + results = allJumps.Where(j => j.JumpDate.Year == yearOfLastJump && j.JumpDate.Month == monthOfLastJump) + .GroupBy(j => j.JumpType.Name, + j => j, + (groupby, jumps) => new Statistic + { + Label = groupby.ToString(), + Nb = jumps.Count() + }) + .ToList(); + } + + return results; + } + + public SimpleSummary GetSimpleSummary(User connectedUser) + { + var allJumps = _jumpService.GetAllJumps(connectedUser); + var results = new SimpleSummary(); + + if (allJumps.Any()) + { + var lastJump = allJumps.OrderByDescending(j => j.JumpDate).First(); + + results = new SimpleSummary + { + LastJump = lastJump, + TotalJumps = allJumps.Count(), + TotalCutaways = allJumps.Where(j => j.WithCutaway).Count() + }; + } + + return results; + } + + private readonly IJumpService _jumpService; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/UserImageService.cs b/Back/skydiveLogs-api.DomainBusiness/UserImageService.cs new file mode 100644 index 0000000..5c8c966 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/UserImageService.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class UserImageService : IUserImageService + { + public UserImageService(IUserImageRepository imageRepository) + { + _imageRepository = imageRepository; + } + + public void AddNewImage(UserImage newImage, User connectedUser) + { + newImage.User = connectedUser; + _imageRepository.Add(newImage); + } + + public void DeleteImageById(int id) + { + throw new NotImplementedException(); + } + + public UserImage GetImageById(int id) + { + return _imageRepository.GetById(id); + } + + public IEnumerable GetAllImages(User connectedUser) + { + return _imageRepository.GetAll(connectedUser); + } + + public void UpdateImage(int id, UserImage Image) + { + throw new NotImplementedException(); + } + + private readonly IUserImageRepository _imageRepository; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/UserService.cs b/Back/skydiveLogs-api.DomainBusiness/UserService.cs new file mode 100644 index 0000000..92ca051 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/UserService.cs @@ -0,0 +1,74 @@ +using System.Security.Cryptography; +using System.Text; +using System.IO; +using System; + +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.DomainBusiness +{ + public class UserService : IUserService + { + public UserService(IUserRepository userRepository) + { + _userRepository = userRepository; + } + + public User GetById(int userId) + { + return _userRepository.GetById(userId); + } + + public User GetByLogin(string login, string password) + { + return _userRepository.GetByLogin(login, EncryptPassword(password)); + } + + public bool AddNewUser(User newUser) + { + newUser.Password = EncryptPassword(newUser.Password); + var foundUser = _userRepository.GetByLogin(newUser.Login, newUser.Password); + var result = false; + + if (foundUser == null) + { + _userRepository.Add(newUser); + result = true; + } + + return result; + } + + private string EncryptPassword(string password) + { + var encryptionKey = "skydivelogsangular"; //we can change the code converstion key as per our requirement + byte[] clearBytes = Encoding.Unicode.GetBytes(password); + var encryptedPassword = string.Empty; + + using (Aes encryptor = Aes.Create()) + { + Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey, + new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); + encryptor.Key = pdb.GetBytes(32); + encryptor.IV = pdb.GetBytes(16); + using (MemoryStream ms = new MemoryStream()) + { + using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) + { + cs.Write(clearBytes, 0, clearBytes.Length); + cs.Close(); + } + + encryptedPassword = Convert.ToBase64String(ms.ToArray()); + } + } + + return encryptedPassword; + } + + private readonly IUserRepository _userRepository; + } +} diff --git a/Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj b/Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj new file mode 100644 index 0000000..0475f09 --- /dev/null +++ b/Back/skydiveLogs-api.DomainBusiness/skydiveLogs-api.DomainBusiness.csproj @@ -0,0 +1,13 @@ + + + + net5.0 + skydiveLogs_api.DomainBusiness + + + + + + + + diff --git a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs new file mode 100644 index 0000000..52c9d27 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class AircraftRepository : IAircraftRepository + { + public AircraftRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfAircraft; + } + + public IEnumerable GetAll() + { + return _col.FindAll().ToList(); + } + + public Aircraft GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Update(Aircraft aircraft) + { + return _col.Update(aircraft); + } + + public bool Add(Aircraft newAircraft) + { + var result = true; + + try + { + _col.Insert(newAircraft); + } + catch + { + result = false; + } + + return result; + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs new file mode 100644 index 0000000..8cec9f8 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class DropZoneRepository : IDropZoneRepository + { + public DropZoneRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfDropZone; + } + + public IEnumerable GetAll() + { + return _col.FindAll().ToList(); + } + + public DropZone GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Update(DropZone updatedDz) + { + return _col.Update(updatedDz); + } + + public bool Add(DropZone newDz) + { + var result = true; + + try + { + _col.Insert(newDz); + } + catch + { + result = false; + } + + return result; + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs new file mode 100644 index 0000000..f3ae4b8 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class GearRepository : IGearRepository + { + public GearRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfGear; + } + + public IEnumerable GetAll() + { + throw new System.NotImplementedException(); + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public Gear GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Update(Gear updatedGear) + { + return _col.Update(updatedGear); + } + + public bool Add(Gear newGear) + { + var result = true; + + try + { + _col.Insert(newGear); + } + catch + { + result = false; + } + + return result; + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs new file mode 100644 index 0000000..852c079 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs @@ -0,0 +1,28 @@ +using LiteDB; + +using skydiveLogs_api.Domain; + + +namespace skydiveLogs_api.Infrastructure.Interfaces +{ + public interface IDataProvider + { + ILiteCollection GetCollection(); + + void Close(); + + ILiteCollection CollOfAircraft { get; } + + ILiteCollection CollOfDropZone { get; } + + ILiteCollection CollOfGear { get; } + + ILiteCollection CollOfJumpType { get; } + + ILiteCollection CollOfJump { get; } + + ILiteCollection CollOfUser { get; } + + ILiteCollection CollOfImage { get; } + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs new file mode 100644 index 0000000..a56a5f7 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs @@ -0,0 +1,67 @@ +using System.Collections.Generic; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class JumpRepository : IJumpRepository + { + public JumpRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfJump; + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.Aircraft) + .Include(x => x.DropZone) + .Include(x => x.Gear) + .Include(x => x.JumpType) + .Include(x => x.User) + .Query() + .Where(j => j.User.Id == user.Id) + .ToList(); + } + + public Jump GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Add(Jump newJump) + { + var result = true; + + try + { + _col.Insert(newJump); + } + catch + { + result = false; + } + + return result; + } + + public bool Update(Jump updatedJump) + { + throw new System.NotImplementedException(); + } + + public IEnumerable GetAll() + { + throw new System.NotImplementedException(); + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs new file mode 100644 index 0000000..ee5adbb --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs @@ -0,0 +1,56 @@ +using System.Collections.Generic; +using System.Linq; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class JumpTypeRepository : IJumpTypeRepository + { + public JumpTypeRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfJumpType; + } + + public IEnumerable GetAll() + { + return _col.FindAll().ToList(); + } + + public JumpType GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Update(JumpType updatedJumpType) + { + return _col.Update(updatedJumpType); + } + + public bool Add(JumpType newJumpType) + { + var result = true; + + try + { + _col.Insert(newJumpType); + } + catch + { + result = false; + } + + return result; + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs new file mode 100644 index 0000000..b10352e --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs @@ -0,0 +1,52 @@ +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class LiteDbProvider : IDataProvider + { + 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"); + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + + BsonMapper.Global.Entity().DbRef(x => x.User, "User"); + } + + public ILiteCollection GetCollection() + { + return _db.GetCollection(); + } + + public void Close() + { + _db.Dispose(); + } + + private readonly LiteDatabase _db; + + public ILiteCollection CollOfAircraft => _db.GetCollection(); + + public ILiteCollection CollOfDropZone => _db.GetCollection(); + + public ILiteCollection CollOfGear => _db.GetCollection(); + + public ILiteCollection CollOfJumpType => _db.GetCollection(); + + public ILiteCollection CollOfJump => _db.GetCollection(); + + public ILiteCollection CollOfUser => _db.GetCollection(); + + public ILiteCollection CollOfImage => _db.GetCollection(); + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs new file mode 100644 index 0000000..375d089 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs @@ -0,0 +1,63 @@ +using System.Collections.Generic; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class UserImageRepository : IUserImageRepository + { + public UserImageRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfImage; + } + + public IEnumerable GetAll() + { + throw new System.NotImplementedException(); + } + + public IEnumerable GetAll(User user) + { + return _col.Include(x => x.User) + .Query() + .Where(j => j.User == user) + .ToList(); + } + + public UserImage GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Update(UserImage image) + { + return _col.Update(image); + } + + public bool Add(UserImage newImage) + { + var result = true; + + try + { + _col.Insert(newImage); + } + catch + { + result = false; + } + + return result; + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs new file mode 100644 index 0000000..883bf5d --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; + +using LiteDB; + +using skydiveLogs_api.Domain; +using skydiveLogs_api.DomainService.Repositories; +using skydiveLogs_api.Infrastructure.Interfaces; + + +namespace skydiveLogs_api.Infrastructure +{ + public class UserRepository : IUserRepository + { + public UserRepository(IDataProvider dataProvider) + { + _dataProvider = dataProvider; + _col = _dataProvider.CollOfUser; + } + + public User GetByLogin(string login, string password) + { + return _col.FindOne(u => u.Login == login && u.Password == password); + } + + public bool Add(User newUser) + { + var result = true; + + try + { + _col.Insert(newUser); + } + catch + { + result = false; + } + + return result; + } + + public IEnumerable GetAll() + { + throw new NotImplementedException(); + } + + public User GetById(int id) + { + return _col.FindById(new BsonValue(id)); + } + + public bool Update(User updated) + { + throw new NotImplementedException(); + } + + private readonly IDataProvider _dataProvider; + + private readonly ILiteCollection _col; + } +} diff --git a/Back/skydiveLogs-api.Infrastructure/skydiveLogs-api.Infrastructure.csproj b/Back/skydiveLogs-api.Infrastructure/skydiveLogs-api.Infrastructure.csproj new file mode 100644 index 0000000..9be7e16 --- /dev/null +++ b/Back/skydiveLogs-api.Infrastructure/skydiveLogs-api.Infrastructure.csproj @@ -0,0 +1,17 @@ + + + + net5.0 + skydiveLogs_api.Infrastructure + + + + + + + + + + + + diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index 43c2976..e1d5445 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -3,8 +3,8 @@ using Microsoft.Extensions.DependencyInjection; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure; -using skydiveLogs_api.Business.Interfaces; -using skydiveLogs_api.Business; +using skydiveLogs_api.DomainBusiness.Interfaces; +using skydiveLogs_api.DomainBusiness; using skydiveLogs_api.Infrastructure.Interfaces; diff --git a/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj b/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj index 65b9195..c18f35c 100644 --- a/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj +++ b/Back/skydiveLogs-api.Ioc/skydiveLogs-api.Ioc.csproj @@ -6,8 +6,8 @@ - - + + diff --git a/Back/skydiveLogs-api.sln b/Back/skydiveLogs-api.sln index 3bc2536..c352ed3 100644 --- a/Back/skydiveLogs-api.sln +++ b/Back/skydiveLogs-api.sln @@ -5,11 +5,11 @@ VisualStudioVersion = 16.0.31019.35 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api", "skydiveLogs-api\skydiveLogs-api.csproj", "{0AC70CC2-CE52-4CD9-89D6-077800574360}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.Domain", "skydiveLogs-api.Model\skydiveLogs-api.Domain.csproj", "{EF101C84-AE0D-4F5E-8BC5-0C55CB0B5D23}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.Domain", "skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj", "{EF101C84-AE0D-4F5E-8BC5-0C55CB0B5D23}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.Business", "skydiveLogs-api.Business\skydiveLogs-api.Business.csproj", "{803C3CFD-71D7-452F-848D-BF3DAF876CDF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.DomainBusiness", "skydiveLogs-api.DomainBusiness\skydiveLogs-api.DomainBusiness.csproj", "{803C3CFD-71D7-452F-848D-BF3DAF876CDF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.Infrastructure", "skydiveLogs-api.Data\skydiveLogs-api.Infrastructure.csproj", "{887D2F69-A9E9-46C4-A5D9-3813A2387AA2}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.Infrastructure", "skydiveLogs-api.Infrastructure\skydiveLogs-api.Infrastructure.csproj", "{887D2F69-A9E9-46C4-A5D9-3813A2387AA2}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "skydiveLogs-api.Ioc", "skydiveLogs-api.Ioc\skydiveLogs-api.Ioc.csproj", "{D2ECA52D-DA50-47D4-8624-4487DE29E0C0}" EndProject diff --git a/Back/skydiveLogs-api/Controllers/AircraftController.cs b/Back/skydiveLogs-api/Controllers/AircraftController.cs index 43f3d9d..583accc 100644 --- a/Back/skydiveLogs-api/Controllers/AircraftController.cs +++ b/Back/skydiveLogs-api/Controllers/AircraftController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/DropZoneController.cs b/Back/skydiveLogs-api/Controllers/DropZoneController.cs index 088fb2f..aa10bf1 100644 --- a/Back/skydiveLogs-api/Controllers/DropZoneController.cs +++ b/Back/skydiveLogs-api/Controllers/DropZoneController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/GearController.cs b/Back/skydiveLogs-api/Controllers/GearController.cs index 5379f78..c3d0e62 100644 --- a/Back/skydiveLogs-api/Controllers/GearController.cs +++ b/Back/skydiveLogs-api/Controllers/GearController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/ImageController.cs b/Back/skydiveLogs-api/Controllers/ImageController.cs index 17768ed..eb82344 100644 --- a/Back/skydiveLogs-api/Controllers/ImageController.cs +++ b/Back/skydiveLogs-api/Controllers/ImageController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/JumpController.cs b/Back/skydiveLogs-api/Controllers/JumpController.cs index 1cc447e..f200463 100644 --- a/Back/skydiveLogs-api/Controllers/JumpController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs index 04bca6d..128036e 100644 --- a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs @@ -5,7 +5,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/StatsController.cs b/Back/skydiveLogs-api/Controllers/StatsController.cs index e5ef1bb..81103ab 100644 --- a/Back/skydiveLogs-api/Controllers/StatsController.cs +++ b/Back/skydiveLogs-api/Controllers/StatsController.cs @@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Cors; using AutoMapper; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; diff --git a/Back/skydiveLogs-api/Controllers/UserController.cs b/Back/skydiveLogs-api/Controllers/UserController.cs index b732b18..bef2100 100644 --- a/Back/skydiveLogs-api/Controllers/UserController.cs +++ b/Back/skydiveLogs-api/Controllers/UserController.cs @@ -11,7 +11,7 @@ using Microsoft.Extensions.Options; using AutoMapper; using skydiveLogs_api.Domain; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DataContract; using skydiveLogs_api.Settings; diff --git a/Back/skydiveLogs-api/Startup.cs b/Back/skydiveLogs-api/Startup.cs index 95b234c..d0d82d1 100644 --- a/Back/skydiveLogs-api/Startup.cs +++ b/Back/skydiveLogs-api/Startup.cs @@ -11,7 +11,7 @@ using Microsoft.IdentityModel.Tokens; using skydiveLogs_api.Ioc; using skydiveLogs_api.Settings; -using skydiveLogs_api.Business.Interfaces; +using skydiveLogs_api.DomainBusiness.Interfaces; namespace skydiveLogs_api diff --git a/Back/skydiveLogs-api/skydiveLogs-api.csproj b/Back/skydiveLogs-api/skydiveLogs-api.csproj index af6cc07..1820661 100644 --- a/Back/skydiveLogs-api/skydiveLogs-api.csproj +++ b/Back/skydiveLogs-api/skydiveLogs-api.csproj @@ -26,9 +26,9 @@ - + - +