Automated PR feature/implementing-logger into Main#23
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces structured logging into the StationController and ReadingController API endpoints, and updates the associated controller unit tests to construct controllers with an injected ILogger.
Changes:
- Add
ILogger<T>constructor injection toStationControllerandReadingController. - Add
LogInformation/LogWarning/LogError/LogDebugstatements around key controller actions and error paths. - Update controller tests to pass mocked
ILogger<T>instances.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| AirAware/Controllers/StationController.cs | Adds injected logger and logs around station CRUD and latest-AQI endpoint. |
| AirAware/Controllers/ReadingController.cs | Adds injected logger and logs around reading CRUD, raw payload parsing, and AQI creation. |
| AirAware.Tests/Controllers/StationControllerTests.cs | Updates test setup to construct StationController with a mocked logger. |
| AirAware.Tests/Controllers/ReadingControllerTests.cs | Updates test setup to construct ReadingController with a mocked logger. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
|
|
||
| // Get latest AQI record for this station, including its reading | ||
| var latest = await context.AqiRecords |
There was a problem hiding this comment.
The query starting here orders AqiRecords before a Join(...). Ordering is not guaranteed to be preserved through a join, so with the later FirstOrDefaultAsync() this can return a non-latest record. Apply the ordering after the join/selection (e.g., order by ar.Aqi.ComputedAt right before FirstOrDefaultAsync).
| _logger.LogDebug("AQI record already exists for reading {ReadingId}", reading.Id); | ||
| } | ||
|
|
||
| return Created($"api/v1/readings/{reading.Id}", new { reading, aqi = aqiRecord }); |
There was a problem hiding this comment.
If an AQI record already exists for this ReadingId, the response still returns the newly computed aqiRecord instance, which may not match what’s persisted (and ignores existing). Consider returning existing when present (or overwriting it) so the API response reflects the stored data.
No description provided.