Update the repository pattern
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class AircraftService : IAircraftService
|
||||
@@ -26,12 +27,12 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public Aircraft GetAircraftById(int id)
|
||||
{
|
||||
return _aircraftRepository.GetAircraftById(id);
|
||||
return _aircraftRepository.GetById(id);
|
||||
}
|
||||
|
||||
public IEnumerable<Aircraft> GetAllAircrafts()
|
||||
{
|
||||
return _aircraftRepository.GetAllAircrafts();
|
||||
return _aircraftRepository.GetAll();
|
||||
}
|
||||
|
||||
public void UpdateAircraft(int id, Aircraft aircraft)
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<DropZone> GetAllDzs()
|
||||
{
|
||||
return _dropZoneRepository.GetAllDzs();
|
||||
return _dropZoneRepository.GetAll();
|
||||
}
|
||||
|
||||
public DropZone GetDzById(int id)
|
||||
{
|
||||
return _dropZoneRepository.GetDzById(id);
|
||||
return _dropZoneRepository.GetById(id);
|
||||
}
|
||||
|
||||
public void UpdateDz(int id, DropZone dropZone)
|
||||
|
||||
@@ -27,12 +27,12 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<Jump> GetAllJumps()
|
||||
{
|
||||
return _jumpRepository.GetAllJumps();
|
||||
return _jumpRepository.GetAll();
|
||||
}
|
||||
|
||||
public Jump GetJumpById(int id)
|
||||
{
|
||||
return _jumpRepository.GetJumpById(id);
|
||||
return _jumpRepository.GetById(id);
|
||||
}
|
||||
|
||||
public void UpdateJump(int id, Jump jump)
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business
|
||||
{
|
||||
public class JumpTypeService : IJumpTypeService
|
||||
@@ -25,12 +27,12 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<JumpType> GetAllJumpTypes()
|
||||
{
|
||||
return _jumpTypeRepository.GetAllJumpTypes();
|
||||
return _jumpTypeRepository.GetAll();
|
||||
}
|
||||
|
||||
public JumpType GetJumpTypeById(int id)
|
||||
{
|
||||
return _jumpTypeRepository.GetJumpTypeById(id);
|
||||
return _jumpTypeRepository.GetById(id);
|
||||
}
|
||||
|
||||
public void UpdateJumpType(int id, JumpType value)
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByAircraft()
|
||||
{
|
||||
var allJumps = _jumpRepository.GetAllJumps();
|
||||
var allJumps = _jumpRepository.GetAll();
|
||||
|
||||
return allJumps.GroupBy(j => j.AircraftId,
|
||||
j => j,
|
||||
@@ -31,7 +31,7 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByDz()
|
||||
{
|
||||
var allJumps = _jumpRepository.GetAllJumps();
|
||||
var allJumps = _jumpRepository.GetAll();
|
||||
|
||||
return allJumps.GroupBy(j => j.DropZoneId,
|
||||
j => j,
|
||||
@@ -45,7 +45,7 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByJumpType()
|
||||
{
|
||||
var allJumps = _jumpRepository.GetAllJumps();
|
||||
var allJumps = _jumpRepository.GetAll();
|
||||
|
||||
return allJumps.GroupBy(j => j.JumpTypeId,
|
||||
j => j,
|
||||
@@ -59,7 +59,7 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByRig()
|
||||
{
|
||||
var allJumps = _jumpRepository.GetAllJumps();
|
||||
var allJumps = _jumpRepository.GetAll();
|
||||
|
||||
return allJumps.GroupBy(j => j.GearId,
|
||||
j => j,
|
||||
@@ -73,7 +73,7 @@ namespace skydiveLogs_api.Business
|
||||
|
||||
public IEnumerable<Statistic> GetStatsByYear()
|
||||
{
|
||||
var allJumps = _jumpRepository.GetAllJumps();
|
||||
var allJumps = _jumpRepository.GetAll();
|
||||
|
||||
return allJumps.GroupBy(j => j.JumpDate.Year,
|
||||
j => j,
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class AircraftRepository : IAircraftRepository
|
||||
{
|
||||
public IEnumerable<Aircraft> GetAllAircrafts()
|
||||
public IEnumerable<Aircraft> GetAll()
|
||||
{
|
||||
IEnumerable<Aircraft> result = new List<Aircraft>();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace skydiveLogs_api.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public Aircraft GetAircraftById(int id)
|
||||
public Aircraft GetById(int id)
|
||||
{
|
||||
Aircraft result;
|
||||
|
||||
|
||||
@@ -11,21 +11,18 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class DropZoneRepository : IDropZoneRepository
|
||||
{
|
||||
public IEnumerable<DropZone> GetAllDzs()
|
||||
public DropZoneRepository(IDataProvider dataProvider)
|
||||
{
|
||||
IEnumerable<DropZone> result = new List<DropZone>();
|
||||
|
||||
using (var db = new LiteDatabase(@".\Data\MyData.db"))
|
||||
{
|
||||
var col = db.GetCollection<DropZone>("DropZone");
|
||||
|
||||
result = col.FindAll().ToList();
|
||||
_dataProvider = dataProvider;
|
||||
_col = _dataProvider.GetCollection<DropZone>();
|
||||
}
|
||||
|
||||
return result;
|
||||
public IEnumerable<DropZone> GetAll()
|
||||
{
|
||||
return _col.FindAll().ToList();
|
||||
}
|
||||
|
||||
public DropZone GetDzById(int id)
|
||||
public DropZone GetById(int id)
|
||||
{
|
||||
DropZone result;
|
||||
|
||||
@@ -38,5 +35,9 @@ namespace skydiveLogs_api.Data
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly LiteCollection<DropZone> _col;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class GearRepository : IGearRepository
|
||||
{
|
||||
public IEnumerable<Gear> GetAllGears()
|
||||
public IEnumerable<Gear> GetAll()
|
||||
{
|
||||
IEnumerable<Gear> result = new List<Gear>();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace skydiveLogs_api.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public Gear GetGearById(int id)
|
||||
public Gear GetById(int id)
|
||||
{
|
||||
Gear result;
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IAircraftRepository
|
||||
public interface IAircraftRepository : IRepository<Aircraft>
|
||||
{
|
||||
IEnumerable<Aircraft> GetAllAircrafts();
|
||||
Aircraft GetAircraftById(int id);
|
||||
}
|
||||
}
|
||||
|
||||
12
Back/skydiveLogs-api.Data/Interface/IDataProvider.cs
Normal file
12
Back/skydiveLogs-api.Data/Interface/IDataProvider.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using LiteDB;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IDataProvider
|
||||
{
|
||||
LiteCollection<T> GetCollection<T>();
|
||||
|
||||
void Close();
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IDropZoneRepository
|
||||
public interface IDropZoneRepository : IRepository<DropZone>
|
||||
{
|
||||
IEnumerable<DropZone> GetAllDzs();
|
||||
|
||||
DropZone GetDzById(int id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IGearRepository
|
||||
public interface IGearRepository : IRepository<Gear>
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IJumpRepository
|
||||
public interface IJumpRepository : IRepository<Jump>
|
||||
{
|
||||
IEnumerable<Jump> GetAllJumps();
|
||||
|
||||
Jump GetJumpById(int id);
|
||||
|
||||
bool AddJump(Jump newJump);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using skydiveLogs_api.Model;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IJumpTypeRepository
|
||||
public interface IJumpTypeRepository : IRepository<JumpType>
|
||||
{
|
||||
IEnumerable<JumpType> GetAllJumpTypes();
|
||||
JumpType GetJumpTypeById(int id);
|
||||
}
|
||||
}
|
||||
|
||||
12
Back/skydiveLogs-api.Data/Interface/IRepository.cs
Normal file
12
Back/skydiveLogs-api.Data/Interface/IRepository.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IRepository<T>
|
||||
{
|
||||
IEnumerable<T> GetAll();
|
||||
|
||||
T GetById(int id);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class JumpRepository : IJumpRepository
|
||||
{
|
||||
public IEnumerable<Jump> GetAllJumps()
|
||||
public IEnumerable<Jump> GetAll()
|
||||
{
|
||||
IEnumerable<Jump> result = new List<Jump>();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace skydiveLogs_api.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public Jump GetJumpById(int id)
|
||||
public Jump GetById(int id)
|
||||
{
|
||||
Jump result;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class JumpTypeRepository : IJumpTypeRepository
|
||||
{
|
||||
public IEnumerable<JumpType> GetAllJumpTypes()
|
||||
public IEnumerable<JumpType> GetAll()
|
||||
{
|
||||
IEnumerable<JumpType> result = new List<JumpType>();
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace skydiveLogs_api.Data
|
||||
return result;
|
||||
}
|
||||
|
||||
public JumpType GetJumpTypeById(int id)
|
||||
public JumpType GetById(int id)
|
||||
{
|
||||
JumpType result;
|
||||
|
||||
|
||||
27
Back/skydiveLogs-api.Data/LiteDbProvider.cs
Normal file
27
Back/skydiveLogs-api.Data/LiteDbProvider.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class LiteDbProvider : IDataProvider
|
||||
{
|
||||
public LiteDbProvider(string connectionString)
|
||||
{
|
||||
_db = new LiteDatabase(connectionString);
|
||||
}
|
||||
|
||||
public LiteCollection<T> GetCollection<T>()
|
||||
{
|
||||
return _db.GetCollection<T>();
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
_db.Dispose();
|
||||
}
|
||||
|
||||
private readonly LiteDatabase _db;
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ namespace skydiveLogs_api.Ioc
|
||||
_services.AddScoped<Data.Interface.IJumpRepository, Data.JumpRepository>();
|
||||
_services.AddScoped<Data.Interface.IJumpTypeRepository, Data.JumpTypeRepository>();
|
||||
_services.AddScoped<Data.Interface.IGearRepository, Data.GearRepository>();
|
||||
|
||||
_services.AddScoped<Data.Interface.IDataProvider, Data.LiteDbProvider>();
|
||||
}
|
||||
|
||||
private readonly IServiceCollection _services;
|
||||
|
||||
Reference in New Issue
Block a user