|
@@ -19,6 +19,9 @@ using Microsoft.Extensions.Options;
|
|
|
using System.Net.Http;
|
|
|
using TEAMModelOS.SDK.Context.Configuration;
|
|
|
using System.Net;
|
|
|
+using Microsoft.Extensions.Configuration;
|
|
|
+using TEAMModelOS.SDK.Models.Service;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
|
|
|
namespace TEAMModelOS.Controllers
|
|
|
{
|
|
@@ -33,11 +36,15 @@ namespace TEAMModelOS.Controllers
|
|
|
private readonly AzureCosmosFactory _azureCosmos;
|
|
|
private readonly AzureStorageFactory _azureStorage;
|
|
|
private readonly Option _option;
|
|
|
- public SchoolTeacherController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option)
|
|
|
+ private readonly IConfiguration _configuration;
|
|
|
+ private readonly NotificationService _notificationService;
|
|
|
+ public SchoolTeacherController(AzureCosmosFactory azureCosmos, AzureStorageFactory azureStorage, IOptionsSnapshot<Option> option, IConfiguration configuration, NotificationService notificationService)
|
|
|
{
|
|
|
_azureCosmos = azureCosmos;
|
|
|
_azureStorage = azureStorage;
|
|
|
_option = option?.Value;
|
|
|
+ _configuration = configuration;
|
|
|
+ _notificationService = notificationService;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 取得學校所有老師(不論加入狀態)
|
|
@@ -194,8 +201,10 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
[HttpPost("add-teacher-status")]
|
|
|
+ [AuthToken(Roles = "teacher,admin")]
|
|
|
public async Task<IActionResult> AddSchoolTeacher(JsonElement request)
|
|
|
{
|
|
|
+ var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
|
|
|
var client = _azureCosmos.GetCosmosClient();
|
|
|
//參數取得
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
@@ -216,11 +225,13 @@ namespace TEAMModelOS.Controllers
|
|
|
}
|
|
|
try
|
|
|
{
|
|
|
+ List<TmdInfo> ids = new List<TmdInfo>();
|
|
|
foreach (var obj in user_list.EnumerateArray())
|
|
|
{
|
|
|
obj.TryGetProperty("id", out JsonElement id);
|
|
|
obj.TryGetProperty("name", out JsonElement name);
|
|
|
obj.TryGetProperty("picture", out JsonElement picture);
|
|
|
+ ids.Add(new TmdInfo { tmdid=$"{id}",tmdname=$"{name}" });
|
|
|
//老師個人資料
|
|
|
var tresponse = await client.GetContainer("TEAMModelOS", "Teacher").ReadItemStreamAsync(id.ToString(), new PartitionKey("Base"));
|
|
|
if(tresponse.Status == 200)
|
|
@@ -290,6 +301,26 @@ namespace TEAMModelOS.Controllers
|
|
|
await client.GetContainer("TEAMModelOS", "School").CreateItemStreamAsync(stream, new PartitionKey($"Teacher-{school_code}"));
|
|
|
}
|
|
|
}
|
|
|
+ string bizcode = grant_type.GetString();
|
|
|
+ if (grant_type.GetString() == "join")
|
|
|
+ {
|
|
|
+ bizcode = "request-join";
|
|
|
+ }
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{school_code}",
|
|
|
+ to = ids.Select(x => x.tmdid).ToList(),
|
|
|
+ label = $"{bizcode}_school",
|
|
|
+ body = new { biz = bizcode, tmdid = tid, tmdname = tname.ToString(), schoolcode = $"{school_code}", schoolname = $"{schname}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
return Ok(new { });
|
|
|
}
|
|
|
catch(Exception ex)
|
|
@@ -304,12 +335,13 @@ namespace TEAMModelOS.Controllers
|
|
|
/// <param name="request"></param>
|
|
|
/// <returns></returns>
|
|
|
[ProducesDefaultResponseType]
|
|
|
- //[AuthToken(Roles = "admin")]
|
|
|
+ [AuthToken(Roles = "admin")]
|
|
|
[HttpPost("upd-teacher-status")]
|
|
|
public async Task<IActionResult> UpdSchoolTeacherStatus(JsonElement request)
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
|
|
|
if (!request.TryGetProperty("grant_type", out JsonElement grant_type)) return BadRequest();
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
@@ -364,7 +396,26 @@ namespace TEAMModelOS.Controllers
|
|
|
};
|
|
|
var response = await client.GetContainer("TEAMModelOS", "School").CreateItemAsync(st, new PartitionKey($"Teacher-{school_code}"));
|
|
|
}
|
|
|
-
|
|
|
+ string bizcode = grant_type.GetString();
|
|
|
+ if (grant_type.GetString() == "join")
|
|
|
+ {
|
|
|
+ bizcode = "request-join";
|
|
|
+ }
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{school_code}",
|
|
|
+ to =new List<string> { teacher.id },
|
|
|
+ label = $"{bizcode}_school",
|
|
|
+ body = new { biz = bizcode, tmdid = tid, tmdname =tname, schoolcode = $"{school_code}", schoolname = $"{schname}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
return Ok(new { });
|
|
|
}
|
|
|
catch (Exception ex)
|
|
@@ -385,6 +436,7 @@ namespace TEAMModelOS.Controllers
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
+ var (tid, tname, _, tschool) = HttpContext.GetAuthTokenInfo();
|
|
|
if (!request.TryGetProperty("school_code", out JsonElement school_code)) return BadRequest();
|
|
|
if (!request.TryGetProperty("id", out JsonElement id)) return BadRequest();
|
|
|
|
|
@@ -395,7 +447,34 @@ namespace TEAMModelOS.Controllers
|
|
|
await client.GetContainer("TEAMModelOS", "Teacher").ReplaceItemAsync<Teacher>(teacher, id.ToString(), new PartitionKey("Base"));
|
|
|
//移除學校表中的老師document
|
|
|
var sresponse = await client.GetContainer("TEAMModelOS", "School").DeleteItemStreamAsync(id.GetString(), new PartitionKey($"Teacher-{school_code}"));
|
|
|
-
|
|
|
+ //取得學校資訊
|
|
|
+ var schresponse = await client.GetContainer("TEAMModelOS", "School").ReadItemStreamAsync(school_code.ToString(), new PartitionKey("Base"));
|
|
|
+ string schname = string.Empty;
|
|
|
+ if (schresponse.Status == 200)
|
|
|
+ {
|
|
|
+ using var schjson = await JsonDocument.ParseAsync(schresponse.ContentStream);
|
|
|
+ schjson.RootElement.TryGetProperty("name", out JsonElement jsonschname);
|
|
|
+ schname = jsonschname.ToString();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return BadRequest();
|
|
|
+ }
|
|
|
+ Notification notification = new Notification
|
|
|
+ {
|
|
|
+ hubName = "hita",
|
|
|
+ type = "msg",
|
|
|
+ from = $"ies5:{school_code}",
|
|
|
+ to = new List<string> { teacher.id },
|
|
|
+ label = $"remove_school",
|
|
|
+ body = new { biz = "remove", tmdid = tid, tmdname = tname, schoolcode = $"{school_code}", schoolname = $"{schname}", status = 1, time = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds() }.ToJsonString(),
|
|
|
+ expires = DateTimeOffset.UtcNow.AddDays(7).ToUnixTimeSeconds()
|
|
|
+ };
|
|
|
+ var url = _configuration.GetValue<string>("HaBookAuth:CoreService:sendnotification");
|
|
|
+ var clientID = _configuration.GetValue<string>("HaBookAuth:CoreService:clientID");
|
|
|
+ var clientSecret = _configuration.GetValue<string>("HaBookAuth:CoreService:clientSecret");
|
|
|
+ var location = _option.Location;
|
|
|
+ var code = await _notificationService.SendNotification(clientID, clientSecret, location, url, notification);
|
|
|
return Ok(new { });
|
|
|
}
|
|
|
catch (Exception ex)
|