59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
using Common.Dtos.Prompt;
|
|
using System.Net.Http.Json;
|
|
|
|
namespace HushianWebApp.Service
|
|
{
|
|
public class PromptService
|
|
{
|
|
private readonly BaseController _baseController;
|
|
const string BaseRoute = "v1/Prompt/";
|
|
|
|
public PromptService(BaseController baseController)
|
|
{
|
|
_baseController = baseController;
|
|
}
|
|
|
|
public async Task<bool> AddPrompt(ADD_PromptDto model)
|
|
{
|
|
var response = await _baseController.Post($"{BaseRoute}AddPrompt", model);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public async Task<bool> UpdatePrompt(ReadANDUpdate_PromptDto model)
|
|
{
|
|
var response = await _baseController.Put($"{BaseRoute}UpdatePrompt", model);
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public async Task<bool> DeletePrompt(int id)
|
|
{
|
|
var response = await _baseController.Delete($"{BaseRoute}DeletePrompt/{id}");
|
|
return response.IsSuccessStatusCode;
|
|
}
|
|
|
|
public async Task<ReadANDUpdate_PromptDto?> GetPrompt(int id)
|
|
{
|
|
var response = await _baseController.Get($"{BaseRoute}GetPrompt/{id}");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return await response.Content.ReadFromJsonAsync<ReadANDUpdate_PromptDto>();
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public async Task<List<ReadANDUpdate_PromptDto>> GetPrompts()
|
|
{
|
|
var response = await _baseController.Get($"{BaseRoute}GetPrompts");
|
|
if (response.IsSuccessStatusCode)
|
|
{
|
|
return await response.Content.ReadFromJsonAsync<List<ReadANDUpdate_PromptDto>>() ?? new();
|
|
}
|
|
return new();
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|