public static async Task Run(
            [QueueTrigger(QueueNames.ActivityUpdated)] ActivityUpdatedMessage message,
            [Table(TableNames.AthletesTable, "{AthleteId}", "")] AthleteTableEntity athlete,
            [Table(TableNames.AthletesTable)] CloudTable athletesTable,
            [Queue(QueueNames.SyncDay)] IAsyncCollector <SyncDayRequest> syncDayRequests,
            ILogger log)
        {
            var littleStravaClient = new LittleStravaClient();
            var activity           = await littleStravaClient.GetActivityById(athlete, message.ActivityId);

            await syncDayRequests.AddAsync(new SyncDayRequest
            {
                DateTime  = activity.StartDate.Date,
                AthleteId = athlete.GetAthleteId()
            });

            await athletesTable.ExecuteAsync(TableOperation.InsertOrReplace(athlete));
        }
Example #2
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "webhook")] HttpRequest req,
            [Queue(QueueNames.ActivityUpdated)] IAsyncCollector <ActivityUpdatedMessage> activitiesUpdated,
            ILogger log)
        {
            var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            var data        = JsonSerializer.Deserialize <WebhookData>(requestBody);

            if (data.ObjectType == ObjectType.Activity)
            {
                var message = new ActivityUpdatedMessage
                {
                    AthleteId  = data.OwnerId,
                    ActivityId = data.ObjectId
                };

                await activitiesUpdated.AddAsync(message);
            }

            return(new OkResult());
        }