|
@@ -38,7 +38,7 @@ namespace TEAMModelFunction
|
|
[FunctionName("fix-exam-activity")]
|
|
[FunctionName("fix-exam-activity")]
|
|
public async Task<IActionResult> ExamActivity([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,ILogger log)
|
|
public async Task<IActionResult> ExamActivity([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,ILogger log)
|
|
{
|
|
{
|
|
- log.LogInformation("C# HTTP trigger function processed a request.");
|
|
|
|
|
|
+ log.LogInformation("fix-exam-activity...");
|
|
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
List<string> datas = JsonConvert.DeserializeObject<List<string>>(requestBody);
|
|
List<string> datas = JsonConvert.DeserializeObject<List<string>>(requestBody);
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
@@ -59,52 +59,17 @@ namespace TEAMModelFunction
|
|
}
|
|
}
|
|
}
|
|
}
|
|
log.LogInformation($"{exams.ToJsonString()}");
|
|
log.LogInformation($"{exams.ToJsonString()}");
|
|
- foreach (var info in exams) {
|
|
|
|
|
|
+ foreach (var info in exams)
|
|
|
|
+ {
|
|
|
|
+ if (info.classes.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
List<string> sub = new List<string>();
|
|
List<string> sub = new List<string>();
|
|
foreach (ExamSubject subject in info.subjects)
|
|
foreach (ExamSubject subject in info.subjects)
|
|
{
|
|
{
|
|
sub.Add(subject.id);
|
|
sub.Add(subject.id);
|
|
}
|
|
}
|
|
- //ActivityData dataa;
|
|
|
|
- //if (info.scope == "school")
|
|
|
|
- //{
|
|
|
|
- // dataa = new ActivityData
|
|
|
|
- // {
|
|
|
|
- // id = info.id,
|
|
|
|
- // code = $"Activity-{info.school}",
|
|
|
|
- // type = "exam",
|
|
|
|
- // name = info.name,
|
|
|
|
- // startTime = info.startTime,
|
|
|
|
- // endTime = info.endTime,
|
|
|
|
- // scode = info.code,
|
|
|
|
- // scope = info.scope,
|
|
|
|
- // classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
|
|
|
|
- // tmdids = new List<string> { "" },
|
|
|
|
- // progress = "going",
|
|
|
|
- // subjects = sub
|
|
|
|
- // };
|
|
|
|
- // await client.GetContainer("TEAMModelOS", "School").UpsertItemAsync<ActivityData>(dataa, new Azure.Cosmos.PartitionKey(dataa.code));
|
|
|
|
- //}
|
|
|
|
- //else if (info.scope == "private")
|
|
|
|
- //{
|
|
|
|
- // dataa = new ActivityData
|
|
|
|
- // {
|
|
|
|
- // id = info.id,
|
|
|
|
- // code = $"Activity-Common",
|
|
|
|
- // type = "exam",
|
|
|
|
- // name = info.name,
|
|
|
|
- // startTime = info.startTime,
|
|
|
|
- // endTime = info.endTime,
|
|
|
|
- // scode = info.code,
|
|
|
|
- // scope = info.scope,
|
|
|
|
- // progress = "going",
|
|
|
|
- // classes = info.classes.IsNotEmpty() ? info.classes : new List<string> { "" },
|
|
|
|
- // tmdids = new List<string> { "" },
|
|
|
|
- // subjects = sub
|
|
|
|
- // };
|
|
|
|
- // await client.GetContainer("TEAMModelOS", "Teacher").UpsertItemAsync<ActivityData>(dataa, new Azure.Cosmos.PartitionKey(dataa.code));
|
|
|
|
- //}
|
|
|
|
-
|
|
|
|
(List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
(List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
List<StuActivity> stuActivities = new List<StuActivity>();
|
|
List<StuActivity> stuActivities = new List<StuActivity>();
|
|
List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
@@ -124,7 +89,8 @@ namespace TEAMModelFunction
|
|
scope = info.scope,
|
|
scope = info.scope,
|
|
school = info.school,
|
|
school = info.school,
|
|
creatorId = info.creatorId,
|
|
creatorId = info.creatorId,
|
|
- subjects = sub
|
|
|
|
|
|
+ subjects = sub,
|
|
|
|
+ blob = null
|
|
|
|
|
|
});
|
|
});
|
|
});
|
|
});
|
|
@@ -145,7 +111,8 @@ namespace TEAMModelFunction
|
|
scope = info.scope,
|
|
scope = info.scope,
|
|
school = info.school,
|
|
school = info.school,
|
|
creatorId = info.creatorId,
|
|
creatorId = info.creatorId,
|
|
- subjects = sub
|
|
|
|
|
|
+ subjects = sub,
|
|
|
|
+ blob=null
|
|
});
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -160,33 +127,170 @@ namespace TEAMModelFunction
|
|
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
|
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
|
ILogger log)
|
|
ILogger log)
|
|
{
|
|
{
|
|
- log.LogInformation("C# HTTP trigger function processed a request.1");
|
|
|
|
- string name = req.Query["name"];
|
|
|
|
|
|
+
|
|
|
|
+ log.LogInformation("fix-vote-activity...");
|
|
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
- dynamic data = JsonConvert.DeserializeObject(requestBody);
|
|
|
|
- log.LogInformation($"{data}");
|
|
|
|
- name = name ?? data?.name;
|
|
|
|
|
|
+ List<string> datas = JsonConvert.DeserializeObject<List<string>>(requestBody);
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
|
|
- 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);
|
|
|
|
|
|
+ var query = $"select * from c ";
|
|
|
|
+ foreach (string data in datas)
|
|
|
|
+ {
|
|
|
|
+ List<Vote> votes = new List<Vote>();
|
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
|
+ queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Vote-{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())
|
|
|
|
+ {
|
|
|
|
+ votes.Add(obj.ToObject<Vote>());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ log.LogInformation($"{votes.ToJsonString()}");
|
|
|
|
+ foreach (var info in votes)
|
|
|
|
+ {
|
|
|
|
+ if (info.classes.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
|
|
+ List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
|
+ List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
|
+ if (tmdids.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ tmdids.ForEach(x => {
|
|
|
|
+ tmdActivities.Add(new StuActivity
|
|
|
|
+ {
|
|
|
|
+ pk = "Activity",
|
|
|
|
+ id = info.id,
|
|
|
|
+ code = $"Activity-{x}",
|
|
|
|
+ type = "vote",
|
|
|
|
+ name = info.name,
|
|
|
|
+ startTime = info.startTime,
|
|
|
|
+ endTime = info.endTime,
|
|
|
|
+ scode = info.code,
|
|
|
|
+ scope = info.scope,
|
|
|
|
+ school = info.school,
|
|
|
|
+ creatorId = info.creatorId,
|
|
|
|
+ subjects = new List<string>() { "" },
|
|
|
|
+ blob = null
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (studentss.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ studentss.ForEach(x => {
|
|
|
|
+ stuActivities.Add(new StuActivity
|
|
|
|
+ {
|
|
|
|
+ pk = "Activity",
|
|
|
|
+ id = info.id,
|
|
|
|
+ code = $"Activity-{info.school}-{x.id}",
|
|
|
|
+ type = "vote",
|
|
|
|
+ name = info.name,
|
|
|
|
+ startTime = info.startTime,
|
|
|
|
+ endTime = info.endTime,
|
|
|
|
+ scode = info.code,
|
|
|
|
+ scope = info.scope,
|
|
|
|
+ school = info.school,
|
|
|
|
+ creatorId = info.creatorId,
|
|
|
|
+ subjects = new List<string>() { "" },
|
|
|
|
+ blob = null
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return new OkObjectResult(new { });
|
|
}
|
|
}
|
|
[FunctionName("fix-survey-activity")]
|
|
[FunctionName("fix-survey-activity")]
|
|
public async Task<IActionResult> SurveyActivity(
|
|
public async Task<IActionResult> SurveyActivity(
|
|
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
|
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
|
|
ILogger log)
|
|
ILogger log)
|
|
{
|
|
{
|
|
- log.LogInformation("C# HTTP trigger function processed a request.1");
|
|
|
|
- string name = req.Query["name"];
|
|
|
|
|
|
+ log.LogInformation("fix-survey-activity...");
|
|
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
|
|
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);
|
|
|
|
|
|
+ List<string> datas = JsonConvert.DeserializeObject<List<string>>(requestBody);
|
|
|
|
+ var client = _azureCosmos.GetCosmosClient();
|
|
|
|
+
|
|
|
|
+ var query = $"select * from c ";
|
|
|
|
+ foreach (string data in datas)
|
|
|
|
+ {
|
|
|
|
+ List<Survey> surveys = new List<Survey>();
|
|
|
|
+ await foreach (var item in client.GetContainer("TEAMModelOS", "Common").GetItemQueryStreamIterator(
|
|
|
|
+ queryText: query, requestOptions: new QueryRequestOptions() { PartitionKey = new PartitionKey($"Survey-{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())
|
|
|
|
+ {
|
|
|
|
+ surveys.Add(obj.ToObject<Survey>());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ log.LogInformation($"{surveys.ToJsonString()}");
|
|
|
|
+ foreach (var info in surveys)
|
|
|
|
+ {
|
|
|
|
+ if (info.classes.IsEmpty())
|
|
|
|
+ {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ (List<string> tmdids, List<Students> studentss) = await TriggerStuActivity.GetStuList(client, info.classes, info.school);
|
|
|
|
+ List<StuActivity> stuActivities = new List<StuActivity>();
|
|
|
|
+ List<StuActivity> tmdActivities = new List<StuActivity>();
|
|
|
|
+ if (tmdids.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ tmdids.ForEach(x => {
|
|
|
|
+ tmdActivities.Add(new StuActivity
|
|
|
|
+ {
|
|
|
|
+ pk = "Activity",
|
|
|
|
+ id = info.id,
|
|
|
|
+ code = $"Activity-{x}",
|
|
|
|
+ type = "survey",
|
|
|
|
+ name = info.name,
|
|
|
|
+ startTime = info.startTime,
|
|
|
|
+ endTime = info.endTime,
|
|
|
|
+ scode = info.code,
|
|
|
|
+ scope = info.scope,
|
|
|
|
+ school = info.school,
|
|
|
|
+ creatorId = info.creatorId,
|
|
|
|
+ subjects = new List<string>() { "" },
|
|
|
|
+ blob = info.blob
|
|
|
|
+
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ if (studentss.IsNotEmpty())
|
|
|
|
+ {
|
|
|
|
+ studentss.ForEach(x => {
|
|
|
|
+ stuActivities.Add(new StuActivity
|
|
|
|
+ {
|
|
|
|
+ pk = "Activity",
|
|
|
|
+ id = info.id,
|
|
|
|
+ code = $"Activity-{info.school}-{x.id}",
|
|
|
|
+ type = "survey",
|
|
|
|
+ name = info.name,
|
|
|
|
+ startTime = info.startTime,
|
|
|
|
+ endTime = info.endTime,
|
|
|
|
+ scode = info.code,
|
|
|
|
+ scope = info.scope,
|
|
|
|
+ school = info.school,
|
|
|
|
+ creatorId = info.creatorId,
|
|
|
|
+ subjects = new List<string>() { "" },
|
|
|
|
+ blob=info.blob
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ await TriggerStuActivity.SaveStuActivity(client, stuActivities, tmdActivities);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return new OkObjectResult(new { });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|