Exemplo n.º 1
0
        public static async Task <ActionResult <SlackUserEntity> > GetUser(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "teams/{teamId}/users/{userId}")] HttpRequest req,
            [CosmosDB(
                 databaseName: "IdentityHistory",
                 collectionName: "SlackUsers",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{userId}",
                 PartitionKey = "{teamId}")] SlackUserEntity userEntity,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            return(new OkObjectResult(userEntity));
        }
Exemplo n.º 2
0
        public static async Task ReceiveSlackUser(
            [QueueTrigger("receive-changed-user", Connection = "")] UserInfo changedUser,
            [CosmosDB(
                 databaseName: "IdentityHistory",
                 collectionName: "SlackUsers",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{Id}",
                 PartitionKey = "{TeamId}")] SlackUserEntity userEntity,
            [CosmosDB(
                 databaseName: "IdentityHistory",
                 collectionName: "SlackUsers",
                 ConnectionStringSetting = "CosmosDBConnection",
                 Id = "{Id}",
                 PartitionKey = "{TeamId}")] IAsyncCollector <SlackUserEntity> userEntityOut,
            ILogger log)
        {
            log.LogInformation($"C# Queue trigger function processed: {JsonConvert.SerializeObject(changedUser)}");

            if (userEntity == null)
            {
                userEntity = new SlackUserEntity()
                {
                    TeamId = changedUser.team_id,
                    Id     = changedUser.id,
                };
            }

            var newProfie = JsonConvert.DeserializeObject <UserProfileInfo>(JsonConvert.SerializeObject(changedUser.profile));

            newProfie.Timestamp = DateTimeOffset.UtcNow;

            var existProfile = userEntity.RecentProfile.OrderByDescending(x => x.Timestamp).FirstOrDefault();

            if (existProfile == null || existProfile.hasChange(newProfie))
            {
                log.LogInformation("Profile changed.");

                userEntity.CurrentUser = changedUser;
                userEntity.RecentProfile.Add(newProfie);
                await userEntityOut.AddAsync(userEntity);
            }
        }