public async Task <PinsReturnDto> GetBoardPinsAsync( GetBoardPinsDto model ) { var userId = long.Parse(_httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value); var board = await _boardService.GetByIdAsync(model.BoardId); if (board == null) { throw new ArgumentException("Board not found."); } if (board.CreatedBy != userId && board.IsPrivate) { throw new UnauthorizedAccessException(); } var pins = await(await _boardPinService.GetAllAsync(d => d.Board.Id == model.BoardId, x => x.Pin)) .Skip(model.Offset) .Take(model.Take) .Select(e => e.Pin.ToPinReturnDto()) .ToListAsync(); var pinsCount = (await _boardPinService.GetAllAsync(d => d.Board.Id == model.BoardId, x => x.Pin)).Count(); return(pins.ToPinsReturnDtoExtensions(pinsCount)); }
public async Task <IActionResult> GetBoardPins( [FromQuery] GetBoardPinsDto model ) { try { var responsePayload = await _boardPinService.GetBoardPinsAsync(model); return(Ok(responsePayload)); } catch (UnauthorizedAccessException) { return(Unauthorized()); } catch (Exception ex) { return(BadRequest(new { ex.Message })); } }