From 0d136a938aa33a95dd0a4838f2a9faa8f0408f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Andr=C3=A9?= Date: Thu, 22 Apr 2021 23:31:08 +0200 Subject: [PATCH] Auto clean code --- .../Interfaces/IAircraftService.cs | 20 +++---- .../Interfaces/IIdentityService.cs | 4 ++ .../Interfaces/IInitDbService.cs | 6 ++- .../Interfaces/IJumpService.cs | 5 +- .../Interfaces/IJumpTypeService.cs | 18 ++++--- .../Interfaces/IUserImageService.cs | 5 +- .../Interfaces/IUserService.cs | 10 ++-- .../JumpService.cs | 1 - .../Repositories/IAircraftRepository.cs | 3 +- .../Repositories/IDropZoneRepository.cs | 3 +- .../IFavoriteDropZoneRepository.cs | 5 +- .../Repositories/IGearRepository.cs | 6 ++- .../Repositories/IJumpRepository.cs | 6 ++- .../Repositories/IJumpTypeRepository.cs | 3 +- .../Repositories/IRepository.cs | 6 ++- .../Repositories/IUserImageRepository.cs | 11 ++-- .../Repositories/IUserRepository.cs | 7 ++- .../AircraftRepository.cs | 50 +++++++++-------- .../DropZoneRepository.cs | 50 +++++++++-------- .../FavoriteDropZoneRepository.cs | 38 +++++++------ .../GearRepository.cs | 54 +++++++++++-------- .../Interfaces/IDataProvider.cs | 21 ++++---- .../JumpRepository.cs | 10 ++-- .../JumpTypeRepository.cs | 50 +++++++++-------- .../LiteDbProvider.cs | 40 ++++++++------ .../UserImageRepository.cs | 54 +++++++++++-------- .../UserRepository.cs | 32 ++++++----- .../Controllers/AircraftController.cs | 16 +++--- .../Controllers/DropZoneController.cs | 18 +++---- 29 files changed, 325 insertions(+), 227 deletions(-) diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs index 4120ef3..210f583 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IAircraftService.cs @@ -1,20 +1,22 @@ -using System.Collections.Generic; - -using skydiveLogs_api.Domain; - +using skydiveLogs_api.Domain; +using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness.Interfaces { public interface IAircraftService { - IEnumerable GetAllAircrafts(); - - Aircraft GetAircraftById(int id); + #region Public Methods void AddNewAircraft(Aircraft aircraft); + void DeleteAircraftById(int id); + + Aircraft GetAircraftById(int id); + + IEnumerable GetAllAircrafts(); + void UpdateAircraft(int id, Aircraft aircraft); - void DeleteAircraftById(int id); + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IIdentityService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IIdentityService.cs index b6aeba2..0a250c1 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IIdentityService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IIdentityService.cs @@ -4,6 +4,10 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces { public interface IIdentityService { + #region Public Properties + User ConnectedUser { get; } + + #endregion Public Properties } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs index 85717ec..04bba8f 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IInitDbService.cs @@ -2,6 +2,10 @@ { public interface IInitDbService { + #region Public Methods + public void GenerateDb(); + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs index ed7dd65..1155ea8 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs @@ -1,6 +1,5 @@ -using System.Collections.Generic; - -using skydiveLogs_api.Domain; +using skydiveLogs_api.Domain; +using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness.Interfaces { diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs index 0045884..94c68fe 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpTypeService.cs @@ -1,20 +1,22 @@ -using System.Collections.Generic; - -using skydiveLogs_api.Domain; - +using skydiveLogs_api.Domain; +using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness.Interfaces { public interface IJumpTypeService { + #region Public Methods + + void AddNewJumpType(JumpType value); + + void DeleteJumpTypeById(int id); + IEnumerable GetAllJumpTypes(); JumpType GetJumpTypeById(int id); - void AddNewJumpType(JumpType value); - void UpdateJumpType(int id, JumpType value); - void DeleteJumpTypeById(int id); + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs index 6df3b72..65d6621 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserImageService.cs @@ -1,6 +1,5 @@ -using System.Collections.Generic; - -using skydiveLogs_api.Domain; +using skydiveLogs_api.Domain; +using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness.Interfaces { diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs index 46edd5d..f88e97b 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IUserService.cs @@ -4,10 +4,14 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces { public interface IUserService { - User GetByLogin(string login, string password); + #region Public Methods + + bool AddNewUser(User user, bool isAdmin = false); User GetById(int userId); - bool AddNewUser(User user, bool isAdmin = false); + User GetByLogin(string login, string password); + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs index 6cc89dc..ca2ce4e 100644 --- a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs @@ -1,7 +1,6 @@ using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DomainService.Repositories; -using System; using System.Collections.Generic; namespace skydiveLogs_api.DomainBusiness diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IAircraftRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IAircraftRepository.cs index 5ae24ef..fc75954 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IAircraftRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IAircraftRepository.cs @@ -1,9 +1,8 @@ using skydiveLogs_api.Domain; - namespace skydiveLogs_api.DomainService.Repositories { public interface IAircraftRepository : IRepository { } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IDropZoneRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IDropZoneRepository.cs index 7dbf598..605f967 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IDropZoneRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IDropZoneRepository.cs @@ -1,9 +1,8 @@ using skydiveLogs_api.Domain; - namespace skydiveLogs_api.DomainService.Repositories { public interface IDropZoneRepository : IRepository { } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IFavoriteDropZoneRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IFavoriteDropZoneRepository.cs index 55beb3f..bbbb385 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IFavoriteDropZoneRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IFavoriteDropZoneRepository.cs @@ -5,9 +5,12 @@ namespace skydiveLogs_api.DomainService.Repositories { public interface IFavoriteDropZoneRepository : IRepository { + #region Public Methods + int Delete(int dropZoneId, int userId); IEnumerable GetAll(User user); + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IGearRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IGearRepository.cs index b07585b..f06113d 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IGearRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IGearRepository.cs @@ -5,6 +5,10 @@ namespace skydiveLogs_api.DomainService.Repositories { public interface IGearRepository : IRepository { + #region Public Methods + IEnumerable GetAll(User connectedUser); + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs index fd11a8a..68950b5 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs @@ -5,8 +5,12 @@ namespace skydiveLogs_api.DomainService.Repositories { public interface IJumpRepository : IRepository { - IEnumerable GetAll(User user); + #region Public Methods bool DeleteById(int id); + + IEnumerable GetAll(User user); + + #endregion Public Methods } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IJumpTypeRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IJumpTypeRepository.cs index aeb734a..ce84215 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IJumpTypeRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IJumpTypeRepository.cs @@ -1,9 +1,8 @@ using skydiveLogs_api.Domain; - namespace skydiveLogs_api.DomainService.Repositories { public interface IJumpTypeRepository : IRepository { } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs index 15d47af..cfc532d 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs @@ -4,12 +4,16 @@ namespace skydiveLogs_api.DomainService.Repositories { public interface IRepository { + #region Public Methods + + int Add(T newEntity); + IEnumerable GetAll(); T GetById(int id); bool Update(T updated); - int Add(T newEntity); + #endregion Public Methods } } \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IUserImageRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IUserImageRepository.cs index 87e2739..d9c35cc 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IUserImageRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IUserImageRepository.cs @@ -1,11 +1,14 @@ -using System.Collections.Generic; -using skydiveLogs_api.Domain; - +using skydiveLogs_api.Domain; +using System.Collections.Generic; namespace skydiveLogs_api.DomainService.Repositories { public interface IUserImageRepository : IRepository { + #region Public Methods + IEnumerable GetAll(User user); + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IUserRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IUserRepository.cs index c05eb9d..4f16eb4 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IUserRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IUserRepository.cs @@ -1,10 +1,13 @@ using skydiveLogs_api.Domain; - namespace skydiveLogs_api.DomainService.Repositories { public interface IUserRepository : IRepository { + #region Public Methods + User GetByLogin(string login, string password); + + #endregion Public Methods } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs index 2d51ebe..6cee341 100644 --- a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs @@ -1,37 +1,25 @@ -using System.Collections.Generic; -using System.Linq; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System.Collections.Generic; +using System.Linq; namespace skydiveLogs_api.Infrastructure { public class AircraftRepository : IAircraftRepository { + #region Public Constructors + public AircraftRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfAircraft; } - public IEnumerable GetAll() - { - return _col.FindAll().ToList(); - } + #endregion Public Constructors - public Aircraft GetById(int id) - { - return _col.FindById(new BsonValue(id)); - } - - public bool Update(Aircraft aircraft) - { - return _col.Update(aircraft); - } + #region Public Methods public int Add(Aircraft newAircraft) { @@ -50,8 +38,28 @@ namespace skydiveLogs_api.Infrastructure return result; } - private readonly IDataProvider _dataProvider; + 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); + } + + #endregion Public Methods + + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs index 043354b..d188a0b 100644 --- a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs @@ -1,37 +1,25 @@ -using System.Collections.Generic; -using System.Linq; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System.Collections.Generic; +using System.Linq; namespace skydiveLogs_api.Infrastructure { public class DropZoneRepository : IDropZoneRepository { + #region Public Constructors + public DropZoneRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfDropZone; } - public IEnumerable GetAll() - { - return _col.FindAll().ToList(); - } + #endregion Public Constructors - public DropZone GetById(int id) - { - return _col.FindById(new BsonValue(id)); - } - - public bool Update(DropZone updatedDz) - { - return _col.Update(updatedDz); - } + #region Public Methods public int Add(DropZone newDz) { @@ -50,8 +38,28 @@ namespace skydiveLogs_api.Infrastructure return result; } - private readonly IDataProvider _dataProvider; + 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); + } + + #endregion Public Methods + + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs b/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs index c7a3b76..8fe24cc 100644 --- a/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs @@ -1,26 +1,24 @@ -using System.Collections.Generic; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System.Collections.Generic; namespace skydiveLogs_api.Infrastructure { public class FavoriteDropZoneRepository : IFavoriteDropZoneRepository { + #region Public Constructors + public FavoriteDropZoneRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfFavoriteDropZone; } - public int Delete(int dropZoneId, int userId) - { - return _col.DeleteMany(d => d.DropZone.Id == dropZoneId && d.User.Id == userId); - } + #endregion Public Constructors + + #region Public Methods public int Add(FavoriteDropZone favoriteToAdd) { @@ -39,6 +37,11 @@ namespace skydiveLogs_api.Infrastructure return result; } + public int Delete(int dropZoneId, int userId) + { + return _col.DeleteMany(d => d.DropZone.Id == dropZoneId && d.User.Id == userId); + } + public IEnumerable GetAll(User user) { return _col.Query() @@ -46,6 +49,11 @@ namespace skydiveLogs_api.Infrastructure .ToList(); } + public IEnumerable GetAll() + { + throw new System.NotImplementedException(); + } + public FavoriteDropZone GetById(int id) { throw new System.NotImplementedException(); @@ -56,13 +64,13 @@ namespace skydiveLogs_api.Infrastructure throw new System.NotImplementedException(); } - public IEnumerable GetAll() - { - throw new System.NotImplementedException(); - } + #endregion Public Methods - private readonly IDataProvider _dataProvider; + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs index ec8df9b..faae95a 100644 --- a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs @@ -1,22 +1,42 @@ -using System.Collections.Generic; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System.Collections.Generic; namespace skydiveLogs_api.Infrastructure { public class GearRepository : IGearRepository { + #region Public Constructors + public GearRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfGear; } + #endregion Public Constructors + + #region Public Methods + + public int Add(Gear newGear) + { + int result; + + try + { + var tmp = _col.Insert(newGear); + result = tmp.AsInt32; + } + catch + { + result = 0; + } + + return result; + } + public IEnumerable GetAll() { throw new System.NotImplementedException(); @@ -40,25 +60,13 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(updatedGear); } - public int Add(Gear newGear) - { - int result; + #endregion Public Methods - try - { - var tmp = _col.Insert(newGear); - result = tmp.AsInt32; - } - catch - { - result = 0; - } - - return result; - } - - private readonly IDataProvider _dataProvider; + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs index 0b35dd2..650ce30 100644 --- a/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs +++ b/Back/skydiveLogs-api.Infrastructure/Interfaces/IDataProvider.cs @@ -2,29 +2,32 @@ using skydiveLogs_api.Domain; - namespace skydiveLogs_api.Infrastructure.Interfaces { public interface IDataProvider { - ILiteCollection GetCollection(); + #region Public Methods void Close(); + ILiteCollection GetCollection(); + + #endregion Public Methods + + #region Public Properties + ILiteCollection CollOfAircraft { get; } ILiteCollection CollOfDropZone { get; } + ILiteCollection CollOfFavoriteDropZone { get; } ILiteCollection CollOfGear { get; } - ILiteCollection CollOfJumpType { get; } - + ILiteCollection CollOfImage { get; } ILiteCollection CollOfJump { get; } - + ILiteCollection CollOfJumpType { get; } ILiteCollection CollOfUser { get; } - ILiteCollection CollOfImage { get; } - - ILiteCollection CollOfFavoriteDropZone { get; } + #endregion Public Properties } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs index 0757e8c..8c4c3a7 100644 --- a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs @@ -37,6 +37,11 @@ namespace skydiveLogs_api.Infrastructure return result; } + public bool DeleteById(int id) + { + return _col.Delete(new BsonValue(id)); + } + public IEnumerable GetAll(User user) { return _col.Include(x => x.Aircraft) @@ -63,11 +68,6 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(updatedJump); } - public bool DeleteById(int id) - { - return _col.Delete(new BsonValue(id)); - } - #endregion Public Methods #region Private Fields diff --git a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs index 495cd53..062763b 100644 --- a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs @@ -1,37 +1,25 @@ -using System.Collections.Generic; -using System.Linq; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System.Collections.Generic; +using System.Linq; namespace skydiveLogs_api.Infrastructure { public class JumpTypeRepository : IJumpTypeRepository { + #region Public Constructors + public JumpTypeRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfJumpType; } - public IEnumerable GetAll() - { - return _col.FindAll().ToList(); - } + #endregion Public Constructors - public JumpType GetById(int id) - { - return _col.FindById(new BsonValue(id)); - } - - public bool Update(JumpType updatedJumpType) - { - return _col.Update(updatedJumpType); - } + #region Public Methods public int Add(JumpType newJumpType) { @@ -50,8 +38,28 @@ namespace skydiveLogs_api.Infrastructure return result; } - private readonly IDataProvider _dataProvider; + 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); + } + + #endregion Public Methods + + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs index 22db661..17fa608 100644 --- a/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs +++ b/Back/skydiveLogs-api.Infrastructure/LiteDbProvider.cs @@ -3,15 +3,16 @@ using skydiveLogs_api.Domain; using skydiveLogs_api.Infrastructure.Interfaces; - namespace skydiveLogs_api.Infrastructure { public class LiteDbProvider : IDataProvider { + #region Public Constructors + 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"); @@ -26,32 +27,39 @@ namespace skydiveLogs_api.Infrastructure BsonMapper.Global.Entity().DbRef(x => x.DropZone, "DropZone"); } - public ILiteCollection GetCollection() - { - return _db.GetCollection(); - } + #endregion Public Constructors + + #region Public Methods public void Close() { _db.Dispose(); } - private readonly LiteDatabase _db; + public ILiteCollection GetCollection() + { + return _db.GetCollection(); + } + + #endregion Public Methods + + #region Public Properties public ILiteCollection CollOfAircraft => _db.GetCollection(); - public ILiteCollection CollOfDropZone => _db.GetCollection(); - + public ILiteCollection CollOfFavoriteDropZone => _db.GetCollection(); public ILiteCollection CollOfGear => _db.GetCollection(); - - public ILiteCollection CollOfJumpType => _db.GetCollection(); - + public ILiteCollection CollOfImage => _db.GetCollection(); public ILiteCollection CollOfJump => _db.GetCollection(); - + public ILiteCollection CollOfJumpType => _db.GetCollection(); public ILiteCollection CollOfUser => _db.GetCollection(); - public ILiteCollection CollOfImage => _db.GetCollection(); + #endregion Public Properties - public ILiteCollection CollOfFavoriteDropZone => _db.GetCollection(); + #region Private Fields + + private readonly LiteDatabase _db; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs index 44be344..e842a35 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs @@ -1,22 +1,42 @@ -using System.Collections.Generic; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System.Collections.Generic; namespace skydiveLogs_api.Infrastructure { public class UserImageRepository : IUserImageRepository { + #region Public Constructors + public UserImageRepository(IDataProvider dataProvider) { _dataProvider = dataProvider; _col = _dataProvider.CollOfImage; } + #endregion Public Constructors + + #region Public Methods + + public int Add(UserImage newImage) + { + int result; + + try + { + var tmp = _col.Insert(newImage); + result = tmp.AsInt32; + } + catch + { + result = 0; + } + + return result; + } + public IEnumerable GetAll() { throw new System.NotImplementedException(); @@ -40,25 +60,13 @@ namespace skydiveLogs_api.Infrastructure return _col.Update(image); } - public int Add(UserImage newImage) - { - int result; + #endregion Public Methods - try - { - var tmp = _col.Insert(newImage); - result = tmp.AsInt32; - } - catch - { - result = 0; - } - - return result; - } - - private readonly IDataProvider _dataProvider; + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs index 56867cd..28235c4 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs @@ -1,27 +1,25 @@ -using System; -using System.Collections.Generic; - -using LiteDB; - +using LiteDB; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure.Interfaces; - +using System; +using System.Collections.Generic; namespace skydiveLogs_api.Infrastructure { public class UserRepository : IUserRepository { + #region Public Constructors + 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); - } + #endregion Public Constructors + + #region Public Methods public int Add(User newUser) { @@ -50,13 +48,23 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } + public User GetByLogin(string login, string password) + { + return _col.FindOne(u => u.Login == login && u.Password == password); + } + public bool Update(User updated) { throw new NotImplementedException(); } - private readonly IDataProvider _dataProvider; + #endregion Public Methods + + #region Private Fields private readonly ILiteCollection _col; + private readonly IDataProvider _dataProvider; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Controllers/AircraftController.cs b/Back/skydiveLogs-api/Controllers/AircraftController.cs index 461965d..a3b9864 100644 --- a/Back/skydiveLogs-api/Controllers/AircraftController.cs +++ b/Back/skydiveLogs-api/Controllers/AircraftController.cs @@ -40,14 +40,6 @@ namespace skydiveLogs_api.Controllers return _mapper.Map>(result); } - [HttpGet("GetSimple")] - [EnableCors] - public IEnumerable GetSimple() - { - var result = _aircraftService.GetAllAircrafts(); - return _mapper.Map>(result); - } - // GET: api/Aircraft/5 [HttpGet("{id}")] [EnableCors] @@ -57,6 +49,14 @@ namespace skydiveLogs_api.Controllers return _mapper.Map(result); } + [HttpGet("GetSimple")] + [EnableCors] + public IEnumerable GetSimple() + { + var result = _aircraftService.GetAllAircrafts(); + return _mapper.Map>(result); + } + // POST: api/Aircraft [HttpPost] [EnableCors] diff --git a/Back/skydiveLogs-api/Controllers/DropZoneController.cs b/Back/skydiveLogs-api/Controllers/DropZoneController.cs index d7a712d..6a96dbd 100644 --- a/Back/skydiveLogs-api/Controllers/DropZoneController.cs +++ b/Back/skydiveLogs-api/Controllers/DropZoneController.cs @@ -49,15 +49,6 @@ namespace skydiveLogs_api.Controllers return _mapper.Map>(result); } - [HttpGet("GetSimple")] - [EnableCors] - public IEnumerable GetSimple() - { - var result = _dropZoneService.GetAllDzs(); - - return _mapper.Map>(result); - } - // GET: api/DropZone/5 [HttpGet("{id}")] [EnableCors] @@ -68,6 +59,15 @@ namespace skydiveLogs_api.Controllers return _mapper.Map(result); } + [HttpGet("GetSimple")] + [EnableCors] + public IEnumerable GetSimple() + { + var result = _dropZoneService.GetAllDzs(); + + return _mapper.Map>(result); + } + // POST: api/DropZone [HttpPost] [EnableCors]