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,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,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<Jump>().DbRef(x => x.JumpType, "JumpType");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.Aircraft, "Aircraft");
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
@@ -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
}
}
}