Rename directories and projects

This commit is contained in:
Sébastien André
2021-03-12 18:01:15 +01:00
parent 9341bb284e
commit a477b43f57
53 changed files with 1588 additions and 18 deletions

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,7 @@
namespace skydiveLogs_api.Domain
{
public class DatabaseOptions
{
public string ConnectionString { get; set; }
}
}

View File

@@ -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<string> Type { get; set; }
public bool IsFavorite { get; set; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,9 @@
namespace skydiveLogs_api.Domain
{
public class JumpType
{
public int Id { get; set; }
public string Name { get; set; }
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,9 @@
namespace skydiveLogs_api.Domain
{
public class Statistic
{
public string Label { get; set; }
public int Nb { get; set; }
}
}

View File

@@ -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; }
}
}

View File

@@ -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; }
}
}

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>skydiveLogs_api.Domain</RootNamespace>
</PropertyGroup>
</Project>

View File

@@ -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<Aircraft> GetAllAircrafts()
{
return _aircraftRepository.GetAll();
}
public void UpdateAircraft(int id, Aircraft aircraft)
{
throw new NotImplementedException();
}
private readonly IAircraftRepository _aircraftRepository;
}
}

View File

@@ -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<DropZone> 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;
}
}

View File

@@ -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<Gear> GetAllGears(User connectedUser)
{
return _gearRepository.GetAll(connectedUser);
}
public void UpdateGear(int id, Gear Gear)
{
throw new NotImplementedException();
}
private readonly IGearRepository _gearRepository;
}
}

View File

@@ -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<List<DropZone>>(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<List<JumpType>>(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<List<Aircraft>>(jsonString, options);
foreach (var item in jsonModel)
{
_aircraftService.AddNewAircraft(item);
}
}
private readonly IAircraftService _aircraftService;
private readonly IJumpTypeService _jumpTypeService;
private readonly IDropZoneService _dropZoneService;
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IAircraftService
{
IEnumerable<Aircraft> GetAllAircrafts();
Aircraft GetAircraftById(int id);
void AddNewAircraft(Aircraft aircraft);
void UpdateAircraft(int id, Aircraft aircraft);
void DeleteAircraftById(int id);
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IDropZoneService
{
IEnumerable<DropZone> GetAllDzs();
DropZone GetDzById(int id);
void DeleteDzById(int id);
bool UpdateDz(int id, DropZone dropZone);
void AddNewDz(DropZone dropZone);
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IGearService
{
IEnumerable<Gear> GetAllGears(User connectedUser);
Gear GetGearById(int id);
void DeleteGearById(int id);
void UpdateGear(int id, Gear gear);
void AddNewGear(Gear gear, User connectedUser);
}
}

View File

@@ -0,0 +1,7 @@
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IInitDbService
{
public void GenerateDb();
}
}

View File

@@ -0,0 +1,25 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IJumpService
{
IEnumerable<Jump> 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);
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IJumpTypeService
{
IEnumerable<JumpType> GetAllJumpTypes();
JumpType GetJumpTypeById(int id);
void AddNewJumpType(JumpType value);
void UpdateJumpType(int id, JumpType value);
void DeleteJumpTypeById(int id);
}
}

View File

@@ -0,0 +1,30 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IStatsService
{
IEnumerable<Statistic> GetStatsByDz(User connectedUser);
IEnumerable<Statistic> GetStatsByAircraft(User connectedUser);
IEnumerable<Statistic> GetStatsByJumpType(User connectedUser);
IEnumerable<Statistic> GetStatsByGear(User connectedUser);
IEnumerable<Statistic> GetStatsByYear(User connectedUser);
IEnumerable<Statistic> GetStatsForLastYearByDz(User connectedUser);
IEnumerable<Statistic> GetStatsForLastYearByJumpType(User connectedUser);
IEnumerable<Statistic> GetStatsForLastMonthByDz(User connectedUser);
IEnumerable<Statistic> GetStatsForLastMonthByJumpType(User connectedUser);
SimpleSummary GetSimpleSummary(User connectedUser);
}
}

View File

@@ -0,0 +1,20 @@
using System.Collections.Generic;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IUserImageService
{
IEnumerable<UserImage> GetAllImages(User connectedUser);
UserImage GetImageById(int id);
void AddNewImage(UserImage image, User connectedUser);
void UpdateImage(int id, UserImage image);
void DeleteImageById(int id);
}
}

View File

@@ -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);
}
}

View File

@@ -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<Jump> 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;
}
}

View File

@@ -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<JumpType> 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;
}
}

View File

@@ -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<Statistic> GetStatsByAircraft(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByDz(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByJumpType(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByGear(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsByYear(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsForLastYearByDz(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsForLastYearByJumpType(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsForLastMonthByDz(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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<Statistic> GetStatsForLastMonthByJumpType(User connectedUser)
{
var allJumps = _jumpService.GetAllJumps(connectedUser);
var results = new List<Statistic>();
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;
}
}

View File

@@ -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<UserImage> GetAllImages(User connectedUser)
{
return _imageRepository.GetAll(connectedUser);
}
public void UpdateImage(int id, UserImage Image)
{
throw new NotImplementedException();
}
private readonly IUserImageRepository _imageRepository;
}
}

View File

@@ -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;
}
}

View File

@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>skydiveLogs_api.DomainBusiness</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
</ItemGroup>
</Project>

View File

@@ -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<Aircraft> 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<Aircraft> _col;
}
}

View File

@@ -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<DropZone> 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<DropZone> _col;
}
}

View File

@@ -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<Gear> GetAll()
{
throw new System.NotImplementedException();
}
public IEnumerable<Gear> 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<Gear> _col;
}
}

View File

@@ -0,0 +1,28 @@
using LiteDB;
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.Infrastructure.Interfaces
{
public interface IDataProvider
{
ILiteCollection<T> GetCollection<T>();
void Close();
ILiteCollection<Aircraft> CollOfAircraft { get; }
ILiteCollection<DropZone> CollOfDropZone { get; }
ILiteCollection<Gear> CollOfGear { get; }
ILiteCollection<JumpType> CollOfJumpType { get; }
ILiteCollection<Jump> CollOfJump { get; }
ILiteCollection<User> CollOfUser { get; }
ILiteCollection<UserImage> CollOfImage { get; }
}
}

View File

@@ -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<Jump> 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<Jump> GetAll()
{
throw new System.NotImplementedException();
}
private readonly IDataProvider _dataProvider;
private readonly ILiteCollection<Jump> _col;
}
}

View File

@@ -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<JumpType> 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<JumpType> _col;
}
}

View File

@@ -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<Jump>().DbRef(x => x.JumpType, "JumpType");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Aircraft, "Aircraft");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Gear, "Gear");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.User, "User");
BsonMapper.Global.Entity<UserImage>().DbRef(x => x.User, "User");
BsonMapper.Global.Entity<Gear>().DbRef(x => x.User, "User");
}
public ILiteCollection<T> GetCollection<T>()
{
return _db.GetCollection<T>();
}
public void Close()
{
_db.Dispose();
}
private readonly LiteDatabase _db;
public ILiteCollection<Aircraft> CollOfAircraft => _db.GetCollection<Aircraft>();
public ILiteCollection<DropZone> CollOfDropZone => _db.GetCollection<DropZone>();
public ILiteCollection<Gear> CollOfGear => _db.GetCollection<Gear>();
public ILiteCollection<JumpType> CollOfJumpType => _db.GetCollection<JumpType>();
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
public ILiteCollection<UserImage> CollOfImage => _db.GetCollection<UserImage>();
}
}

View File

@@ -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<UserImage> GetAll()
{
throw new System.NotImplementedException();
}
public IEnumerable<UserImage> 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<UserImage> _col;
}
}

View File

@@ -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<User> 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<User> _col;
}
}

View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<RootNamespace>skydiveLogs_api.Infrastructure</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.10" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\skydiveLogs-api.DomainService\skydiveLogs-api.DomainService.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
</ItemGroup>
</Project>

View File

@@ -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;

View File

@@ -6,8 +6,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\skydiveLogs-api.Business\skydiveLogs-api.Business.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Data\skydiveLogs-api.Infrastructure.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Infrastructure\skydiveLogs-api.Infrastructure.csproj" />
<ProjectReference Include="..\skydiveLogs-api.DomainBusiness\skydiveLogs-api.DomainBusiness.csproj" />
</ItemGroup>
<ItemGroup>

View File

@@ -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

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -4,7 +4,7 @@ using Microsoft.AspNetCore.Cors;
using AutoMapper;
using skydiveLogs_api.Business.Interfaces;
using skydiveLogs_api.DomainBusiness.Interfaces;
using skydiveLogs_api.DataContract;

View File

@@ -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;

View File

@@ -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

View File

@@ -26,9 +26,9 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\skydiveLogs-api.Business\skydiveLogs-api.Business.csproj" />
<ProjectReference Include="..\skydiveLogs-api.DomainBusiness\skydiveLogs-api.DomainBusiness.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Ioc\skydiveLogs-api.Ioc.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Model\skydiveLogs-api.Domain.csproj" />
<ProjectReference Include="..\skydiveLogs-api.Domain\skydiveLogs-api.Domain.csproj" />
</ItemGroup>
</Project>