Add a link betweend a gear to the connected user.
This commit is contained in:
@@ -15,8 +15,10 @@ namespace skydiveLogs_api.Business
|
|||||||
_gearRepository = gearRepository;
|
_gearRepository = gearRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddNewGear(Gear newGear)
|
public void AddNewGear(Gear newGear,
|
||||||
|
User connectedUser)
|
||||||
{
|
{
|
||||||
|
newGear.User = connectedUser;
|
||||||
_gearRepository.Add(newGear);
|
_gearRepository.Add(newGear);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,9 +32,9 @@ namespace skydiveLogs_api.Business
|
|||||||
return _gearRepository.GetById(id);
|
return _gearRepository.GetById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<Gear> GetAllGears()
|
public IEnumerable<Gear> GetAllGears(User connectedUser)
|
||||||
{
|
{
|
||||||
return _gearRepository.GetAll();
|
return _gearRepository.GetAll(connectedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateGear(int id, Gear Gear)
|
public void UpdateGear(int id, Gear Gear)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace skydiveLogs_api.Business.Interface
|
|||||||
{
|
{
|
||||||
public interface IGearService
|
public interface IGearService
|
||||||
{
|
{
|
||||||
IEnumerable<Gear> GetAllGears();
|
IEnumerable<Gear> GetAllGears(User connectedUser);
|
||||||
|
|
||||||
Gear GetGearById(int id);
|
Gear GetGearById(int id);
|
||||||
|
|
||||||
@@ -15,6 +15,6 @@ namespace skydiveLogs_api.Business.Interface
|
|||||||
|
|
||||||
void UpdateGear(int id, Gear gear);
|
void UpdateGear(int id, Gear gear);
|
||||||
|
|
||||||
void AddNewGear(Gear gear);
|
void AddNewGear(Gear gear, User connectedUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,15 @@ namespace skydiveLogs_api.Data
|
|||||||
|
|
||||||
public IEnumerable<Gear> GetAll()
|
public IEnumerable<Gear> GetAll()
|
||||||
{
|
{
|
||||||
return _col.FindAll().ToList();
|
throw new System.NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Gear> GetAll(User connectedUser)
|
||||||
|
{
|
||||||
|
return _col.Include(x => x.User)
|
||||||
|
.Query()
|
||||||
|
.Where(j => j.User.Id == user.Id)
|
||||||
|
ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Gear GetById(int id)
|
public Gear GetById(int id)
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
using skydiveLogs_api.Model;
|
using skydiveLogs_api.Model;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace skydiveLogs_api.Data.Interface
|
namespace skydiveLogs_api.Data.Interface
|
||||||
{
|
{
|
||||||
public interface IGearRepository : IRepository<Gear>
|
public interface IGearRepository : IRepository<Gear>
|
||||||
{
|
{
|
||||||
|
IEnumerable<Gear> GetAll(User connectedUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,5 @@ namespace skydiveLogs_api.Data.Interface
|
|||||||
public interface IJumpRepository : IRepository<Jump>
|
public interface IJumpRepository : IRepository<Jump>
|
||||||
{
|
{
|
||||||
IEnumerable<Jump> GetAll(User user);
|
IEnumerable<Jump> GetAll(User user);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ namespace skydiveLogs_api.Data
|
|||||||
public LiteDbProvider(string connectionString)
|
public LiteDbProvider(string connectionString)
|
||||||
{
|
{
|
||||||
_db = new LiteDatabase(connectionString);
|
_db = new LiteDatabase(connectionString);
|
||||||
|
|
||||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.JumpType, "JumpType");
|
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.Aircraft, "Aircraft");
|
||||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
|
BsonMapper.Global.Entity<Jump>().DbRef(x => x.DropZone, "DropZone");
|
||||||
@@ -17,6 +18,8 @@ namespace skydiveLogs_api.Data
|
|||||||
BsonMapper.Global.Entity<Jump>().DbRef(x => x.User, "User");
|
BsonMapper.Global.Entity<Jump>().DbRef(x => x.User, "User");
|
||||||
|
|
||||||
BsonMapper.Global.Entity<UserImage>().DbRef(x => x.User, "User");
|
BsonMapper.Global.Entity<UserImage>().DbRef(x => x.User, "User");
|
||||||
|
|
||||||
|
BsonMapper.Global.Entity<Gear>().DbRef(x => x.User, "User");
|
||||||
}
|
}
|
||||||
|
|
||||||
public ILiteCollection<T> GetCollection<T>()
|
public ILiteCollection<T> GetCollection<T>()
|
||||||
|
|||||||
@@ -17,5 +17,7 @@
|
|||||||
public string MainCanopy { get; set; }
|
public string MainCanopy { get; set; }
|
||||||
|
|
||||||
public string ReserveCanopy { get; set; }
|
public string ReserveCanopy { get; set; }
|
||||||
|
|
||||||
|
public User User { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
[EnableCors]
|
[EnableCors]
|
||||||
public IEnumerable<GearResp> Get()
|
public IEnumerable<GearResp> Get()
|
||||||
{
|
{
|
||||||
var result = _gearService.GetAllGears();
|
var result = _gearService.GetAllGears(ConnectedUser);
|
||||||
return _mapper.Map<IEnumerable<GearResp>>(result);
|
return _mapper.Map<IEnumerable<GearResp>>(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ namespace skydiveLogs_api.Controllers
|
|||||||
[EnableCors]
|
[EnableCors]
|
||||||
public void Post([FromBody] GearReq value)
|
public void Post([FromBody] GearReq value)
|
||||||
{
|
{
|
||||||
_gearService.AddNewGear(_mapper.Map<Gear>(value));
|
_gearService.AddNewGear(_mapper.Map<Gear>(value), ConnectedUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PUT: api/Gear/5
|
// PUT: api/Gear/5
|
||||||
|
|||||||
Reference in New Issue
Block a user