Auto clean code

This commit is contained in:
Sébastien André
2021-04-22 23:31:08 +02:00
parent 1c66efa4e8
commit 0d136a938a
29 changed files with 325 additions and 227 deletions

View File

@@ -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<Aircraft> GetAllAircrafts();
Aircraft GetAircraftById(int id);
#region Public Methods
void AddNewAircraft(Aircraft aircraft);
void DeleteAircraftById(int id);
Aircraft GetAircraftById(int id);
IEnumerable<Aircraft> GetAllAircrafts();
void UpdateAircraft(int id, Aircraft aircraft);
void DeleteAircraftById(int id);
#endregion Public Methods
}
}

View File

@@ -4,6 +4,10 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces
{
public interface IIdentityService
{
#region Public Properties
User ConnectedUser { get; }
#endregion Public Properties
}
}

View File

@@ -2,6 +2,10 @@
{
public interface IInitDbService
{
#region Public Methods
public void GenerateDb();
#endregion Public Methods
}
}

View File

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

View File

@@ -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<JumpType> GetAllJumpTypes();
JumpType GetJumpTypeById(int id);
void AddNewJumpType(JumpType value);
void UpdateJumpType(int id, JumpType value);
void DeleteJumpTypeById(int id);
#endregion Public Methods
}
}

View File

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

View File

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

View File

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

View File

@@ -1,6 +1,5 @@
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainService.Repositories
{
public interface IAircraftRepository : IRepository<Aircraft>

View File

@@ -1,6 +1,5 @@
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainService.Repositories
{
public interface IDropZoneRepository : IRepository<DropZone>

View File

@@ -5,9 +5,12 @@ namespace skydiveLogs_api.DomainService.Repositories
{
public interface IFavoriteDropZoneRepository : IRepository<FavoriteDropZone>
{
#region Public Methods
int Delete(int dropZoneId, int userId);
IEnumerable<FavoriteDropZone> GetAll(User user);
#endregion Public Methods
}
}

View File

@@ -5,6 +5,10 @@ namespace skydiveLogs_api.DomainService.Repositories
{
public interface IGearRepository : IRepository<Gear>
{
#region Public Methods
IEnumerable<Gear> GetAll(User connectedUser);
#endregion Public Methods
}
}

View File

@@ -5,8 +5,12 @@ namespace skydiveLogs_api.DomainService.Repositories
{
public interface IJumpRepository : IRepository<Jump>
{
IEnumerable<Jump> GetAll(User user);
#region Public Methods
bool DeleteById(int id);
IEnumerable<Jump> GetAll(User user);
#endregion Public Methods
}
}

View File

@@ -1,6 +1,5 @@
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainService.Repositories
{
public interface IJumpTypeRepository : IRepository<JumpType>

View File

@@ -4,12 +4,16 @@ namespace skydiveLogs_api.DomainService.Repositories
{
public interface IRepository<T>
{
#region Public Methods
int Add(T newEntity);
IEnumerable<T> GetAll();
T GetById(int id);
bool Update(T updated);
int Add(T newEntity);
#endregion Public Methods
}
}

View File

@@ -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<UserImage>
{
#region Public Methods
IEnumerable<UserImage> GetAll(User user);
#endregion Public Methods
}
}

View File

@@ -1,10 +1,13 @@
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.DomainService.Repositories
{
public interface IUserRepository : IRepository<User>
{
#region Public Methods
User GetByLogin(string login, string password);
#endregion Public Methods
}
}

View File

@@ -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<Aircraft> 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<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);
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection<Aircraft> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -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<DropZone> 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<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);
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection<DropZone> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -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<FavoriteDropZone> GetAll(User user)
{
return _col.Query()
@@ -46,6 +49,11 @@ namespace skydiveLogs_api.Infrastructure
.ToList();
}
public IEnumerable<FavoriteDropZone> 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<FavoriteDropZone> GetAll()
{
throw new System.NotImplementedException();
}
#endregion Public Methods
private readonly IDataProvider _dataProvider;
#region Private Fields
private readonly ILiteCollection<FavoriteDropZone> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -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<Gear> 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<Gear> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -2,29 +2,32 @@
using skydiveLogs_api.Domain;
namespace skydiveLogs_api.Infrastructure.Interfaces
{
public interface IDataProvider
{
ILiteCollection<T> GetCollection<T>();
#region Public Methods
void Close();
ILiteCollection<T> GetCollection<T>();
#endregion Public Methods
#region Public Properties
ILiteCollection<Aircraft> CollOfAircraft { get; }
ILiteCollection<DropZone> CollOfDropZone { get; }
ILiteCollection<FavoriteDropZone> CollOfFavoriteDropZone { get; }
ILiteCollection<Gear> CollOfGear { get; }
ILiteCollection<JumpType> CollOfJumpType { get; }
ILiteCollection<UserImage> CollOfImage { get; }
ILiteCollection<Jump> CollOfJump { get; }
ILiteCollection<JumpType> CollOfJumpType { get; }
ILiteCollection<User> CollOfUser { get; }
ILiteCollection<UserImage> CollOfImage { get; }
ILiteCollection<FavoriteDropZone> CollOfFavoriteDropZone { get; }
#endregion Public Properties
}
}

View File

@@ -37,6 +37,11 @@ namespace skydiveLogs_api.Infrastructure
return result;
}
public bool DeleteById(int id)
{
return _col.Delete(new BsonValue(id));
}
public IEnumerable<Jump> 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

View File

@@ -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<JumpType> 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<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);
}
#endregion Public Methods
#region Private Fields
private readonly ILiteCollection<JumpType> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -3,11 +3,12 @@
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);
@@ -26,32 +27,39 @@ namespace skydiveLogs_api.Infrastructure
BsonMapper.Global.Entity<FavoriteDropZone>().DbRef(x => x.DropZone, "DropZone");
}
public ILiteCollection<T> GetCollection<T>()
{
return _db.GetCollection<T>();
}
#endregion Public Constructors
#region Public Methods
public void Close()
{
_db.Dispose();
}
private readonly LiteDatabase _db;
public ILiteCollection<T> GetCollection<T>()
{
return _db.GetCollection<T>();
}
#endregion Public Methods
#region Public Properties
public ILiteCollection<Aircraft> CollOfAircraft => _db.GetCollection<Aircraft>();
public ILiteCollection<DropZone> CollOfDropZone => _db.GetCollection<DropZone>();
public ILiteCollection<FavoriteDropZone> CollOfFavoriteDropZone => _db.GetCollection<FavoriteDropZone>();
public ILiteCollection<Gear> CollOfGear => _db.GetCollection<Gear>();
public ILiteCollection<JumpType> CollOfJumpType => _db.GetCollection<JumpType>();
public ILiteCollection<UserImage> CollOfImage => _db.GetCollection<UserImage>();
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
public ILiteCollection<JumpType> CollOfJumpType => _db.GetCollection<JumpType>();
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
public ILiteCollection<UserImage> CollOfImage => _db.GetCollection<UserImage>();
#endregion Public Properties
public ILiteCollection<FavoriteDropZone> CollOfFavoriteDropZone => _db.GetCollection<FavoriteDropZone>();
#region Private Fields
private readonly LiteDatabase _db;
#endregion Private Fields
}
}

View File

@@ -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<UserImage> 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<UserImage> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -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<User> _col;
private readonly IDataProvider _dataProvider;
#endregion Private Fields
}
}

View File

@@ -40,14 +40,6 @@ namespace skydiveLogs_api.Controllers
return _mapper.Map<IEnumerable<AircraftResp>>(result);
}
[HttpGet("GetSimple")]
[EnableCors]
public IEnumerable<AircraftSimpleResp> GetSimple()
{
var result = _aircraftService.GetAllAircrafts();
return _mapper.Map<IEnumerable<AircraftSimpleResp>>(result);
}
// GET: api/Aircraft/5
[HttpGet("{id}")]
[EnableCors]
@@ -57,6 +49,14 @@ namespace skydiveLogs_api.Controllers
return _mapper.Map<AircraftResp>(result);
}
[HttpGet("GetSimple")]
[EnableCors]
public IEnumerable<AircraftSimpleResp> GetSimple()
{
var result = _aircraftService.GetAllAircrafts();
return _mapper.Map<IEnumerable<AircraftSimpleResp>>(result);
}
// POST: api/Aircraft
[HttpPost]
[EnableCors]

View File

@@ -49,15 +49,6 @@ namespace skydiveLogs_api.Controllers
return _mapper.Map<IEnumerable<DropZoneResp>>(result);
}
[HttpGet("GetSimple")]
[EnableCors]
public IEnumerable<DropZoneSimpleResp> GetSimple()
{
var result = _dropZoneService.GetAllDzs();
return _mapper.Map<IEnumerable<DropZoneSimpleResp>>(result);
}
// GET: api/DropZone/5
[HttpGet("{id}")]
[EnableCors]
@@ -68,6 +59,15 @@ namespace skydiveLogs_api.Controllers
return _mapper.Map<DropZoneResp>(result);
}
[HttpGet("GetSimple")]
[EnableCors]
public IEnumerable<DropZoneSimpleResp> GetSimple()
{
var result = _dropZoneService.GetAllDzs();
return _mapper.Map<IEnumerable<DropZoneSimpleResp>>(result);
}
// POST: api/DropZone
[HttpPost]
[EnableCors]