Implementation to have a favorite DZ by user.
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Domain;
|
||||
using skydiveLogs_api.DomainService.Repositories;
|
||||
using skydiveLogs_api.Infrastructure.Interfaces;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Infrastructure
|
||||
{
|
||||
public class FavoriteDropZoneRepository : IFavoriteDropZoneRepository
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public int Add(FavoriteDropZone favoriteToAdd)
|
||||
{
|
||||
int result;
|
||||
|
||||
try
|
||||
{
|
||||
var tmp = _col.Insert(favoriteToAdd);
|
||||
result = tmp.AsInt32;
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<FavoriteDropZone> GetAll(User user)
|
||||
{
|
||||
return _col.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public FavoriteDropZone GetById(int id)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Update(FavoriteDropZone updated)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public IEnumerable<FavoriteDropZone> GetAll()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<FavoriteDropZone> _col;
|
||||
}
|
||||
}
|
||||
@@ -24,5 +24,7 @@ namespace skydiveLogs_api.Infrastructure.Interfaces
|
||||
ILiteCollection<User> CollOfUser { get; }
|
||||
|
||||
ILiteCollection<UserImage> CollOfImage { get; }
|
||||
|
||||
ILiteCollection<FavoriteDropZone> CollOfFavoriteDropZone { get; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace skydiveLogs_api.Infrastructure
|
||||
.Include(x => x.DropZone)
|
||||
.Include(x => x.Gear)
|
||||
.Include(x => x.JumpType)
|
||||
.Include(x => x.User)
|
||||
//.Include(x => x.User)
|
||||
.Query()
|
||||
.Where(j => j.User.Id == user.Id)
|
||||
.ToList();
|
||||
|
||||
@@ -21,6 +21,9 @@ namespace skydiveLogs_api.Infrastructure
|
||||
BsonMapper.Global.Entity<UserImage>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<Gear>().DbRef(x => x.User, "User");
|
||||
|
||||
BsonMapper.Global.Entity<FavoriteDropZone>().DbRef(x => x.User, "User");
|
||||
BsonMapper.Global.Entity<FavoriteDropZone>().DbRef(x => x.DropZone, "DropZone");
|
||||
}
|
||||
|
||||
public ILiteCollection<T> GetCollection<T>()
|
||||
@@ -48,5 +51,7 @@ namespace skydiveLogs_api.Infrastructure
|
||||
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
|
||||
|
||||
public ILiteCollection<UserImage> CollOfImage => _db.GetCollection<UserImage>();
|
||||
|
||||
public ILiteCollection<FavoriteDropZone> CollOfFavoriteDropZone => _db.GetCollection<FavoriteDropZone>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user