Még csak lépések vannak ...

This commit is contained in:
2025-03-03 17:03:41 +01:00
parent 2ad8ba2d51
commit 1e9fdf7ea5
5 changed files with 43 additions and 12 deletions
@@ -1,10 +1,7 @@
using AutoMapper;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System.Net.Http.Json;
using WorkFlowCheck.Common.DTO;
using WorkFlowCheck.MAUI.DataLayer;
using WorkFlowCheck.MAUI.Services.Interfaces;
@@ -14,14 +11,45 @@ namespace WorkFlowCheck.MAUI.Services
public class CheckListService : BaseService, ICheckListService
{
private readonly IUserService _userService;
public CheckListService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper, IUserService userService ) : base(httpClient, configuration, dbContext, mapper)
public CheckListService(HttpClient httpClient, IConfiguration configuration, AppDbContext dbContext, IMapper mapper, IUserService userService) : base(httpClient, configuration, dbContext, mapper)
{
_userService = userService;
}
public async Task StartNew(UserDTO userDTO)
public async Task<ApiResponseDTO<CheckListHeaderDTO>> StartNew(CheckListTemplateHeaderDTO checkListTemplateHeaderDTO)
{
try
{
// Az API végpont meghatározása
string endpoint = $"{_httpClient.BaseAddress}api/checklist/startnew";
// HTTP POST kérés küldése
ApiRequestDTO<CheckListTemplateHeaderDTO> request = new ApiRequestDTO<CheckListTemplateHeaderDTO>();
request.UserDTO = _userService.GetCurrentUser();
request.Data = checkListTemplateHeaderDTO;
using (HttpResponseMessage httpResponseMessage = await _httpClient.PostAsJsonAsync(endpoint, request))
{
httpResponseMessage.EnsureSuccessStatusCode();
var jsonString = await httpResponseMessage.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<ApiResponseDTO<CheckListHeaderDTO>>(jsonString);
return response ?? new ApiResponseDTO<CheckListHeaderDTO>
{
IsSuccess = false,
};
}
}
catch (Exception ex)
{
// Hiba visszaadása
return new ApiResponseDTO<CheckListHeaderDTO>
{
IsSuccess = false
};
}
}
}
}