diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.cs b/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.cs index 4002a7b..72e56c4 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.cs +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.cs @@ -163,6 +163,84 @@ public virtual async System.Threading.Tasks.Task Up } } + /// Success + /// A server side error occurred. + public virtual System.Threading.Tasks.Task GetByIdAndPasswordAsync(GetByIdAndPasswordRequestContract body) + { + return GetByIdAndPasswordAsync(body, System.Threading.CancellationToken.None); + } + + /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. + /// Success + /// A server side error occurred. + public virtual async System.Threading.Tasks.Task GetByIdAndPasswordAsync(GetByIdAndPasswordRequestContract body, System.Threading.CancellationToken cancellationToken) + { + var urlBuilder_ = new System.Text.StringBuilder(); + urlBuilder_.Append(BaseUrl != null ? BaseUrl.TrimEnd('/') : "").Append("/api/File/GetByIdAndPassword"); + + var client_ = _httpClient; + var disposeClient_ = false; + try + { + using (var request_ = await CreateHttpRequestMessageAsync(cancellationToken).ConfigureAwait(false)) + { + var json_ = Newtonsoft.Json.JsonConvert.SerializeObject(body, _settings.Value); + var content_ = new System.Net.Http.StringContent(json_); + content_.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); + request_.Content = content_; + request_.Method = new System.Net.Http.HttpMethod("POST"); + request_.Headers.Accept.Add(System.Net.Http.Headers.MediaTypeWithQualityHeaderValue.Parse("text/plain")); + + PrepareRequest(client_, request_, urlBuilder_); + + var url_ = urlBuilder_.ToString(); + request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); + + PrepareRequest(client_, request_, url_); + + var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); + var disposeResponse_ = true; + try + { + var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); + if (response_.Content != null && response_.Content.Headers != null) + { + foreach (var item_ in response_.Content.Headers) + headers_[item_.Key] = item_.Value; + } + + ProcessResponse(client_, response_); + + var status_ = (int)response_.StatusCode; + if (status_ == 200) + { + var objectResponse_ = await ReadObjectResponseAsync(response_, headers_, cancellationToken).ConfigureAwait(false); + if (objectResponse_.Object == null) + { + throw new ApiException("Response was null which was not expected.", status_, objectResponse_.Text, headers_, null); + } + return objectResponse_.Object; + } + else + { + var responseData_ = response_.Content == null ? null : await response_.Content.ReadAsStringAsync().ConfigureAwait(false); + throw new ApiException("The HTTP status code of the response was not expected (" + status_ + ").", status_, responseData_, headers_, null); + } + } + finally + { + if (disposeResponse_) + response_.Dispose(); + } + } + } + finally + { + if (disposeClient_) + client_.Dispose(); + } + } + /// Success /// A server side error occurred. public virtual System.Threading.Tasks.Task GetByKeyAndUniqueIdentityAsync(GetByKeyRequestContract body) @@ -4511,6 +4589,52 @@ protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.Cal } } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] + public partial class GetByIdAndPasswordRequestContract : System.ComponentModel.INotifyPropertyChanged + { + private long _id; + private string _password; + + [Newtonsoft.Json.JsonProperty("id", Required = Newtonsoft.Json.Required.DisallowNull, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public long Id + { + get { return _id; } + + set + { + if (_id != value) + { + _id = value; + RaisePropertyChanged(); + } + } + } + + [Newtonsoft.Json.JsonProperty("password", Required = Newtonsoft.Json.Required.Default, NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore)] + public string Password + { + get { return _password; } + + set + { + if (_password != value) + { + _password = value; + RaisePropertyChanged(); + } + } + } + + public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged; + + protected virtual void RaisePropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null) + { + var handler = PropertyChanged; + if (handler != null) + handler(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName)); + } + } + [System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "13.19.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.3.0))")] public partial class GetByKeyRequestContract : System.ComponentModel.INotifyPropertyChanged { diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.nswag.json b/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.nswag.json index 54a9b93..f17e775 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.nswag.json +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/Connected Services/StorageGeneratedServices/OpenAPI.nswag.json @@ -78,6 +78,55 @@ } } }, + "/api/File/GetByIdAndPassword": { + "post": { + "tags": [ + "File" + ], + "operationId": "GetByIdAndPassword", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetByIdAndPasswordRequestContract" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/GetByIdAndPasswordRequestContract" + } + }, + "application/*+json": { + "schema": { + "$ref": "#/components/schemas/GetByIdAndPasswordRequestContract" + } + } + } + }, + "responses": { + "200": { + "description": "Success", + "content": { + "text/plain": { + "schema": { + "$ref": "#/components/schemas/FileContractMessageContract" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/FileContractMessageContract" + } + }, + "text/json": { + "schema": { + "$ref": "#/components/schemas/FileContractMessageContract" + } + } + } + } + } + } + }, "/api/File/GetByKeyAndUniqueIdentity": { "post": { "tags": [ @@ -2229,6 +2278,20 @@ } } }, + "GetByIdAndPasswordRequestContract": { + "type": "object", + "additionalProperties": false, + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "password": { + "type": "string", + "nullable": true + } + } + }, "GetByKeyRequestContract": { "type": "object", "additionalProperties": false, diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/EasyMicroservices.StorageMicroservice.Clients.csproj b/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/EasyMicroservices.StorageMicroservice.Clients.csproj index a9666fc..5a8b91c 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/EasyMicroservices.StorageMicroservice.Clients.csproj +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.Clients/EasyMicroservices.StorageMicroservice.Clients.csproj @@ -5,7 +5,7 @@ AnyCPU;x64;x86 EasyMicroservices true - 0.0.0.10 + 0.0.0.11 client generated code. EasyMicroservices@gmail.com storage, microservice, easymicroservice diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/Contracts/Requests/GetByIdAndPasswordRequestContract.cs b/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/Contracts/Requests/GetByIdAndPasswordRequestContract.cs new file mode 100644 index 0000000..db853cc --- /dev/null +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/Contracts/Requests/GetByIdAndPasswordRequestContract.cs @@ -0,0 +1,6 @@ +namespace EasyMicroservices.StorageMicroservice.Contracts.Requests; +public class GetByIdAndPasswordRequestContract +{ + public long Id { get; set; } + public string Password { get; set; } +} diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/EasyMicroservices.StorageMicroservice.Domain.csproj b/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/EasyMicroservices.StorageMicroservice.Domain.csproj index 239df64..c26a0d4 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/EasyMicroservices.StorageMicroservice.Domain.csproj +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.Domain/EasyMicroservices.StorageMicroservice.Domain.csproj @@ -12,7 +12,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.Logics/EasyMicroservices.StorageMicroservice.Logics.csproj b/src/CSharp/EasyMicroservices.StorageMicroservice.Logics/EasyMicroservices.StorageMicroservice.Logics.csproj index 6ff3848..0051530 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.Logics/EasyMicroservices.StorageMicroservice.Logics.csproj +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.Logics/EasyMicroservices.StorageMicroservice.Logics.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Controllers/FileController.cs b/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Controllers/FileController.cs index f628302..335edd1 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Controllers/FileController.cs +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Controllers/FileController.cs @@ -1,13 +1,12 @@ using EasyMicroservices.ContentsMicroservice.Helpers; using EasyMicroservices.Cores.AspCoreApi; -using EasyMicroservices.Cores.AspEntityFrameworkCoreApi.Interfaces; -using EasyMicroservices.Cores.Database.Interfaces; using EasyMicroservices.FileManager.Interfaces; using EasyMicroservices.ServiceContracts; using EasyMicroservices.StorageMicroservice.Contracts; using EasyMicroservices.StorageMicroservice.Contracts.Requests; using EasyMicroservices.StorageMicroservice.Database.Entities; using EasyMicroservices.StorageMicroservice.Logics; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace EasyMicroservices.StorageMicroservice.Controllers @@ -77,6 +76,14 @@ public async Task> UploadFile([FromForm] AddFileRe return errorContract; } + [HttpPost] + [AllowAnonymous] + public Task> GetByIdAndPassword(GetByIdAndPasswordRequestContract request, CancellationToken cancellationToken = default) + { + return _unitOfWork.GetLongContractLogic() + .GetBy(x => x.Id == request.Id && x.Password == request.Password, cancellationToken: cancellationToken); + } + [HttpPost] public async Task> GetByKeyAndUniqueIdentity(GetByKeyRequestContract request, CancellationToken cancellationToken = default) { diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/EasyMicroservices.StorageMicroservice.WebApi.csproj b/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/EasyMicroservices.StorageMicroservice.WebApi.csproj index 08d3326..919d9f9 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/EasyMicroservices.StorageMicroservice.WebApi.csproj +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/EasyMicroservices.StorageMicroservice.WebApi.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Program.cs b/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Program.cs index a6c75ac..b2a199e 100644 --- a/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Program.cs +++ b/src/CSharp/EasyMicroservices.StorageMicroservice.WebApi/Program.cs @@ -32,6 +32,7 @@ static WebApplicationBuilder CreateBuilder(string[] args) app.Services.AddScoped(serviceProvider => new DiskDirectoryProvider(webRootPath)); app.Services.AddTransient(serviceProvider => new DiskFileProvider(new DiskDirectoryProvider(webRootPath))); StartUpExtensions.AddWhiteLabel("Storage", "RootAddresses:WhiteLabel"); + StartUpExtensions.AddAuthentication("RootAddresses:Authentication"); return app; } }