diff --git a/Back/skydiveLogs-api.DomainBusiness/CacheService.cs b/Back/skydiveLogs-api.DomainBusiness/CacheService.cs index 2e76594..01edbfa 100644 --- a/Back/skydiveLogs-api.DomainBusiness/CacheService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/CacheService.cs @@ -7,24 +7,39 @@ namespace skydiveLogs_api.DomainBusiness { public class CacheService : ICacheService { + #region Public Constructors + + public CacheService() + { + _memoryCache = MemoryCache.Default; + } + + #endregion Public Constructors + + #region Private Fields + + private readonly MemoryCache _memoryCache; + + #endregion Private Fields + #region Public Methods public bool Contains(CacheType type, int userId = 0) { var key = GetKey(userId, type); - return MemoryCache.Default[key.ToString()] != null; + return _memoryCache.Contains(key.ToString()); } public void Delete(CacheType type, int userId = 0) { var key = GetKey(userId, type); - MemoryCache.Default.Remove(key.ToString()); + _memoryCache.Remove(key.ToString()); } public T Get(CacheType type, int userId = 0) { var key = GetKey(userId, type); - return (T)MemoryCache.Default[key.ToString()]; + return (T)_memoryCache.Get(key.ToString()); } public void Put(CacheType type, object value, int duration, int userId = 0) @@ -38,7 +53,7 @@ namespace skydiveLogs_api.DomainBusiness AbsoluteExpiration = DateTime.Now.AddMilliseconds(duration) }; - MemoryCache.Default.Set(key.ToString(), value, policy); + _memoryCache.Set(key.ToString(), value, policy); } private string GetKey(int userId, CacheType type) diff --git a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs index 1155ea8..75ee2c9 100644 --- a/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/Interfaces/IJumpService.cs @@ -19,6 +19,10 @@ namespace skydiveLogs_api.DomainBusiness.Interfaces Jump GetJumpById(int id); + int GetJumpCount(); + + IEnumerable GetJumpsByIndexes(int beginIndex, int endIndex); + void UpdateJump(int id, Jump jump); #endregion Public Methods diff --git a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs index ca2ce4e..c96e120 100644 --- a/Back/skydiveLogs-api.DomainBusiness/JumpService.cs +++ b/Back/skydiveLogs-api.DomainBusiness/JumpService.cs @@ -63,6 +63,16 @@ namespace skydiveLogs_api.DomainBusiness return _jumpRepository.GetById(id); } + public int GetJumpCount() + { + return _jumpRepository.GetCount(_identityService.ConnectedUser); + } + + public IEnumerable GetJumpsByIndexes(int beginIndex, int endIndex) + { + return _jumpRepository.GetBetweenIndex(_identityService.ConnectedUser, beginIndex, endIndex); + } + public void UpdateJump(int id, Jump updatedJump) { var myJump = GetJumpById(id); diff --git a/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs b/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs index 68950b5..3ad26da 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IJumpRepository.cs @@ -11,6 +11,10 @@ namespace skydiveLogs_api.DomainService.Repositories IEnumerable GetAll(User user); + IEnumerable GetBetweenIndex(User user, int beginIndex, int endIndex); + + int GetCount(User user); + #endregion Public Methods } } \ 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 cfc532d..450d9cb 100644 --- a/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs +++ b/Back/skydiveLogs-api.DomainService/Repositories/IRepository.cs @@ -12,6 +12,8 @@ namespace skydiveLogs_api.DomainService.Repositories T GetById(int id); + int GetCount(); + bool Update(T updated); #endregion Public Methods diff --git a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs index 6cee341..ab54476 100644 --- a/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/AircraftRepository.cs @@ -48,6 +48,11 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(Aircraft aircraft) { return _col.Update(aircraft); diff --git a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs index d188a0b..bb38394 100644 --- a/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/DropZoneRepository.cs @@ -48,6 +48,11 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(DropZone updatedDz) { return _col.Update(updatedDz); diff --git a/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs b/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs index 8fe24cc..12d1d13 100644 --- a/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/FavoriteDropZoneRepository.cs @@ -59,6 +59,11 @@ namespace skydiveLogs_api.Infrastructure throw new System.NotImplementedException(); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(FavoriteDropZone updated) { throw new System.NotImplementedException(); diff --git a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs index faae95a..9ede950 100644 --- a/Back/skydiveLogs-api.Infrastructure/GearRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/GearRepository.cs @@ -55,6 +55,11 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(Gear updatedGear) { return _col.Update(updatedGear); diff --git a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs index dda946e..acdc3f9 100644 --- a/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/JumpRepository.cs @@ -56,11 +56,35 @@ namespace skydiveLogs_api.Infrastructure throw new System.NotImplementedException(); } + public IEnumerable GetBetweenIndex(User user, int beginIndex, int endIndex) + { + return _col.Include(x => x.Aircraft) + .Include(x => x.DropZone) + .Include(x => x.Gear) + .Include(x => x.JumpType) + .Query() + .OrderByDescending(j => j.JumpDate) + .Where(j => j.User.Id == user.Id) + .Limit(endIndex - beginIndex) + .Offset(beginIndex) + .ToList(); + } + public Jump GetById(int id) { return _col.FindById(new BsonValue(id)); } + public int GetCount(User user) + { + return _col.Count(j => j.User.Id == user.Id); + } + + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(Jump updatedJump) { return _col.Update(updatedJump); diff --git a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs index 062763b..c113fb9 100644 --- a/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/JumpTypeRepository.cs @@ -48,6 +48,11 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(JumpType updatedJumpType) { return _col.Update(updatedJumpType); diff --git a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs index e842a35..5e51941 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserImageRepository.cs @@ -55,6 +55,11 @@ namespace skydiveLogs_api.Infrastructure return _col.FindById(new BsonValue(id)); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(UserImage image) { return _col.Update(image); diff --git a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs index 28235c4..e1a4e7f 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserRepository.cs @@ -53,6 +53,11 @@ namespace skydiveLogs_api.Infrastructure return _col.FindOne(u => u.Login == login && u.Password == password); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(User updated) { throw new NotImplementedException(); diff --git a/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs b/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs index e6dff83..4bfbc7c 100644 --- a/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs +++ b/Back/skydiveLogs-api.Infrastructure/UserStatsRepository.cs @@ -55,6 +55,11 @@ namespace skydiveLogs_api.Infrastructure throw new System.NotImplementedException(); } + public int GetCount() + { + throw new System.NotImplementedException(); + } + public bool Update(UserStats stats) { //col.UpdateMany(x => new Customer { Name diff --git a/Back/skydiveLogs-api/Controllers/JumpController.cs b/Back/skydiveLogs-api/Controllers/JumpController.cs index 883eb1e..f8caef3 100644 --- a/Back/skydiveLogs-api/Controllers/JumpController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpController.cs @@ -5,6 +5,7 @@ using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; using System.Collections.Generic; +using System.Linq; namespace skydiveLogs_api.Controllers { @@ -34,11 +35,32 @@ namespace skydiveLogs_api.Controllers // GET: api/Jump [HttpGet] [EnableCors] - public IEnumerable Get() + public JumpListResp Get() { - var result = _jumpService.GetAllJumps(); + var tmp = _jumpService.GetAllJumps(); + var result = new JumpListResp + { + Rows = _mapper.Map>(tmp), + Count = tmp.Count() + }; - return _mapper.Map>(result); + return result; + } + + // GET: api/Jump/5/10 + [HttpGet("{beginJumpIndex}/{endJumpIndex}")] + [EnableCors] + public JumpListResp Get(int beginJumpIndex, int endJumpIndex) + { + var totalJumps = _jumpService.GetJumpCount(); + var tmp = _jumpService.GetJumpsByIndexes(beginJumpIndex, endJumpIndex); + var result = new JumpListResp + { + Rows = _mapper.Map>(tmp), + Count = totalJumps + }; + + return result; } // GET: api/Jump/5 diff --git a/Back/skydiveLogs-api/DataContract/JumpListResp.cs b/Back/skydiveLogs-api/DataContract/JumpListResp.cs new file mode 100644 index 0000000..e8795d1 --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/JumpListResp.cs @@ -0,0 +1,14 @@ +using System.Collections.Generic; + +namespace skydiveLogs_api.DataContract +{ + public class JumpListResp + { + #region Public Properties + + public int Count { get; set; } + public IEnumerable Rows { get; set; } + + #endregion Public Properties + } +} \ No newline at end of file