API Listing Issue

Viewed 27

I have created an API for the ASP.NET Core project.

below code shows a method of me listing out my data from the API.

Controller.cs

[HttpGet(ApiRoutes.Testing.ListTesting)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public async Task<IActionResult> List()
{
    if (!ModelState.IsValid)
    {
        return BadRequest(ModelState);
    }

    try
    {
        var list = await _testingComponent.GetTestingListsAsync();

        return Ok(list);
    }
    catch (Exception e)
    {
        _logger.LogError("Error happened when displaying safe truck transaction: {0}", e.Message);

        return StatusCode(500, "Internal Server Error. Please Try Again Later");
    }
}

TestingComponent.cs

public async Task<List<TestingListResponse>> GetTestingListsAsync()
{
    await using var dbContext = GetDbContext();

    var list = dbContext.Testing.AsNoTracking();

    var result = await _resultProjector.ProjectListAsync<TestingListResponse, Testing>(List);

    return result;
}

Howeever, it shows an error - "Testing should detect as a namespace but it acts more like a type"

Testing>();

May I know how to solve that?

0 Answers
Related