diff --git a/Back/skydiveLogs-api.Ioc/IocService.cs b/Back/skydiveLogs-api.Ioc/IocService.cs index b650673..442f3ae 100644 --- a/Back/skydiveLogs-api.Ioc/IocService.cs +++ b/Back/skydiveLogs-api.Ioc/IocService.cs @@ -6,6 +6,7 @@ using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.DomainService.Repositories; using skydiveLogs_api.Infrastructure; using skydiveLogs_api.Infrastructure.Interfaces; +using System.Security.Claims; namespace skydiveLogs_api.Ioc { @@ -38,7 +39,7 @@ namespace skydiveLogs_api.Ioc _services.AddSingleton(); _services.AddScoped(); - _services.AddScoped(s => s.GetService()?.HttpContext.User); + _services.AddScoped(s => s.GetService()?.HttpContext.User); _services.AddScoped(); _services.AddScoped(); diff --git a/Back/skydiveLogs-api/Controllers/AircraftController.cs b/Back/skydiveLogs-api/Controllers/AircraftController.cs index 583accc..0282bad 100644 --- a/Back/skydiveLogs-api/Controllers/AircraftController.cs +++ b/Back/skydiveLogs-api/Controllers/AircraftController.cs @@ -1,18 +1,17 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using Microsoft.AspNetCore.Cors; - -using AutoMapper; - +using Microsoft.AspNetCore.Mvc; +using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DataContract; - +using System.Collections.Generic; namespace skydiveLogs_api.Controllers { public class AircraftController : Base { + #region Public Constructors + public AircraftController(IAircraftService aircraftService, IMapper mapper) { @@ -20,6 +19,18 @@ namespace skydiveLogs_api.Controllers _mapper = mapper; } + #endregion Public Constructors + + #region Public Methods + + // DELETE: api/ApiWithActions/5 + [HttpDelete("{id}")] + [EnableCors] + public void Delete(int id) + { + _aircraftService.DeleteAircraftById(id); + } + // GET: api/Aircraft [HttpGet] [EnableCors] @@ -54,15 +65,13 @@ namespace skydiveLogs_api.Controllers _aircraftService.UpdateAircraft(id, _mapper.Map(value)); } - // DELETE: api/ApiWithActions/5 - [HttpDelete("{id}")] - [EnableCors] - public void Delete(int id) - { - _aircraftService.DeleteAircraftById(id); - } + #endregion Public Methods + + #region Private Fields private readonly IAircraftService _aircraftService; private readonly IMapper _mapper; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Controllers/Base.cs b/Back/skydiveLogs-api/Controllers/Base.cs index 0909ae9..e0486e8 100644 --- a/Back/skydiveLogs-api/Controllers/Base.cs +++ b/Back/skydiveLogs-api/Controllers/Base.cs @@ -7,23 +7,5 @@ namespace skydiveLogs_api.Controllers [Route("api/[controller]")] [ApiController] [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)] - public class Base : ControllerBase - { - //public User ConnectedUser - //{ - // get - // { - // if (_connectedUser == null) - // { - // _connectedUser = new User(); - // _connectedUser.Login = User.Claims.Single(c => c.Type == ClaimTypes.Name).Value; - // _connectedUser.Id = Convert.ToInt32(User.Claims.Single(c => c.Type == ClaimTypes.UserData).Value); - // } - - // return _connectedUser; - // } - //} - - //private User _connectedUser; - } + public class Base : ControllerBase { } } \ No newline at end of file diff --git a/Back/skydiveLogs-api/Controllers/DropZoneController.cs b/Back/skydiveLogs-api/Controllers/DropZoneController.cs index 36afcd1..d5f2098 100644 --- a/Back/skydiveLogs-api/Controllers/DropZoneController.cs +++ b/Back/skydiveLogs-api/Controllers/DropZoneController.cs @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using Microsoft.AspNetCore.Cors; - -using AutoMapper; - +using Microsoft.AspNetCore.Mvc; +using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DataContract; +using System.Collections.Generic; namespace skydiveLogs_api.Controllers { diff --git a/Back/skydiveLogs-api/Controllers/GearController.cs b/Back/skydiveLogs-api/Controllers/GearController.cs index 4486ff5..c585d5f 100644 --- a/Back/skydiveLogs-api/Controllers/GearController.cs +++ b/Back/skydiveLogs-api/Controllers/GearController.cs @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using Microsoft.AspNetCore.Cors; - -using AutoMapper; - +using Microsoft.AspNetCore.Mvc; +using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DataContract; +using System.Collections.Generic; namespace skydiveLogs_api.Controllers { diff --git a/Back/skydiveLogs-api/Controllers/ImageController.cs b/Back/skydiveLogs-api/Controllers/ImageController.cs index 93826c7..b115392 100644 --- a/Back/skydiveLogs-api/Controllers/ImageController.cs +++ b/Back/skydiveLogs-api/Controllers/ImageController.cs @@ -1,12 +1,10 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using Microsoft.AspNetCore.Cors; - -using AutoMapper; - +using Microsoft.AspNetCore.Mvc; +using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DataContract; +using System.Collections.Generic; namespace skydiveLogs_api.Controllers { diff --git a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs index 128036e..dd35321 100644 --- a/Back/skydiveLogs-api/Controllers/JumpTypeController.cs +++ b/Back/skydiveLogs-api/Controllers/JumpTypeController.cs @@ -1,18 +1,17 @@ -using System.Collections.Generic; -using Microsoft.AspNetCore.Mvc; +using AutoMapper; using Microsoft.AspNetCore.Cors; - -using AutoMapper; - +using Microsoft.AspNetCore.Mvc; +using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DataContract; - +using System.Collections.Generic; namespace skydiveLogs_api.Controllers { public class JumpTypeController : Base { + #region Public Constructors + public JumpTypeController(IJumpTypeService jumpTypeService, IMapper mapper) { @@ -20,6 +19,18 @@ namespace skydiveLogs_api.Controllers _mapper = mapper; } + #endregion Public Constructors + + #region Public Methods + + // DELETE: api/ApiWithActions/5 + [HttpDelete("{id}")] + [EnableCors] + public void Delete(int id) + { + _jumpTypeService.DeleteJumpTypeById(id); + } + // GET: api/JumpType [HttpGet] [EnableCors] @@ -54,15 +65,13 @@ namespace skydiveLogs_api.Controllers _jumpTypeService.UpdateJumpType(id, _mapper.Map(value)); } - // DELETE: api/ApiWithActions/5 - [HttpDelete("{id}")] - [EnableCors] - public void Delete(int id) - { - _jumpTypeService.DeleteJumpTypeById(id); - } + #endregion Public Methods + + #region Private Fields private readonly IJumpTypeService _jumpTypeService; private readonly IMapper _mapper; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Controllers/UserController.cs b/Back/skydiveLogs-api/Controllers/UserController.cs index 5618358..7529573 100644 --- a/Back/skydiveLogs-api/Controllers/UserController.cs +++ b/Back/skydiveLogs-api/Controllers/UserController.cs @@ -1,20 +1,17 @@ -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Cors; +using AutoMapper; using Microsoft.AspNetCore.Authorization; -using Microsoft.IdentityModel.Tokens; -using System.IdentityModel.Tokens.Jwt; -using System; -using System.Text; -using System.Security.Claims; +using Microsoft.AspNetCore.Cors; +using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; - -using AutoMapper; - +using Microsoft.IdentityModel.Tokens; +using skydiveLogs_api.DataContract; using skydiveLogs_api.Domain; using skydiveLogs_api.DomainBusiness.Interfaces; -using skydiveLogs_api.DataContract; using skydiveLogs_api.Settings; - +using System; +using System.IdentityModel.Tokens.Jwt; +using System.Security.Claims; +using System.Text; namespace skydiveLogs_api.Controllers { @@ -22,6 +19,8 @@ namespace skydiveLogs_api.Controllers [ApiController] public class UserController : Base { + #region Public Constructors + public UserController(IUserService userService, IMapper mapper, IOptions jwtSettings) @@ -31,6 +30,10 @@ namespace skydiveLogs_api.Controllers _jwtConf = jwtSettings.Value; } + #endregion Public Constructors + + #region Public Methods + // GET: api/User/AlwayLogin [HttpGet("AlwaysLogin")] [EnableCors] @@ -39,7 +42,6 @@ namespace skydiveLogs_api.Controllers return Ok(); } - // POST: api/User/Authenticate [AllowAnonymous] [HttpPost("Authenticate")] @@ -90,6 +92,8 @@ namespace skydiveLogs_api.Controllers return result; } + #endregion Public Methods + // PUT: api/User/5 //[HttpPut("{id}")] //[EnableCors] @@ -98,6 +102,8 @@ namespace skydiveLogs_api.Controllers // _userService.UpdateUser(id, _mapper.Map(value)); //} + #region Private Methods + private string CreateToken(UserResp foundUser) { var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_jwtConf.Passphrase)); @@ -118,8 +124,14 @@ namespace skydiveLogs_api.Controllers return new JwtSecurityTokenHandler().WriteToken(token); } - private readonly IUserService _userService; - private readonly IMapper _mapper; + #endregion Private Methods + + #region Private Fields + private readonly JwtSettings _jwtConf; + private readonly IMapper _mapper; + private readonly IUserService _userService; + + #endregion Private Fields } -} +} \ No newline at end of file diff --git a/Back/skydiveLogs-api/Startup.cs b/Back/skydiveLogs-api/Startup.cs index 8a278a9..1705257 100644 --- a/Back/skydiveLogs-api/Startup.cs +++ b/Back/skydiveLogs-api/Startup.cs @@ -1,17 +1,15 @@ -using System.Text; -using System.IO; - +using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.AspNetCore.Authentication.JwtBearer; using Microsoft.IdentityModel.Tokens; - +using skydiveLogs_api.DomainBusiness.Interfaces; using skydiveLogs_api.Ioc; using skydiveLogs_api.Settings; -using skydiveLogs_api.DomainBusiness.Interfaces; +using System.IO; +using System.Text; namespace skydiveLogs_api {