@@ -7,6 +7,11 @@ import com.dpconde.sofia_tracker.presentation.dto.RemoteEventDto
77import com.dpconde.sofia_tracker.presentation.dto.UpdateEventRequestDto
88import com.dpconde.sofia_tracker.presentation.exception.EventNotFoundException
99import com.dpconde.sofia_tracker.presentation.mappers.EventDtoMapper
10+ import io.swagger.v3.oas.annotations.Operation
11+ import io.swagger.v3.oas.annotations.Parameter
12+ import io.swagger.v3.oas.annotations.responses.ApiResponse
13+ import io.swagger.v3.oas.annotations.responses.ApiResponses
14+ import io.swagger.v3.oas.annotations.tags.Tag
1015import jakarta.validation.Valid
1116import org.springframework.format.annotation.DateTimeFormat
1217import org.springframework.http.HttpStatus
@@ -18,6 +23,7 @@ import java.time.ZoneOffset
1823
1924@RestController
2025@RequestMapping(" /api/events" )
26+ @Tag(name = " Events" , description = " API for managing baby events (feeding, sleeping, diaper changes)" )
2127class EventController (
2228 private val createEventUseCase : CreateEventUseCase ,
2329 private val getEventUseCase : GetEventUseCase ,
@@ -28,6 +34,17 @@ class EventController(
2834) {
2935
3036 @PostMapping
37+ @Operation(
38+ summary = " Create a new event" ,
39+ description = " Creates a new baby event (feeding, sleeping, or diaper change)"
40+ )
41+ @ApiResponses(
42+ value = [
43+ ApiResponse (responseCode = " 201" , description = " Event created successfully" ),
44+ ApiResponse (responseCode = " 400" , description = " Invalid request data" ),
45+ ApiResponse (responseCode = " 409" , description = " Event with this ID already exists" )
46+ ]
47+ )
3148 fun createEvent (@Valid @RequestBody request : CreateEventRequestDto ): ResponseEntity <RemoteEventDto > {
3249 val command = eventDtoMapper.toCreateEventCommand(request)
3350 val createdEvent = createEventUseCase.execute(command)
@@ -36,7 +53,20 @@ class EventController(
3653 }
3754
3855 @GetMapping(" /{id}" )
39- fun getEvent (@PathVariable id : String ): ResponseEntity <RemoteEventDto > {
56+ @Operation(
57+ summary = " Get event by ID" ,
58+ description = " Retrieves a specific event by its unique identifier"
59+ )
60+ @ApiResponses(
61+ value = [
62+ ApiResponse (responseCode = " 200" , description = " Event found" ),
63+ ApiResponse (responseCode = " 404" , description = " Event not found" )
64+ ]
65+ )
66+ fun getEvent (
67+ @Parameter(description = " Event ID" , required = true )
68+ @PathVariable id : String
69+ ): ResponseEntity <RemoteEventDto > {
4070 val event = getEventUseCase.execute(id)
4171 ? : throw EventNotFoundException (" Event with ID $id not found" )
4272
@@ -77,9 +107,22 @@ class EventController(
77107 }
78108
79109 @GetMapping
110+ @Operation(
111+ summary = " List events" ,
112+ description = " Retrieves all events with optional filtering by type or date range"
113+ )
114+ @ApiResponses(
115+ value = [
116+ ApiResponse (responseCode = " 200" , description = " Events retrieved successfully" ),
117+ ApiResponse (responseCode = " 400" , description = " Invalid query parameters" )
118+ ]
119+ )
80120 fun listEvents (
121+ @Parameter(description = " Filter by event type (EAT, SLEEP, POOP)" )
81122 @RequestParam(required = false ) type : String? ,
123+ @Parameter(description = " Start date for date range filter (ISO format)" )
82124 @RequestParam(required = false ) @DateTimeFormat(iso = DateTimeFormat .ISO .DATE_TIME ) start : LocalDateTime ? ,
125+ @Parameter(description = " End date for date range filter (ISO format)" )
83126 @RequestParam(required = false ) @DateTimeFormat(iso = DateTimeFormat .ISO .DATE_TIME ) end : LocalDateTime ?
84127 ): ResponseEntity <List <RemoteEventDto >> {
85128 val events = when {
@@ -107,6 +150,11 @@ class EventController(
107150 }
108151
109152 @GetMapping(" /health" )
153+ @Operation(
154+ summary = " Health check" ,
155+ description = " Returns the health status of the Events API"
156+ )
157+ @ApiResponse(responseCode = " 200" , description = " Service is healthy" )
110158 fun health (): ResponseEntity <Map <String , String >> {
111159 return ResponseEntity .ok(mapOf (" status" to " UP" ))
112160 }
0 commit comments