Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ This project uses famous football stadiums (A-Z) that hosted FIFA World Cup matc

### Fixed

- `GET /players` now returns `200 OK` with an empty list `[]` when no players exist, instead of `404 Not Found` (#425)
- AutoMapper `Player → PlayerResponseModel` profile now explicitly ignores the `Id` source member via `ForSourceMember`, making the exclusion intentional rather than implicit (#425)

### Removed

---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public async Task<IResult> PostAsync([FromBody] PlayerRequestModel player)
Title = "Conflict",
Status = StatusCodes.Status409Conflict,
Detail = $"Player with Squad Number '{player.SquadNumber}' already exists.",
Instance = HttpContext?.Request?.Path.ToString()
Instance = HttpContext?.Request?.Path.ToString(),
}
);
}
Expand All @@ -92,29 +92,15 @@ public async Task<IResult> PostAsync([FromBody] PlayerRequestModel player)
/// Retrieves all Players
/// </summary>
/// <response code="200">OK</response>
/// <response code="404">Not Found</response>
[HttpGet(Name = "Retrieve")]
[ProducesResponseType<PlayerResponseModel>(StatusCodes.Status200OK)]
[ProducesResponseType<ProblemDetails>(StatusCodes.Status404NotFound)]
public async Task<IResult> GetAsync()
{
var players = await playerService.RetrieveAsync();

if (players.Count > 0)
{
logger.LogInformation("GET /players retrieved");
return TypedResults.Ok(players);
}
else
{
logger.LogWarning("GET /players not found");
return TypedResults.Problem(
statusCode: StatusCodes.Status404NotFound,
title: NotFoundTitle,
detail: "No players were found.",
instance: HttpContext?.Request?.Path.ToString()
);
}
logger.LogInformation("GET /players retrieved {Count} player(s)", players.Count);

return TypedResults.Ok(players);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public PlayerMappingProfile()

// Player → PlayerResponseModel
CreateMap<Player, PlayerResponseModel>()
.ForSourceMember(source => source.Id, options => options.DoNotValidate())
.ForMember(
destination => destination.FullName,
options =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public async Task Get_Players_Existing_ReturnsPlayers()

[Fact]
[Trait("Category", "Unit")]
public async Task Get_Players_NonExisting_Returns404NotFound()
public async Task Get_Players_Empty_Returns200OkWithEmptyList()
{
// Arrange
var (service, logger, validator) = PlayerMocks.InitControllerMocks();
Expand All @@ -196,8 +196,9 @@ public async Task Get_Players_NonExisting_Returns404NotFound()

// Assert
service.Verify(service => service.RetrieveAsync(), Times.Once);
var httpResult = result.Should().BeOfType<ProblemHttpResult>().Subject;
httpResult.StatusCode.Should().Be(StatusCodes.Status404NotFound);
var httpResult = result.Should().BeOfType<Ok<List<PlayerResponseModel>>>().Subject;
httpResult.StatusCode.Should().Be(StatusCodes.Status200OK);
httpResult.Value.Should().NotBeNull().And.BeEmpty();
}

[Fact]
Expand Down
Loading