Some other func

This commit is contained in:
2025-01-06 08:58:17 +01:00
parent 8bbcbfab09
commit a80870b5c3
9 changed files with 118 additions and 19 deletions
+2 -1
View File
@@ -2,7 +2,8 @@
<PropertyGroup> <PropertyGroup>
<!--Work around so the conditions work below--> <!--Work around so the conditions work below-->
<TargetFrameworks>netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid10.0;net8.0;net8.0-android;net8.0-ios</TargetFrameworks> <!--<TargetFrameworks>netstandard1.0;netstandard2.0;Xamarin.iOS10;MonoAndroid10.0;net8.0;net8.0-android;net8.0-ios</TargetFrameworks>-->
<TargetFrameworks>net8.0;net8.0-android;net8.0-ios</TargetFrameworks>
<AssemblyName>Plugin.NFC</AssemblyName> <AssemblyName>Plugin.NFC</AssemblyName>
<RootNamespace>Plugin.NFC</RootNamespace> <RootNamespace>Plugin.NFC</RootNamespace>
@@ -9,9 +9,15 @@ namespace WorkFlowCheck.API.Controllers
public class UserController : ControllerBase public class UserController : ControllerBase
{ {
[HttpGet] [HttpGet]
public ActionResult<ResponseDTO> Get() public async Task<ApiResponseDTO<UserDTO>> Get()
{ {
return new ResponseDTO { Message = "Success" }; var userDTO = new UserDTO() { Id = 1, Email = "email", Name = "Name" };
var retVal = new ApiResponseDTO<UserDTO>()
{
IsSuccess = true,
Data = userDTO
};
return retVal;
} }
} }
} }
+7 -5
View File
@@ -4,6 +4,7 @@ using System.Text.Json;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using WorkFlowCheck.API; using WorkFlowCheck.API;
using WorkFlowCheck.DL; using WorkFlowCheck.DL;
using Microsoft.AspNetCore.Mvc;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@@ -45,12 +46,13 @@ builder.Services.AddSwaggerGen(c =>
}); });
}); });
// Szolgáltatások hozzáadása builder.Services.AddControllers()
builder.Services.AddControllers().AddJsonOptions(options => .AddNewtonsoftJson(options =>
{ {
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; // Itt konfigurálhatod az egyedi beállításokat
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
}); ; options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
var app = builder.Build(); var app = builder.Build();
// Swagger middleware // Swagger middleware
@@ -14,6 +14,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.11" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup> </ItemGroup>
@@ -0,0 +1,39 @@
using System.Text.Json.Serialization;
namespace WorkFlowCheck.BL.DTO
{
public class ApiResponseBaseDTO
{
public bool IsSuccess { get; set; }
public IEnumerable<string> Errors { get; set; }
public bool HandleError { get; set; }
public string Error
{
get
{
if (Errors == null || Errors.Count() == 0) return string.Empty;
return string.Join(';', Errors);
}
}
}
public class ApiResponseDTO : ApiResponseBaseDTO
{
public object Data { get; set; }
}
public interface IApiResponseDTO<out T>
{
}
public class ApiResponseDTO<T> : ApiResponseBaseDTO, IApiResponseDTO<T>
{
public T Data { get; set; }
}
public class ApiResponseListDTO<T> : ApiResponseBaseDTO
{
public T[] Data { get; set; }
public int Total { get; set; }
}
}
-10
View File
@@ -1,10 +0,0 @@
using System.Text.Json.Serialization;
namespace WorkFlowCheck.BL.DTO
{
[JsonSerializable(typeof(ResponseDTO))]
public class ResponseDTO
{
public string Message { get; set; } = null!;
}
}
+9
View File
@@ -0,0 +1,9 @@
namespace WorkFlowCheck.BL.DTO
{
public class UserDTO
{
public int Id { get; set; }
public string Name { get; set; } = null!;
public string Email { get; set; } = null!;
}
}
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Json;
using System.Text;
using System.Threading.Tasks;
using WorkFlowCheck.BL.DTO;
namespace WorkFlowCheck.MAUI.Services
{
public class UserService
{
private readonly HttpClient _httpClient;
public UserService(HttpClient httpClient)
{
_httpClient = httpClient;
// Alapértelmezett fejléc beállítása az API-kulccsal
_httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_KEY");
// Ha egyéni fejlécet használsz:
// _httpClient.DefaultRequestHeaders.Add("X-Api-Key", "YOUR_API_KEY");
}
public async Task<ApiResponseDTO<UserDTO>> GetUserAsync()
{
try
{
// Az API végpont meghatározása
string endpoint = "api/user";
// HTTP GET kérés küldése
var response = await _httpClient.GetFromJsonAsync<ApiResponseDTO<UserDTO>>(endpoint);
return response ?? new ApiResponseDTO<UserDTO>
{
IsSuccess = false,
};
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<UserDTO>
{
IsSuccess = false
};
}
}
}
}
@@ -57,6 +57,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" /> <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" /> <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.1" />
@@ -64,6 +66,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Plugin.NFC\Plugin.NFC.csproj" /> <ProjectReference Include="..\Plugin.NFC\Plugin.NFC.csproj" />
<ProjectReference Include="..\WorkFlowCheck.BL\WorkFlowCheck.BL.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>