-2
I’m starting to learn C#, using . NET CORE, and I’m trying to create an API that searches a Mongodb bank.
I’ve looked at some topics here, seen some things, but none of the solutions I found worked.
I created a class called Searchparameter to be able to receive the search parameters, but when I try to do the same in Insominia it returns the following:
I can’t understand what’s going on. They follow the classes.
Searchparametrs:
public class SearchParameters
{
// Propriedes
[Required(ErrorMessage = "É necessário informar um parâmetro de busca.")]
[JsonProperty("ticketField")]
public string ticketField { get; set; } // representa o campo do ticket que será utilizado para busca.
[Required(ErrorMessage = "É necessário informar um parâmetro de comparação.")]
[JsonProperty("comparationParameter")]
public string comparationParameter { get; set; } // representa o parâmetro de comparação, se o valor a ser buscado é IGUAL ou DIFERENTE do ticketField.
[JsonProperty("initialDate")]
public DateTime initialDate { get; set; } // representa a data incial de um período a ser pequisado.
[JsonProperty("finalDate")]
public DateTime finalDate { get; set; } // representa a data final de um período a ser pesquisado.
}
CONTROLLER start, which defines the route:
[ApiController]
[Route("v1/archivedTickets")]
public class ArchivedTicketsController : ControllerBase
{...}
GET CONTROLLER METHOD:
[HttpGet]
[Route("getByChannelName/{searchParameters}")]
public IActionResult getByChannelName(SearchParameters searchParameters)
{
try
{
return Ok(_repository.GetByChannelName(searchParameters));
}
catch (Exception exc)
{
return null;
}
}
Method that performs the search in the REPOSITORY:
public List<ArchivedTicketsModel> GetByChannelName(SearchParameters searchParameters)
{
return _collection.Find(archivedTicket => archivedTicket.ChannelName == searchParameters.ticketField && archivedTicket.DateCreation >= searchParameters.initialDate && archivedTicket.DateCreation <= searchParameters.finalDate).ToList();
}
I put a breakpoint in the CONTROLLER class to debug, but Insominia returns this message without even entering the GET method.
I’m testing on a localhost, which is my base_url. You have already received the parameters separately, and it worked, but the JSON object will not, and I want to receive this object as parameter.
Gave straight! Thank you so much for your help!!
– Matheus Molina