From d528e37f3649a9681b1a25de4519d04c2dcb86e9 Mon Sep 17 00:00:00 2001 From: moritzLanger Date: Thu, 15 Dec 2022 11:33:48 +0100 Subject: [PATCH 1/2] added ErrorOr to not throw Errors anymore --- .../Controllers/SessionController.cs | 167 +++++++------- .../Controllers/StatusController.cs | 36 ++- .../Service/ISessionService.cs | 25 ++- .../Service/SessionService.cs | 211 +++++++++++------- ...evon4Net.Application.WebAPI.Implementation | 7 + ...t.Application.WebAPI.Implementation.csproj | 1 + 6 files changed, 242 insertions(+), 205 deletions(-) diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/SessionController.cs b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/SessionController.cs index 19cfba4..a36c10d 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/SessionController.cs +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/SessionController.cs @@ -47,18 +47,16 @@ public SessionController(ISessionService SessionService, IWebSocketHandler webSo public async Task CreateSession(SessionDto sessionDto) { Devon4NetLogger.Debug($"Create session that will expire at {sessionDto.ExpiresAt}"); - try - { - return Ok(await _sessionService.CreateSession(sessionDto)); - } - catch (Exception exception) + var errorOrResult = await _sessionService.CreateSession(sessionDto); + + if (errorOrResult.IsError) { - return exception switch - { - InvalidExpiryDateException _ => BadRequest(), - _ => StatusCode(500) - }; + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); } + + return Ok(errorOrResult.Value); + } [HttpPut] [AllowAnonymous] @@ -70,20 +68,16 @@ public async Task CreateSession(SessionDto sessionDto) public async Task InvalidateSession(long id) { Devon4NetLogger.Debug($"Put-Request to invalidate session with id: {id}"); + var errorOrResult = await _sessionService.InvalidateSession(id); - try + if (errorOrResult.IsError) { - return Ok(await _sessionService.InvalidateSession(id)); - } - catch (Exception exception) - { - return exception switch - { - NotFoundException _ => NotFound(), - InvalidSessionException _ => BadRequest(), - _ => StatusCode(500) - }; + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); } + + return Ok(errorOrResult.Value); + } /// @@ -101,19 +95,15 @@ public async Task RemoveUserFromSession(long sessionId, String us { Devon4NetLogger.Debug($"Put-Request for removing user with id: {userId} from session status with id: {sessionId}"); - try - { - var leaveResult = await _sessionService.RemoveUserFromSession(sessionId, userId); + var errorOrResult = await _sessionService.RemoveUserFromSession(sessionId, userId); - return new ObjectResult(JsonConvert.SerializeObject(leaveResult)); - } - catch (Exception exception) + if (errorOrResult.IsError) { - return exception switch - { - NotFoundException _ => StatusCode(500), - }; + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); } + + return new ObjectResult(JsonConvert.SerializeObject(errorOrResult.Value)); } /// @@ -132,26 +122,25 @@ public async Task> AddUserToSession(string inviteToken, [F var (username, desiredRole) = joinDto; - var (completed, result) = await _sessionService.AddUserToSession(inviteToken, username, desiredRole); + var errorOrResult = await _sessionService.AddUserToSession(inviteToken, username, desiredRole); - if (completed) + if (errorOrResult.IsError) { - var (sessionId, userId, _, role, token) = result; - - Message Message = new Message - { - Type = MessageType.UserJoined, - Payload = new UserDto { Id = userId, Role = role, Token = token, Username = username }, - }; + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); + } - await _webSocketHandler.Send(Message, sessionId); + var (sessionId, userId, _, role, token) = errorOrResult.Value.Item2; - return new ObjectResult(JsonConvert.SerializeObject(result)); - } - else + Message Message = new Message { - return BadRequest(); - } + Type = MessageType.UserJoined, + Payload = new UserDto { Id = userId, Role = role, Token = token, Username = username }, + }; + + await _webSocketHandler.Send(Message, sessionId); + + return new ObjectResult(JsonConvert.SerializeObject(errorOrResult.Value.Item2)); } [HttpPost] @@ -169,22 +158,24 @@ public async Task AddTask(long sessionId, [FromBody] TaskDto task) Devon4NetLogger.Debug($"{userId}"); - var (finished, taskDto) = await _sessionService.AddTaskToSession(sessionId, userId, task); + var errorOrResult = await _sessionService.AddTaskToSession(sessionId, userId, task); - if (finished) + if (errorOrResult.IsError) { - Message Message = new Message - { - Type = MessageType.TaskCreated, - Payload = taskDto - }; + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); + } - await _webSocketHandler.Send(Message, sessionId); + Message Message = new Message + { + Type = MessageType.TaskCreated, + Payload = errorOrResult.Value.Item2 + }; - return Ok(); - } + await _webSocketHandler.Send(Message, sessionId); + + return Ok(); - return BadRequest(); } [HttpDelete] @@ -197,31 +188,24 @@ public async Task DeleteTask(long sessionId, string taskId) { Devon4NetLogger.Debug($"Delete-Request to delete task with id: {taskId} from session with id: {sessionId}"); - try - { - var finished = await _sessionService.DeleteTask(sessionId, taskId); - - if (finished) - { - Message message = new Message - { - Type = MessageType.TaskDeleted, - Payload = taskId - }; - await _webSocketHandler.Send(message, sessionId); - return Ok(); - } + + var errorOrResult = await _sessionService.DeleteTask(sessionId, taskId); + if (errorOrResult.IsError) + { + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); return BadRequest(); } - catch (Exception exception) + + Message message = new Message { - return exception switch - { - NotFoundException or TaskNotFoundException => NotFound(), - _ => StatusCode(500) - }; - } + Type = MessageType.TaskDeleted, + Payload = taskId + }; + await _webSocketHandler.Send(message, sessionId); + return Ok(); + + } /// @@ -240,11 +224,17 @@ public async Task> AddNewEstimation(long sessionId, var (taskId, voteBy, complexity) = estimationDto; - var result = await _sessionService.AddNewEstimation(sessionId, taskId, voteBy, complexity); + var errorOrResult = await _sessionService.AddNewEstimation(sessionId, taskId, voteBy, complexity); + + if (errorOrResult.IsError) + { + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); + } await _webSocketHandler.Send(new Message { Type = MessageType.EstimationAdded, Payload = estimationDto }, sessionId); - return StatusCode(StatusCodes.Status201Created, result); + return StatusCode(StatusCodes.Status201Created, errorOrResult.Value); } [HttpPut] @@ -257,18 +247,19 @@ public async Task ChangeTaskStatus(long sessionId, [FromBody] Tas { // Changing the status of a task requires other elements to be modified. // There can always be only one open or evaluated task at the same time. - var (finished, modifiedTasks) = await _sessionService.ChangeTaskStatus(sessionId, statusChange); - if (finished) - { - await _webSocketHandler.Send(new Message> { Type = MessageType.TaskStatusModified, Payload = modifiedTasks }, sessionId); + var errorOrResult = await _sessionService.ChangeTaskStatus(sessionId, statusChange); - return Ok(modifiedTasks); - } - else + if (errorOrResult.IsError) { - return BadRequest("Zero entries got updated due to errors. Please ensure the task exists."); + Devon4NetLogger.Debug(errorOrResult.FirstError.Description); + return BadRequest(); } + + await _webSocketHandler.Send(new Message> { Type = MessageType.TaskStatusModified, Payload = errorOrResult.Value.Item2 }, sessionId); + + return Ok(errorOrResult.Value.Item2); + } } } diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/StatusController.cs b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/StatusController.cs index 094db81..4bd26f2 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/StatusController.cs +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Controllers/StatusController.cs @@ -37,32 +37,26 @@ public async Task GetSessionStatus(long id) { Devon4NetLogger.Debug($"Get-Request for session status with id: {id}"); - try - { - var (isValid, inviteToken, tasks, users) = await _sessionService.GetStatus(id); + var errorOrStatus = await _sessionService.GetStatus(id); - Devon4NetLogger.Debug($"Session is valid: {isValid}"); + if (errorOrStatus.IsError) + { + Devon4NetLogger.Debug(errorOrStatus.FirstError.Description); + return BadRequest(); + } - var statusResult = new StatusDto - { - IsValid = isValid, - InviteToken = inviteToken, - Tasks = tasks.Select(item => TaskConverter.ModelToDto(item)).ToList(), - Users = users.Select(item => UserConverter.ModelToDto(item)).ToList(), - }; + Devon4NetLogger.Debug($"Session is valid: {errorOrStatus.Value.Item1}"); - return new ObjectResult(JsonConvert.SerializeObject(statusResult)); - } - catch (Exception exception) + var statusResult = new StatusDto { - Devon4NetLogger.Debug($"Exception thrown: {exception.Message}"); + IsValid = errorOrStatus.Value.Item1, + InviteToken = errorOrStatus.Value.Item2, + Tasks = errorOrStatus.Value.Item3.Select(item => TaskConverter.ModelToDto(item)).ToList(), + Users = errorOrStatus.Value.Item4.Select(item => UserConverter.ModelToDto(item)).ToList(), + }; - return exception switch - { - NotFoundException _ => NotFound(), - _ => StatusCode(500), - }; - } + return new ObjectResult(JsonConvert.SerializeObject(statusResult)); } + } } \ No newline at end of file diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/ISessionService.cs b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/ISessionService.cs index 170677d..c27ab07 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/ISessionService.cs +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/ISessionService.cs @@ -1,7 +1,6 @@ using Devon4Net.Application.WebAPI.Implementation.Domain.Entities; using Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Dtos; - -using LiteDB; +using ErrorOr; namespace Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Service { @@ -10,38 +9,40 @@ namespace Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement /// public interface ISessionService { + public ErrorOr validateSession(Session session, long? sessionId); + public Task GetSession(long id); public Task FindSessionWithInviteToken(string token); - public Task<(bool, string?, List, List)> GetStatus(long sessionId); + public Task, List)>> GetStatus(long sessionId); /// /// CreateSession /// /// /// - public Task CreateSession(SessionDto sessionDto); - public Task InvalidateSession(long sessionId); + public Task> CreateSession(SessionDto sessionDto); + public Task> InvalidateSession(long sessionId); - public Task AddNewEstimation(long sessionId, string taskId, string voteBy, int complexity); + public Task> AddNewEstimation(long sessionId, string taskId, string voteBy, int complexity); - public Task RemoveUserFromSession(long id, String userId); + public Task> RemoveUserFromSession(long id, String userId); /// /// Add an User to a given session /// - public Task<(bool, JoinSessionResultDto?)> AddUserToSession(string inviteToken, string username, Role desiredRole); + public Task> AddUserToSession(string inviteToken, string username, Role desiredRole); - public Task<(bool, TaskDto?)> AddTaskToSession(long sessionId, string userId, TaskDto task); + public Task> AddTaskToSession(long sessionId, string userId, TaskDto task); /// /// Delete a Task /// - public Task DeleteTask(long sessionId, string taskId); + public Task> DeleteTask(long sessionId, string taskId); - public Task<(bool, List)> ChangeTaskStatus(long sessionId, TaskStatusChangeDto statusChange); + public Task)>> ChangeTaskStatus(long sessionId, TaskStatusChangeDto statusChange); - public Task isPrivilegedUser(long sessionId, string userId); + public Task> isPrivilegedUser(long sessionId, string userId); } } \ No newline at end of file diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs index 814191b..7071757 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs @@ -11,6 +11,7 @@ using System; using Devon4Net.Infrastructure.JWT.Handlers; using System.Security.Claims; +using ErrorOr; namespace Devon4Net.Application.WebAPI.Implementation.Business.SessionManagement.Service { @@ -33,16 +34,37 @@ public SessionService(ILiteDbRepository SessionRepository, ILiteDbRepos _userRepository = UserRepository; _jwtHandler = JwtHandler; } + + /// + /// validates a Session + /// + /// + /// Error Or Bool + public ErrorOr validateSession(Session session, long? sessionId) + { + + if (session == null) + { + return Error.Failure(description: $"no session with the sessionId: {sessionId}"); + } + if (session.ExpiresAt < DateTime.Now) + { + return Error.Failure(description: $"Session with the SessionId: {sessionId} is no longer valid"); + } + return true; + + } + /// /// Creates the Session /// /// /// - public async Task CreateSession(SessionDto sessionDto) + public async Task> CreateSession(SessionDto sessionDto) { if (sessionDto.ExpiresAt <= DateTime.Now || sessionDto.ExpiresAt == null) { - throw new InvalidExpiryDateException(); + return Error.Failure(description: "Session is no longer valid or never existed"); } var (expiresAt, username) = sessionDto; @@ -101,18 +123,16 @@ public async Task GetSession(long id) return _sessionRepository.GetFirstOrDefault(expression); } - public async Task InvalidateSession(long sessionId) + public async Task> InvalidateSession(long sessionId) { Session sessionResult = await GetSession(sessionId); - if (sessionResult == null) - { - throw new NotFoundException(sessionId); - } + var errorOrTrue = validateSession(sessionResult, sessionId); - if (!sessionResult.IsValid()) + if (errorOrTrue.IsError) { - throw new InvalidSessionException(sessionId); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; } sessionResult.ExpiresAt = DateTime.Now; @@ -120,20 +140,16 @@ public async Task InvalidateSession(long sessionId) return _sessionRepository.Update(sessionResult); } - public async Task<(bool, string?, List, List)> GetStatus(long sessionId) + public async Task, List)>> GetStatus(long sessionId) { var entity = await GetSession(sessionId); - if (entity == null) - { - throw new NotFoundException(sessionId); - } + var errorOrTrue = validateSession(entity, sessionId); - bool sessionIsValid = entity.IsValid(); - - if (!sessionIsValid) + if (errorOrTrue.IsError) { - return (false, null, null, null); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; } return (true, entity.InviteToken, entity.Tasks.ToList(), entity.Users.ToList()); @@ -147,20 +163,24 @@ public async Task InvalidateSession(long sessionId) /// The originating user's ID /// Complexity estimation /// - public async Task AddNewEstimation(long sessionId, string taskId, string voteBy, int complexity) + public async Task> AddNewEstimation(long sessionId, string taskId, string voteBy, int complexity) { var session = await GetSession(sessionId); - if (session is null) + + var errorOrTrue = validateSession(session, sessionId); + + if (errorOrTrue.IsError) { - throw new NoLongerValid(sessionId); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; } var containsTask = session.Tasks.Where(item => item.Id == taskId).Any(); if (containsTask == false) { - throw new NoOpenOrSuspendedTask(); + return Error.Failure(description: "No open or suspended tasks"); } var task = session.Tasks.First(item => item.Id == taskId); @@ -176,7 +196,7 @@ public async Task AddNewEstimation(long sessionId, string taskId, st if (alreadyContainsEstimation) { - var oldEstimation = estimations.First(est => est.VoteBy == voteBy); + var oldEstimation = estimations.FirstOrDefault(est => est.VoteBy == voteBy); estimations.Remove(oldEstimation); } @@ -189,24 +209,30 @@ public async Task AddNewEstimation(long sessionId, string taskId, st return newEstimation; } - public async Task RemoveUserFromSession(long sessionId, string userId) + public async Task> RemoveUserFromSession(long sessionId, string userId) { - var expression = LiteDB.Query.EQ("_id", sessionId); - var session = _sessionRepository.GetFirstOrDefault(expression); + + var session = await GetSession(sessionId); - if (session != null) + var errorOrTrue = validateSession(session, sessionId); + + if (errorOrTrue.IsError) { - var user = session.Users.SingleOrDefault(i => i.Id == userId); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; + } - if (user != null) - { - session.Users.Remove(user); - _sessionRepository.Update(session); - return true; - } + var user = session.Users.SingleOrDefault(i => i.Id == userId); + + if (user != null) + { + session.Users.Remove(user); + _sessionRepository.Update(session); + return true; } + - return false; + return Error.Failure(description: $"no user with the id: {userId} could be found"); } /// @@ -216,7 +242,7 @@ public async Task RemoveUserFromSession(long sessionId, string userId) /// /// /// - public async Task<(bool, JoinSessionResultDto?)> AddUserToSession(string inviteToken, string username, Role desiredRole) + public async Task> AddUserToSession(string inviteToken, string username, Role desiredRole) { if (desiredRole == Role.Author) { @@ -225,9 +251,12 @@ public async Task RemoveUserFromSession(long sessionId, string userId) var session = await FindSessionWithInviteToken(inviteToken); - if (!session.IsValid()) + var errorOrTrue = validateSession(session, null); + + if (errorOrTrue.IsError) { - Devon4NetLogger.Debug("Session is not valid!"); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; } Devon4NetLogger.Debug("Adding to session!"); @@ -240,16 +269,12 @@ public async Task RemoveUserFromSession(long sessionId, string userId) var userEntity = _userRepository.Create(newUser); - bool finished = false; - - if (session is not null) - { - session.Users.Add(newUser); + session.Users.Add(newUser); - finished = _sessionRepository.Update(session); + var finished = _sessionRepository.Update(session); - Devon4NetLogger.Debug("Added user to session!"); - }; + Devon4NetLogger.Debug("Added user to session!"); + if (finished) { @@ -282,10 +307,18 @@ public async Task RemoveUserFromSession(long sessionId, string userId) return (false, null); } - public async Task<(bool, TaskDto)> AddTaskToSession(long sessionId, string userId, TaskDto task) + public async Task> AddTaskToSession(long sessionId, string userId, TaskDto task) { var session = await GetSession(sessionId); + var errorOrTrue = validateSession(session, sessionId); + + if (errorOrTrue.IsError) + { + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; + } + if (!session.isPrivilegedUser(userId)) { return (false, null); @@ -302,18 +335,16 @@ public async Task RemoveUserFromSession(long sessionId, string userId) Url = url, Status = Status.Suspended }; + + session.Tasks.Add(newTask); - if (session != null) - { - session.Tasks.Add(newTask); - - var finished = _sessionRepository.Update(session); + var finished = _sessionRepository.Update(session); - if (finished) - { - return (finished, TaskConverter.ModelToDto(newTask)); - } + if (finished) + { + return (finished, TaskConverter.ModelToDto(newTask)); } + return (false, null); } @@ -324,13 +355,16 @@ public async Task RemoveUserFromSession(long sessionId, string userId) /// /// /// - public async Task DeleteTask(long sessionId, string taskId) + public async Task> DeleteTask(long sessionId, string taskId) { var session = await GetSession(sessionId); - if (session == null) + var errorOrTrue = validateSession(session, sessionId); + + if (errorOrTrue.IsError) { - throw new NotFoundException(sessionId); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; } var task = session.Tasks.ToList().Find(item => item.Id == taskId); @@ -353,51 +387,60 @@ private string generateInviteToken() return BitConverter.ToString(randomNumber).Replace("-", String.Empty); } - public async Task<(bool, List)> ChangeTaskStatus(long sessionId, TaskStatusChangeDto statusChange) + public async Task)>> ChangeTaskStatus(long sessionId, TaskStatusChangeDto statusChange) { var session = await GetSession(sessionId); - var (id, status) = statusChange; - // if the session could be found and is valid - if (session is not null && session.IsValid()) + var errorOrTrue = validateSession(session, sessionId); + + if (errorOrTrue.IsError) { - var containsTask = session.Tasks.Where(item => item.Id == id).Any(); + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; + } - if (!containsTask) - { - return (false, new List()); - } + var (id, status) = statusChange; - // and it contains the task requested to be chnaged - var (modified, taskChanges) = session.ChangeStatusOfTask(id, status); + var containsTask = session.Tasks.Where(item => item.Id == id).Any(); - if (!modified) - { - return (false, new List()); - } + if (!containsTask) + { + return (false, new List()); + } - var finished = _sessionRepository.Update(session); + // and it contains the task requested to be chnaged + var (modified, taskChanges) = session.ChangeStatusOfTask(id, status); - // and we could properly update the database - if (finished) - { - var converted = taskChanges.Select<(String id, Status status), TaskStatusChangeDto>(item => new TaskStatusChangeDto { Id = item.id, Status = item.status }).ToList(); + if (!modified) + { + return (false, new List()); + } - return (true, converted); - } + var finished = _sessionRepository.Update(session); + + // and we could properly update the database + if (finished) + { + var converted = taskChanges.Select<(String id, Status status), TaskStatusChangeDto>(item => new TaskStatusChangeDto { Id = item.id, Status = item.status }).ToList(); + + return (true, converted); } + return (false, new List()); } - public async Task isPrivilegedUser(long sessionId, string userId) + public async Task> isPrivilegedUser(long sessionId, string userId) { var session = await GetSession(sessionId); - if (session is null || !session.IsValid()) + var errorOrTrue = validateSession(session, sessionId); + + if (errorOrTrue.IsError) { - return false; + Devon4NetLogger.Debug(errorOrTrue.FirstError.Description); + return errorOrTrue.FirstError; } if (session.Users.First().Id.Equals(userId)) diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation index add0f62..1c67786 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation @@ -703,6 +703,13 @@ + + + validates a Session + + + Error Or Bool + Creates the Session diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation.csproj b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation.csproj index 9fee781..a817a11 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation.csproj +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Devon4Net.Application.WebAPI.Implementation.csproj @@ -35,6 +35,7 @@ + From db7be67a4c47eda6a5fa217c5c99ebe87ccff7ac Mon Sep 17 00:00:00 2001 From: moritzLanger Date: Mon, 19 Dec 2022 10:41:21 +0100 Subject: [PATCH 2/2] removed one mote Error Throw --- .../Business/SessionManagement/Service/SessionService.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs index 7071757..d65c8bc 100644 --- a/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs +++ b/dotnet-estimation/dotnet-estimation/Templates/WebAPI/Devon4Net.Application.WebAPI.Implementation/Business/SessionManagement/Service/SessionService.cs @@ -371,7 +371,7 @@ public async Task> DeleteTask(long sessionId, string taskId) if (task == null) { - throw new TaskNotFoundException(taskId); + return Error.Failure(description: $"No task found with taskId: {taskId}"); } session.Tasks.Remove(task);