Beispiel #1
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "sleepdata")] HttpRequest req,
            ILogger logger,
            [Inject] SleepDataService sleepDataService
            )
        {
            logger.LogInformation("SleepDataHttpTrigger function processed a request.");

            var json = await req.ReadAsStringAsync();

            logger.LogInformation(json);

            var sleepDataRequest = JsonConvert.DeserializeObject <SleepDataRequest>(json);

            var now    = DateTime.UtcNow;
            var entity = new SleepDataEntity("sleepDataEntity", now.Ticks.ToString())
            {
                SleepDuration        = sleepDataRequest.SleepDuration.ToString(),
                DeviceUser           = sleepDataRequest.DeviceUser,
                InBedDateandTime     = DateTimeParser.ParseWithingsDate(sleepDataRequest.InBedDateandTime).AddHours(-9),
                DeviceMac            = sleepDataRequest.DeviceMac,
                OutofBedDateandTime  = DateTimeParser.ParseWithingsDate(sleepDataRequest.OutofBedDateandTime).AddHours(-9),
                LightSleepDuration   = sleepDataRequest.LightSleepDuration.ToString(),
                DeepSleepDuration    = sleepDataRequest.DeepSleepDuration.ToString(),
                RemSleepDuration     = sleepDataRequest.RemSleepDuration.ToString(),
                SleepScore           = sleepDataRequest.SleepScore,
                SnoringDuration      = sleepDataRequest.SnoringDuration.ToString(),
                SnoringEpisodesCount = sleepDataRequest.SnoringEpisodesCount,
                HeartRateAverage     = sleepDataRequest.HeartRateAverage,
                AwakeDuration        = sleepDataRequest.AwakeDuration.ToString(),
                StatusSleepScore     = sleepDataRequest.StatusSleepScore,
                StatusRegularity     = sleepDataRequest.StatusRegularity,
                NbInterruptions      = sleepDataRequest.NbInterruptions,
                TimeToSleep          = sleepDataRequest.TimeToSleep.ToString(),
                TimeToGetUp          = sleepDataRequest.TimeToGetUp.ToString(),
                InsertedTime         = now,
            };

            await sleepDataService.AddAsync(entity);

            return(new OkObjectResult("ok"));
        }
Beispiel #2
0
 public Task AddAsync(SleepDataEntity entity)
 {
     return(sleepDataRepository.AddAsync(entity));
 }