Add a controler for "User" (add and authenticate)
This commit is contained in:
@@ -20,5 +20,7 @@ namespace skydiveLogs_api.Data.Interface
|
||||
ILiteCollection<JumpType> CollOfJumpType { get; }
|
||||
|
||||
ILiteCollection<Jump> CollOfJump { get; }
|
||||
|
||||
ILiteCollection<User> CollOfUser { get; }
|
||||
}
|
||||
}
|
||||
|
||||
10
Back/skydiveLogs-api.Data/Interface/IUserRepository.cs
Normal file
10
Back/skydiveLogs-api.Data/Interface/IUserRepository.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data.Interface
|
||||
{
|
||||
public interface IUserRepository : IRepository<User>
|
||||
{
|
||||
User GetByLogin(string login, string password);
|
||||
}
|
||||
}
|
||||
@@ -37,5 +37,7 @@ namespace skydiveLogs_api.Data
|
||||
public ILiteCollection<JumpType> CollOfJumpType => _db.GetCollection<JumpType>();
|
||||
|
||||
public ILiteCollection<Jump> CollOfJump => _db.GetCollection<Jump>();
|
||||
|
||||
public ILiteCollection<User> CollOfUser => _db.GetCollection<User>();
|
||||
}
|
||||
}
|
||||
|
||||
61
Back/skydiveLogs-api.Data/UserRepository.cs
Normal file
61
Back/skydiveLogs-api.Data/UserRepository.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
using LiteDB;
|
||||
|
||||
using skydiveLogs_api.Data.Interface;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Data
|
||||
{
|
||||
public class UserRepository : IUserRepository
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
public bool Add(User newUser)
|
||||
{
|
||||
var result = true;
|
||||
|
||||
try
|
||||
{
|
||||
_col.Insert(newUser);
|
||||
}
|
||||
catch
|
||||
{
|
||||
result = false;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public IEnumerable<User> GetAll()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public User GetById(int id)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public bool Update(User updated)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
private readonly IDataProvider _dataProvider;
|
||||
|
||||
private readonly ILiteCollection<User> _col;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="LiteDB" Version="5.0.1" />
|
||||
<PackageReference Include="LiteDB" Version="5.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user