Example #1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Received recent shift request.");

            var claims = await _authenticationHelper.DecodeToken(req.Headers["Authorization"]);

            if (claims == null || !claims.Identity.IsAuthenticated)
            {
                log.LogInformation("Unauthorised request received.");
                return(new UnauthorizedResult());
            }

            var shifts = await _shiftService.GetAllShifts(claims.Identity.Name);

            shifts = shifts.Where(s => s.Date.Date <= DateTime.Today)
                     .OrderByDescending(s => s.Date).Take(6);

            return(new OkObjectResult(shifts.Select(s => new ShiftSummary
            {
                CrewMate = s.CrewMate,
                Date = s.Date,
                Duration = s.Duration,
                Event = s.Event,
                Id = s.Id,
                Location = s.Location,
                LoggedCalls = s.Jobs?.Count ?? 0,
                Role = s.Role
            })));
        }
 public ActionResult <IEnumerable <Shift> > Get()
 {
     try
     {
         return(_shiftService.GetAllShifts());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Example #3
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("Received all shift request.");

            var claims = await _authenticationHelper.DecodeToken(req.Headers["Authorization"]);

            if (claims == null || !claims.Identity.IsAuthenticated)
            {
                log.LogInformation("Unauthorised request received.");
                return(new UnauthorizedResult());
            }

            var countValid = int.TryParse(req.Query["count"], out var count);

            if (!countValid)
            {
                count = 10;
            }

            var pageValid = int.TryParse(req.Query["page"], out var page);

            if (!pageValid)
            {
                page = 0;
            }

            var shifts = await _shiftService.GetAllShifts(claims.Identity.Name);

            req.HttpContext.Response.Headers.Add("X-Total-Count", shifts.Count().ToString());

            shifts = shifts.OrderByDescending(s => s.Date).Skip(page * count).Take(count);

            return(new OkObjectResult(shifts.Select(s => new ShiftSummary
            {
                CrewMate = s.CrewMate,
                Date = s.Date,
                Duration = s.Duration,
                Event = s.Event,
                Id = s.Id,
                Location = s.Location,
                LoggedCalls = s.Jobs?.Count ?? 0,
                Role = s.Role
            })));
        }
Example #4
0
 public ActionResult <List <ShiftModel> > Get()
 {
     return(_shiftService.GetAllShifts());
 }