123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- using AipGateway.AIP;
- using AipGateway.API.Application.Modules;
- using AipGateway.API.Domain.IRepositories.IGenericRepositories;
- using AipGateway.API.Domain.Models;
- using AipGateway.API.Domain.Models.Request;
- using AipGateway.API.Domain.Models.Response;
- using AipGateway.API.Extensions;
- using AipGateway.API.Services;
- using Microsoft.AspNetCore.Mvc;
- using Swashbuckle.AspNetCore.Annotations;
- namespace AipGateway.API.Controllers
- {
- [ApiController]
- [Route("v1/aip-api/stream")]
- [Produces("application/json")]
- public class ApiStreamController : BaseModule
- {
- private readonly ILogger<ApiStreamController> _log;
- private readonly IApiStreamService _apiStreamService;
- public ApiStreamController(
- ILogger<ApiStreamController> logger,
- IUnitOfWork unitOfWork,
- IWebHostEnvironment webHostEnvironment,
- IApiStreamService apiStreamService)
- : base(unitOfWork, webHostEnvironment)
- {
- _log = logger;
- _apiStreamService = apiStreamService;
- _log.LogError("ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo: ApiStreamController");
- }
- [HttpPost("info")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseInfo>))]
- public async Task<IResult> GetInfo([FromBody] RequestStream req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_INFO, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.GetInfo(req);
- var data = new SuccessResponseModel<ResponseInfo>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- [HttpPost("set-label")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseStream>))]
- public async Task<IResult> SetLabel([FromBody] RequestStreamSet req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_SET_LABEL, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.SetLabel(req);
- var data = new SuccessResponseModel<ResponseStream>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- [HttpPost("delete-label")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseStream>))]
- public async Task<IResult> DelLabel([FromBody] RequestStreamDel req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_DELETE_LABEL, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.DelLabel(req);
- var data = new SuccessResponseModel<ResponseStream>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- [HttpPost("set-protection")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseStream>))]
- public async Task<IResult> SetProtection([FromBody] RequestStreamSet req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_SET_PROTECTION, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.SetProtection(req);
- var data = new SuccessResponseModel<ResponseStream>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- [HttpPost("delete-protection")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseStream>))]
- public async Task<IResult> DelProtection([FromBody] RequestStreamDel req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_DELETE_PROTECTIN, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.DelProtection(req);
- var data = new SuccessResponseModel<ResponseStream>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- [HttpPost("set-label-protection")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseStream>))]
- public async Task<IResult> SetLabelProtection([FromBody] RequestStreamAllSet req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_SET_LABEL_PROTECTION, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.SetLabelProtection(req);
- var data = new SuccessResponseModel<ResponseStream>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- [HttpPost("delete-label-protection")]
- [SwaggerResponse(200, type: typeof(SuccessResponseModel<ResponseStream>))]
- public async Task<IResult> DelLabelProtection([FromBody] RequestStreamDel req)
- {
- GlobalConstants.SetAuthorization(HttpContext, GlobalConstants.API_STREAM_DELETE_LABEL_PROTECTION, req.apiKey);
- req.apiGuid = GlobalConstants.GetApiGuid(HttpContext);
- HttpContext.Items[GlobalConstants.API_REQUEST] = (RequestBase)req;
- return await CreateResponseAsync(async () =>
- {
- int authError = ContainerService.ValidationApiAuthorization(HttpContext, req.apiKey);
- if (authError != 0)
- {
- throw ContainerService.CreateValidationApiAuthorizationAsync(HttpContext, authError);
- }
- var response = await _apiStreamService.DelLabelProtection(req);
- var data = new SuccessResponseModel<ResponseStream>()
- {
- Message = GlobalConstants.API_RESULT_SUCCESS,
- Result = response,
- StatusCode = System.Net.HttpStatusCode.OK,
- Success = true
- };
- var result = Results.Ok(data);
- HttpContext.Items.Add(GlobalConstants.API_RESULT, (ResponseBase)data.Result);
- return result;
- });
- }
- }
- }
|