public async Task <CommentDetailsDto> Handle(GetCommentQuery request, CancellationToken cancellationToken) { if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId)) { throw new AuthenticationException(); } var commentFromDb = await _commentService.GetCommentAsync(request.CommentId); return(_mapper.Map <CommentDetailsDto>(commentFromDb)); }
public async Task <TeamDetailsDto> Handle(GetSingleTeamQuery request, CancellationToken cancellationToken) { var teamFromDb = await _teamService.GetTeamWithEagerLoadingAsync(request.TeamId); if (_authService.UserRoleAdminOrTeamIdMatches(teamFromDb)) { return(_mapper.Map <TeamDetailsDto>(teamFromDb)); } throw new AuthenticationException(); }
public async Task <TaskDetailsDto> Handle(GetSingleTaskForTeamQuery request, CancellationToken cancellationToken) { if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId)) { throw new AuthenticationException("Unauthorized access."); } var taskFromDb = await _taskService.GetTaskWithEagerLoadingAsync(request.TaskId); return(_mapper.Map <TaskDetailsDto>(taskFromDb)); }
public async Task <IEnumerable <CommentDetailsDto> > Handle(GetAllCommentsQuery request, CancellationToken cancellationToken) { if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId)) { throw new AuthenticationException(); } var commentsToReturn = await _commentService.GetAllCommentsAsync(request.TaskId); return(_mapper.Map <IEnumerable <CommentDetailsDto> >(commentsToReturn)); }
public async Task <CommentDetailsDto> Handle(CreateNewCommentCommand request, CancellationToken cancellationToken) { if (!_authService.UserRoleAdminOrTeamIdMatches(request.CommentForCreationDto.TeamId)) { throw new AuthenticationException(); } request.CommentForCreationDto.UserId = new Guid(_authService.GetUserIdClaimValue()); var commentToAdd = _mapper.Map <Comment>(request.CommentForCreationDto); await _commentService.AddNewCommentAsync(commentToAdd); return(_mapper.Map <CommentDetailsDto>(commentToAdd)); }
public async Task <IEnumerable <TaskDetailsDto> > Handle(GetAllTasksForTeamQuery request, CancellationToken cancellationToken) { if (!_authService.UserRoleAdminOrTeamIdMatches(request.TeamId)) { throw new AuthenticationException("Access denied"); } var tasksFromDb = await _taskService.GetAllTasksForATeamAsync(request.TeamId); var tasksToReturn = tasksFromDb.Select(t => _mapper.Map <TaskDetailsDto>(t)); return(tasksToReturn); }