From 63fab9d827c721941107ca08aee8de49eade474d Mon Sep 17 00:00:00 2001 From: csimonapastore Date: Thu, 19 Jun 2025 23:28:28 +0200 Subject: [PATCH] Removing duplicated lines --- MainProject/Controllers/AuthController.cs | 7 +-- MainProject/Controllers/BaseController.cs | 8 +++- MainProject/Controllers/RoleController.cs | 30 ++---------- MainProject/Controllers/UserController.cs | 50 ++++---------------- MainProject/Controllers/VersionController.cs | 5 +- 5 files changed, 23 insertions(+), 77 deletions(-) diff --git a/MainProject/Controllers/AuthController.cs b/MainProject/Controllers/AuthController.cs index a54e764..fef8838 100644 --- a/MainProject/Controllers/AuthController.cs +++ b/MainProject/Controllers/AuthController.cs @@ -43,12 +43,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } diff --git a/MainProject/Controllers/BaseController.cs b/MainProject/Controllers/BaseController.cs index 491b3f5..d217d39 100644 --- a/MainProject/Controllers/BaseController.cs +++ b/MainProject/Controllers/BaseController.cs @@ -66,9 +66,13 @@ namespace BasicDotnetTemplate.MainProject.Controllers return StatusCode((int)HttpStatusCode.BadRequest, CreateResponse(HttpStatusCode.BadRequest, message, data)); } - protected IActionResult InternalServerError(string message) + protected IActionResult InternalServerError(Exception exception) { - message = String.IsNullOrEmpty(message) ? "Internal server error" : message; + var message = this._somethingWentWrong; + if (!String.IsNullOrEmpty(exception.Message)) + { + message += $". {exception.Message}"; + } return StatusCode((int)HttpStatusCode.InternalServerError, CreateResponse(HttpStatusCode.InternalServerError, message, new object())); } diff --git a/MainProject/Controllers/RoleController.cs b/MainProject/Controllers/RoleController.cs index 226e960..38ddc36 100644 --- a/MainProject/Controllers/RoleController.cs +++ b/MainProject/Controllers/RoleController.cs @@ -47,12 +47,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -88,12 +83,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -101,7 +91,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers [JwtAuthorization()] [ModelStateValidationHandledByFilterAttribute] [HttpPut("update/{guid}")] - [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType>(StatusCodes.Status400BadRequest)] [ProducesResponseType>(StatusCodes.Status500InternalServerError)] public async Task UpdateRoleAsync([FromBody] CreateRoleRequest request, string guid) //NOSONAR @@ -139,12 +129,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -173,12 +158,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } diff --git a/MainProject/Controllers/UserController.cs b/MainProject/Controllers/UserController.cs index 965d28c..89b0967 100644 --- a/MainProject/Controllers/UserController.cs +++ b/MainProject/Controllers/UserController.cs @@ -51,17 +51,12 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } - // [JwtAuthorization()] + [JwtAuthorization()] [ModelStateValidationHandledByFilterAttribute] [HttpPost("create")] [ProducesResponseType(StatusCodes.Status201Created)] @@ -98,12 +93,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -111,7 +101,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers [JwtAuthorization()] [ModelStateValidationHandledByFilterAttribute] [HttpPut("update/{guid}")] - [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType>(StatusCodes.Status400BadRequest)] [ProducesResponseType>(StatusCodes.Status500InternalServerError)] public async Task UpdateUserAsync([FromBody] UpdateUserRequest request, string guid) //NOSONAR @@ -133,12 +123,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -146,7 +131,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers [JwtAuthorization()] [ModelStateValidationHandledByFilterAttribute] [HttpPut("update/{guid}/password")] - [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType>(StatusCodes.Status400BadRequest)] [ProducesResponseType>(StatusCodes.Status500InternalServerError)] public async Task UpdateUserPasswordAsync(string guid, string newPassword) @@ -168,12 +153,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -181,7 +161,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers [JwtAuthorization()] [ModelStateValidationHandledByFilterAttribute] [HttpPut("update/{guid}/role")] - [ProducesResponseType(StatusCodes.Status201Created)] + [ProducesResponseType(StatusCodes.Status200OK)] [ProducesResponseType>(StatusCodes.Status400BadRequest)] [ProducesResponseType>(StatusCodes.Status500InternalServerError)] public async Task UpdateUserRoleAsync(string guid, string roleGuid) @@ -209,12 +189,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } @@ -243,12 +218,7 @@ namespace BasicDotnetTemplate.MainProject.Controllers } catch (Exception exception) { - var message = this._somethingWentWrong; - if (!String.IsNullOrEmpty(exception.Message)) - { - message += $". {exception.Message}"; - } - return InternalServerError(message); + return InternalServerError(exception); } } diff --git a/MainProject/Controllers/VersionController.cs b/MainProject/Controllers/VersionController.cs index 3d81653..e818d01 100644 --- a/MainProject/Controllers/VersionController.cs +++ b/MainProject/Controllers/VersionController.cs @@ -11,9 +11,6 @@ namespace BasicDotnetTemplate.MainProject.Controllers ) : base(configuration) { } [HttpGet("get")] - public IActionResult GetVersion() - { - return Success(String.Empty, _appSettings?.Settings?.Version); - } + public IActionResult GetVersion() => Success(String.Empty, _appSettings?.Settings?.Version); } }