diff --git a/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs b/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs index 3cba1c9..415f0ae 100644 --- a/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IAircraftService.cs @@ -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 diff --git a/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs b/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs index 6042116..37cf401 100644 --- a/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IDropZoneService.cs @@ -1,6 +1,8 @@ using System.Collections.Generic; + using skydiveLogs_api.Model; + namespace skydiveLogs_api.Business.Interface { public interface IDropZoneService diff --git a/Back/skydiveLogs-api.Business/Interface/IGearService.cs b/Back/skydiveLogs-api.Business/Interface/IGearService.cs index 2f6f951..d88c6cc 100644 --- a/Back/skydiveLogs-api.Business/Interface/IGearService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IGearService.cs @@ -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); } } diff --git a/Back/skydiveLogs-api.Business/Interface/IJumpService.cs b/Back/skydiveLogs-api.Business/Interface/IJumpService.cs index dae85d7..caf8d39 100644 --- a/Back/skydiveLogs-api.Business/Interface/IJumpService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IJumpService.cs @@ -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 diff --git a/Back/skydiveLogs-api.Business/Interface/IJumpTypeService.cs b/Back/skydiveLogs-api.Business/Interface/IJumpTypeService.cs index 17eb098..e41bd44 100644 --- a/Back/skydiveLogs-api.Business/Interface/IJumpTypeService.cs +++ b/Back/skydiveLogs-api.Business/Interface/IJumpTypeService.cs @@ -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 { diff --git a/Back/skydiveLogs-api.Business/Interface/IUserService.cs b/Back/skydiveLogs-api.Business/Interface/IUserService.cs new file mode 100644 index 0000000..48cbe1a --- /dev/null +++ b/Back/skydiveLogs-api.Business/Interface/IUserService.cs @@ -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); + } +} diff --git a/Back/skydiveLogs-api.Business/UserService.cs b/Back/skydiveLogs-api.Business/UserService.cs new file mode 100644 index 0000000..5336c4f --- /dev/null +++ b/Back/skydiveLogs-api.Business/UserService.cs @@ -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; + } +} diff --git a/Back/skydiveLogs-api.Data/Interface/IDataProvider.cs b/Back/skydiveLogs-api.Data/Interface/IDataProvider.cs index 14208c8..2b33ef1 100644 --- a/Back/skydiveLogs-api.Data/Interface/IDataProvider.cs +++ b/Back/skydiveLogs-api.Data/Interface/IDataProvider.cs @@ -20,5 +20,7 @@ namespace skydiveLogs_api.Data.Interface ILiteCollection CollOfJumpType { get; } ILiteCollection CollOfJump { get; } + + ILiteCollection CollOfUser { get; } } } diff --git a/Back/skydiveLogs-api.Data/Interface/IUserRepository.cs b/Back/skydiveLogs-api.Data/Interface/IUserRepository.cs new file mode 100644 index 0000000..2289d6e --- /dev/null +++ b/Back/skydiveLogs-api.Data/Interface/IUserRepository.cs @@ -0,0 +1,10 @@ +using skydiveLogs_api.Model; + + +namespace skydiveLogs_api.Data.Interface +{ + public interface IUserRepository : IRepository + { + User GetByLogin(string login, string password); + } +} diff --git a/Back/skydiveLogs-api.Data/LiteDbProvider.cs b/Back/skydiveLogs-api.Data/LiteDbProvider.cs index 0a6f11d..89fff6a 100644 --- a/Back/skydiveLogs-api.Data/LiteDbProvider.cs +++ b/Back/skydiveLogs-api.Data/LiteDbProvider.cs @@ -37,5 +37,7 @@ namespace skydiveLogs_api.Data public ILiteCollection CollOfJumpType => _db.GetCollection(); public ILiteCollection CollOfJump => _db.GetCollection(); + + public ILiteCollection CollOfUser => _db.GetCollection(); } } diff --git a/Back/skydiveLogs-api.Data/UserRepository.cs b/Back/skydiveLogs-api.Data/UserRepository.cs new file mode 100644 index 0000000..18c388c --- /dev/null +++ b/Back/skydiveLogs-api.Data/UserRepository.cs @@ -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 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 _col; + } +} diff --git a/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj b/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj index 079557f..e67d3fb 100644 --- a/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj +++ b/Back/skydiveLogs-api.Data/skydiveLogs-api.Data.csproj @@ -6,7 +6,7 @@ - + diff --git a/Back/skydiveLogs-api.Model/User.cs b/Back/skydiveLogs-api.Model/User.cs new file mode 100644 index 0000000..a43a392 --- /dev/null +++ b/Back/skydiveLogs-api.Model/User.cs @@ -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; } + } +} diff --git a/Back/skydiveLogs-api/Controllers/UserController.cs b/Back/skydiveLogs-api/Controllers/UserController.cs new file mode 100644 index 0000000..96b9134 --- /dev/null +++ b/Back/skydiveLogs-api/Controllers/UserController.cs @@ -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(result); + } + + // POST: api/User + [HttpPost] + [EnableCors] + public void Post([FromBody] UserReq value) + { + _userService.AddNewUser(_mapper.Map(value)); + } + + private readonly IUserService _userService; + private readonly IMapper _mapper; + } +} diff --git a/Back/skydiveLogs-api/Data/JumpsDb-log.db b/Back/skydiveLogs-api/Data/JumpsDb-log.db deleted file mode 100644 index c473c06..0000000 Binary files a/Back/skydiveLogs-api/Data/JumpsDb-log.db and /dev/null differ diff --git a/Back/skydiveLogs-api/Data/JumpsDb.db b/Back/skydiveLogs-api/Data/JumpsDb.db index ce2b393..ee60975 100644 Binary files a/Back/skydiveLogs-api/Data/JumpsDb.db and b/Back/skydiveLogs-api/Data/JumpsDb.db differ diff --git a/Back/skydiveLogs-api/DataContract/AircraftResp.cs b/Back/skydiveLogs-api/DataContract/AircraftResp.cs index 5f8f86e..b5c6261 100644 --- a/Back/skydiveLogs-api/DataContract/AircraftResp.cs +++ b/Back/skydiveLogs-api/DataContract/AircraftResp.cs @@ -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 { diff --git a/Back/skydiveLogs-api/DataContract/JumpReq.cs b/Back/skydiveLogs-api/DataContract/JumpReq.cs index 2bc2da0..c50216e 100644 --- a/Back/skydiveLogs-api/DataContract/JumpReq.cs +++ b/Back/skydiveLogs-api/DataContract/JumpReq.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace skydiveLogs_api.DataContract { diff --git a/Back/skydiveLogs-api/DataContract/JumpTypeReq.cs b/Back/skydiveLogs-api/DataContract/JumpTypeReq.cs index 3533915..ca702a1 100644 --- a/Back/skydiveLogs-api/DataContract/JumpTypeReq.cs +++ b/Back/skydiveLogs-api/DataContract/JumpTypeReq.cs @@ -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 { diff --git a/Back/skydiveLogs-api/DataContract/JumpTypeResp.cs b/Back/skydiveLogs-api/DataContract/JumpTypeResp.cs index bb8583e..44fe563 100644 --- a/Back/skydiveLogs-api/DataContract/JumpTypeResp.cs +++ b/Back/skydiveLogs-api/DataContract/JumpTypeResp.cs @@ -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 { diff --git a/Back/skydiveLogs-api/DataContract/UserReq.cs b/Back/skydiveLogs-api/DataContract/UserReq.cs new file mode 100644 index 0000000..e1971dc --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/UserReq.cs @@ -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; } + } +} diff --git a/Back/skydiveLogs-api/DataContract/UserResp.cs b/Back/skydiveLogs-api/DataContract/UserResp.cs new file mode 100644 index 0000000..87f6b35 --- /dev/null +++ b/Back/skydiveLogs-api/DataContract/UserResp.cs @@ -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; } + } +} diff --git a/Back/skydiveLogs-api/Mapper/ModelProfile.cs b/Back/skydiveLogs-api/Mapper/ModelProfile.cs index 68f60f2..0f4277e 100644 --- a/Back/skydiveLogs-api/Mapper/ModelProfile.cs +++ b/Back/skydiveLogs-api/Mapper/ModelProfile.cs @@ -11,6 +11,7 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + CreateMap(); CreateMap(); CreateMap(); @@ -18,6 +19,7 @@ namespace skydiveLogs_api.Mapper CreateMap(); CreateMap(); CreateMap(); + CreateMap(); CreateMap(); }