|
@@ -0,0 +1,54 @@
|
|
|
+using Azure;
|
|
|
+using Microsoft.AspNetCore.Authorization;
|
|
|
+using Microsoft.AspNetCore.Mvc;
|
|
|
+using System;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using TEAMModelOS.Filter;
|
|
|
+using TEAMModelOS.Models.Request.HiTeachSideMenu;
|
|
|
+using TEAMModelOS.SDK.DI;
|
|
|
+using TEAMModelOS.Services;
|
|
|
+
|
|
|
+namespace TEAMModelOS.Controllers.HiTeachSideMenu.School
|
|
|
+{
|
|
|
+
|
|
|
+ [Route("hiTeachSideMenu/school/[controller]/[action]")]
|
|
|
+ [ApiController]
|
|
|
+ public class ContentController : ControllerBase
|
|
|
+ {
|
|
|
+ private readonly ContentService _contentService;
|
|
|
+
|
|
|
+ public ContentController(AzureStorageFactory azureStorage, AzureCosmosFactory azureCosmos)
|
|
|
+ {
|
|
|
+ _contentService = new ContentService(azureStorage, azureCosmos);
|
|
|
+ }
|
|
|
+
|
|
|
+ [AuthToken(Roles = "teacher,admin,student")]
|
|
|
+ [Authorize(Roles = "IES,HiTeach")]
|
|
|
+ public async Task<IActionResult> Upload([FromForm] UploadSchoolContentRequest request)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ if (!ModelState.IsValid)
|
|
|
+ {
|
|
|
+ return BadRequest(ModelState);
|
|
|
+ }
|
|
|
+
|
|
|
+ await _contentService.UploadToSchool(request.File, request.Id, request.PeriodId, request.SubjectId, request.GradeId);
|
|
|
+
|
|
|
+ return Ok();
|
|
|
+ }
|
|
|
+ catch (RequestFailedException ex)
|
|
|
+ {
|
|
|
+ if (ex.ErrorCode == "BlobAlreadyExists")
|
|
|
+ {
|
|
|
+ return BadRequest(new { message = "The file already exists." });
|
|
|
+ }
|
|
|
+ return StatusCode(500);
|
|
|
+ }
|
|
|
+ catch (Exception)
|
|
|
+ {
|
|
|
+ return StatusCode(500);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|