@@ -7,18 +7,8 @@ namespace events.Controllers;
77
88[ Route ( "api/[controller]" ) ]
99[ ApiController ]
10- public class EventsController : ControllerBase
10+ public class EventsController ( IEventsService service , ILogger < EventsController > logger ) : ControllerBase
1111{
12- private readonly IEventsService _service ;
13- private readonly ILogger < EventsController > _logger ;
14-
15- public EventsController ( IEventsService service , ILogger < EventsController > logger )
16- {
17- _service = service ;
18- _logger = logger ;
19- }
20-
21-
2212 [ HttpGet ]
2313 [ EndpointSummary ( "Paged Event Registrations" ) ]
2414 [ EndpointDescription ( "This returns all the event registrations from our SQLite database, using EF Core" ) ]
@@ -29,8 +19,8 @@ public async Task<IActionResult> GetEventRegistrations([FromQuery] int pageSize
2919 {
3020 try
3121 {
32- _logger . LogInformation ( "Fetching event registrations with pageSize: {PageSize}, lastId: {LastId}" , pageSize , lastId ) ;
33- var pagedResult = await _service . GetEventRegistrationsAsync ( pageSize , lastId , Url ) ;
22+ logger . LogInformation ( "Fetching event registrations with pageSize: {PageSize}, lastId: {LastId}" , pageSize , lastId ) ;
23+ var pagedResult = await service . GetEventRegistrationsAsync ( pageSize , lastId , Url ) ;
3424
3525 var paginationMetadata = new
3626 {
@@ -52,7 +42,7 @@ public async Task<IActionResult> GetEventRegistrations([FromQuery] int pageSize
5242 }
5343 catch ( Exception ex )
5444 {
55- _logger . LogError ( ex , "An error occurred while fetching event registrations." ) ;
45+ logger . LogError ( ex , "An error occurred while fetching event registrations." ) ;
5646 return StatusCode ( 500 , "An error occurred while fetching event registrations." ) ;
5747 }
5848 }
@@ -71,7 +61,7 @@ public async Task<IActionResult> GetEventRegistrationById(int id)
7161
7262 try
7363 {
74- var eventRegistration = await _service . GetEventRegistrationByIdAsync ( id ) ;
64+ var eventRegistration = await service . GetEventRegistrationByIdAsync ( id ) ;
7565 if ( eventRegistration == null )
7666 {
7767 return NotFound ( ) ;
@@ -81,7 +71,7 @@ public async Task<IActionResult> GetEventRegistrationById(int id)
8171 }
8272 catch ( Exception ex )
8373 {
84- _logger . LogError ( ex , "An error occurred while fetching event registration by Id: {Id}" , id ) ;
74+ logger . LogError ( ex , "An error occurred while fetching event registration by Id: {Id}" , id ) ;
8575 return StatusCode ( 500 , "An error occurred while fetching event registration by Id." ) ;
8676 }
8777 }
@@ -98,7 +88,7 @@ public async Task<IActionResult> PostEventRegistration([FromBody] EventRegistrat
9888 return BadRequest ( ModelState ) ;
9989 }
10090
101- var createdEvent = await _service . CreateEventRegistrationAsync ( eventRegistrationDto ) ;
91+ var createdEvent = await service . CreateEventRegistrationAsync ( eventRegistrationDto ) ;
10292
10393 return CreatedAtAction ( nameof ( GetEventRegistrationById ) , new { id = createdEvent . Id } , createdEvent ) ;
10494
0 commit comments