|
@@ -0,0 +1,95 @@
|
|
|
+using System;
|
|
|
+using System.IO;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using Microsoft.Azure.WebJobs;
|
|
|
+using Microsoft.Azure.WebJobs.Extensions.Http;
|
|
|
+using Microsoft.AspNetCore.Http;
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
+using Newtonsoft.Json;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using Azure.Cosmos;
|
|
|
+using System.Text.Json;
|
|
|
+using System.Collections.Generic;
|
|
|
+using TEAMModelOS.SDK.Models;
|
|
|
+using TEAMModelOS.SDK.Extension;
|
|
|
+
|
|
|
+namespace TEAMModelFunction
|
|
|
+{
|
|
|
+ public class ActivityHttpTrigger
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ private readonly AzureCosmosFactory _azureCosmos;
|
|
|
+ private readonly DingDing _dingDing;
|
|
|
+ private readonly AzureStorageFactory _azureStorage;
|
|
|
+ private readonly AzureRedisFactory _azureRedis;
|
|
|
+ public ActivityHttpTrigger(AzureCosmosFactory azureCosmos, DingDing dingDing, AzureStorageFactory azureStorage
|
|
|
+ , AzureRedisFactory azureRedis)
|
|
|
+ {
|
|
|
+ _azureCosmos = azureCosmos;
|
|
|
+ _dingDing = dingDing;
|
|
|
+ _azureStorage = azureStorage;
|
|
|
+ _azureRedis = azureRedis;
|
|
|
+ }
|
|
|
+ [FunctionName("fix-exam-activity")]
|
|
|
+ public async Task<IActionResult> ExamActivity([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,ILogger log)
|
|
|
+ {
|
|
|
+ log.LogInformation("C# HTTP trigger function processed a request.");
|
|
|
+ string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
+ List<string> datas = JsonConvert.DeserializeObject<List<string>>(requestBody);
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
+ List<ExamInfo> exams = new List<ExamInfo>();
|
|
|
+ var query = $"select * from c ";
|
|
|
+ foreach (string data in datas) {
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
+ queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Exam-{data}") }))
|
|
|
+ {
|
|
|
+ using var json = await JsonDocument.ParseAsync(item.ContentStream);
|
|
|
+ if (json.RootElement.TryGetProperty("_count", out JsonElement count) && count.GetUInt16() > 0)
|
|
|
+ {
|
|
|
+ foreach (var obj in json.RootElement.GetProperty("Documents").EnumerateArray())
|
|
|
+ {
|
|
|
+ exams.Add(obj.ToObject<ExamInfo>());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return new OkObjectResult(new { });
|
|
|
+ }
|
|
|
+
|
|
|
+ [FunctionName("fix-vote-activity")]
|
|
|
+ public async Task<IActionResult> VoteActivity(
|
|
|
+ [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
|
|
+ ILogger log)
|
|
|
+ {
|
|
|
+ log.LogInformation("C# HTTP trigger function processed a request.1");
|
|
|
+ string name = req.Query["name"];
|
|
|
+ string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
+ dynamic data = JsonConvert.DeserializeObject(requestBody);
|
|
|
+ log.LogInformation($"{data}");
|
|
|
+ name = name ?? data?.name;
|
|
|
+
|
|
|
+ string responseMessage = string.IsNullOrEmpty(name)
|
|
|
+ ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
|
|
|
+ : $"Hello, {name}. This HTTP triggered function executed successfully.";
|
|
|
+ return new OkObjectResult(responseMessage);
|
|
|
+ }
|
|
|
+ [FunctionName("fix-survey-activity")]
|
|
|
+ public async Task<IActionResult> SurveyActivity(
|
|
|
+ [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
|
|
+ ILogger log)
|
|
|
+ {
|
|
|
+ log.LogInformation("C# HTTP trigger function processed a request.1");
|
|
|
+ string name = req.Query["name"];
|
|
|
+ string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
|
+ dynamic data = JsonConvert.DeserializeObject(requestBody);
|
|
|
+ log.LogInformation($"{data}");
|
|
|
+ name = name ?? data?.name;
|
|
|
+ string responseMessage = string.IsNullOrEmpty(name)
|
|
|
+ ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
|
|
|
+ : $"Hello, {name}. This HTTP triggered function executed successfully.";
|
|
|
+ return new OkObjectResult(responseMessage);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|