Skip to content

Commit

Permalink
Merge pull request #30 from Ali-YousefiTelori/develop
Browse files Browse the repository at this point in the history
Support for GetByIdAndPassword
  • Loading branch information
Ali-YousefiTelori authored Dec 13, 2023
2 parents 8ad165e + bfacadb commit 73a29cc
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,84 @@ public virtual async System.Threading.Tasks.Task<FileContractMessageContract> Up
}
}

/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<FileContractMessageContract> GetByIdAndPasswordAsync(GetByIdAndPasswordRequestContract body)
{
return GetByIdAndPasswordAsync(body, System.Threading.CancellationToken.None);
}

/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual async System.Threading.Tasks.Task<FileContractMessageContract> 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<FileContractMessageContract>(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();
}
}

/// <returns>Success</returns>
/// <exception cref="ApiException">A server side error occurred.</exception>
public virtual System.Threading.Tasks.Task<FileContractMessageContract> GetByKeyAndUniqueIdentityAsync(GetByKeyRequestContract body)
Expand Down Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Platforms>AnyCPU;x64;x86</Platforms>
<Authors>EasyMicroservices</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.0.0.10</Version>
<Version>0.0.0.11</Version>
<Description>client generated code.</Description>
<Copyright>[email protected]</Copyright>
<PackageTags>storage, microservice, easymicroservice</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace EasyMicroservices.StorageMicroservice.Contracts.Requests;
public class GetByIdAndPasswordRequestContract
{
public long Id { get; set; }
public string Password { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="5.0.17" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.61" />
<PackageReference Include="EasyMicroservices.Cores.AspEntityFrameworkCoreApi" Version="0.0.0.64" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="EasyMicroservices.FileManager" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Mapper.CompileTimeMapper" Version="0.0.0.6" />
<PackageReference Include="EasyMicroservices.Mapper.SerializerMapper" Version="0.0.0.3" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.8" />
<PackageReference Include="EasyMicroservices.Serialization.Newtonsoft.Json" Version="0.0.0.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -77,6 +76,14 @@ public async Task<MessageContract<FileContract>> UploadFile([FromForm] AddFileRe
return errorContract;
}

[HttpPost]
[AllowAnonymous]
public Task<MessageContract<FileContract>> GetByIdAndPassword(GetByIdAndPasswordRequestContract request, CancellationToken cancellationToken = default)
{
return _unitOfWork.GetLongContractLogic<FileEntity, FileContract>()
.GetBy(x => x.Id == request.Id && x.Password == request.Password, cancellationToken: cancellationToken);
}

[HttpPost]
public async Task<MessageContract<FileContract>> GetByKeyAndUniqueIdentity(GetByKeyRequestContract request, CancellationToken cancellationToken = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EasyMicroservices.Cores.AspCoreApi" Version="0.0.0.61" />
<PackageReference Include="EasyMicroservices.Cores.AspCoreApi" Version="0.0.0.64" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.14">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static WebApplicationBuilder CreateBuilder(string[] args)
app.Services.AddScoped<IDirectoryManagerProvider>(serviceProvider => new DiskDirectoryProvider(webRootPath));
app.Services.AddTransient<IFileManagerProvider>(serviceProvider => new DiskFileProvider(new DiskDirectoryProvider(webRootPath)));
StartUpExtensions.AddWhiteLabel("Storage", "RootAddresses:WhiteLabel");
StartUpExtensions.AddAuthentication("RootAddresses:Authentication");
return app;
}
}
Expand Down

0 comments on commit 73a29cc

Please sign in to comment.