Add a controler for "User" (add and authenticate)
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IAircraftService
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IDropZoneService
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IGearService
|
||||
@@ -11,8 +13,8 @@ namespace skydiveLogs_api.Business.Interface
|
||||
|
||||
void DeleteGearById(int id);
|
||||
|
||||
void UpdateGear(int id, Gear Gear);
|
||||
void UpdateGear(int id, Gear gear);
|
||||
|
||||
void AddNewGear(Gear Gear);
|
||||
void AddNewGear(Gear gear);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IJumpService
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using skydiveLogs_api.Model;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
|
||||
11
Back/skydiveLogs-api.Business/Interface/IUserService.cs
Normal file
11
Back/skydiveLogs-api.Business/Interface/IUserService.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
namespace skydiveLogs_api.Business.Interface
|
||||
{
|
||||
public interface IUserService
|
||||
{
|
||||
User GetByLogin(string login, string password);
|
||||
|
||||
void AddNewUser(User user);
|
||||
}
|
||||
}
|
||||
32
Back/skydiveLogs-api.Business/UserService.cs
Normal file
32
Back/skydiveLogs-api.Business/UserService.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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 UserService : IUserService
|
||||
{
|
||||
public UserService(IUserRepository userRepository)
|
||||
{
|
||||
_userRepository = userRepository;
|
||||
}
|
||||
|
||||
public User GetByLogin(string login, string password)
|
||||
{
|
||||
var tmp = _userRepository.GetByLogin(login, password);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void AddNewUser(User newUser)
|
||||
{
|
||||
_userRepository.Add(newUser);
|
||||
}
|
||||
|
||||
private readonly IUserRepository _userRepository;
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
|
||||
15
Back/skydiveLogs-api.Model/User.cs
Normal file
15
Back/skydiveLogs-api.Model/User.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
namespace skydiveLogs_api.Model
|
||||
{
|
||||
public class User
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Login { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
44
Back/skydiveLogs-api/Controllers/UserController.cs
Normal file
44
Back/skydiveLogs-api/Controllers/UserController.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Cors;
|
||||
|
||||
using AutoMapper;
|
||||
|
||||
using skydiveLogs_api.Business.Interface;
|
||||
using skydiveLogs_api.DataContract;
|
||||
using skydiveLogs_api.Model;
|
||||
|
||||
|
||||
namespace skydiveLogs_api.Controllers
|
||||
{
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
public class UserController : ControllerBase
|
||||
{
|
||||
public UserController(IUserService userService,
|
||||
IMapper mapper)
|
||||
{
|
||||
_userService = userService;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
// POST: api/User
|
||||
[HttpPost]
|
||||
[EnableCors]
|
||||
public UserResp Authenticate([FromBody] string login, [FromBody] string password)
|
||||
{
|
||||
var result = _userService.GetByLogin(login, password);
|
||||
return _mapper.Map<UserResp>(result);
|
||||
}
|
||||
|
||||
// POST: api/User
|
||||
[HttpPost]
|
||||
[EnableCors]
|
||||
public void Post([FromBody] UserReq value)
|
||||
{
|
||||
_userService.AddNewUser(_mapper.Map<User>(value));
|
||||
}
|
||||
|
||||
private readonly IUserService _userService;
|
||||
private readonly IMapper _mapper;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skydiveLogs_api.DataContract
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class AircraftResp
|
||||
{
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skydiveLogs_api.DataContract
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class JumpTypeReq
|
||||
{
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace skydiveLogs_api.DataContract
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class JumpTypeResp
|
||||
{
|
||||
|
||||
13
Back/skydiveLogs-api/DataContract/UserReq.cs
Normal file
13
Back/skydiveLogs-api/DataContract/UserReq.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class UserReq
|
||||
{
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Login { get; set; }
|
||||
|
||||
public string Password { get; set; }
|
||||
}
|
||||
}
|
||||
13
Back/skydiveLogs-api/DataContract/UserResp.cs
Normal file
13
Back/skydiveLogs-api/DataContract/UserResp.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace skydiveLogs_api.DataContract
|
||||
{
|
||||
public class UserResp
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string FirstName { get; set; }
|
||||
|
||||
public string LastName { get; set; }
|
||||
|
||||
public string Login { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<DataContract.AircraftReq, Model.Aircraft>();
|
||||
CreateMap<DataContract.DropZoneReq, Model.DropZone>();
|
||||
CreateMap<DataContract.GearReq, Model.Gear>();
|
||||
CreateMap<DataContract.UserReq, Model.User>();
|
||||
|
||||
CreateMap<Model.Gear, DataContract.GearResp>();
|
||||
CreateMap<Model.Jump, DataContract.JumpResp>();
|
||||
@@ -18,6 +19,7 @@ namespace skydiveLogs_api.Mapper
|
||||
CreateMap<Model.Aircraft ,DataContract.AircraftResp>();
|
||||
CreateMap<Model.DropZone ,DataContract.DropZoneResp>();
|
||||
CreateMap<Model.Statistic ,DataContract.StatisticResp>();
|
||||
CreateMap<Model.User, DataContract.UserResp>();
|
||||
|
||||
CreateMap<Model.SimpleSummary, DataContract.SimpleSummaryResp>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user