@@ -16,7 +16,7 @@ type GetIncidentsRequest struct {
1616}
1717
1818type GetIncidentsResponse struct {
19- Checks []GetIncidentsResponseIncident `json:"incidents"`
19+ Incidents []GetIncidentsResponseIncident `json:"incidents"`
2020}
2121
2222type GetIncidentsResponseIncident struct {
@@ -56,11 +56,11 @@ func (h *Handlers) GetIncidents(c hs.AuthenticatedContext) error {
5656
5757func (h * Handlers ) newGetIncidentResponse (incidents * []entities.Incident ) * GetIncidentsResponse {
5858 resp := & GetIncidentsResponse {
59- Checks : make ([]GetIncidentsResponseIncident , len (* incidents )),
59+ Incidents : make ([]GetIncidentsResponseIncident , len (* incidents )),
6060 }
6161
6262 for i , incident := range * incidents {
63- resp .Checks [i ] = GetIncidentsResponseIncident {
63+ resp .Incidents [i ] = GetIncidentsResponseIncident {
6464 ID : incident .ID ,
6565 TeamID : incident .TeamID ,
6666 MonitorID : incident .MonitorID ,
@@ -135,3 +135,68 @@ func (h *Handlers) newGetIncidentOverviewResponse(incidents *[]entities.Incident
135135
136136 return resp
137137}
138+
139+ type GetMonitorIncidentsRequest struct {
140+ TeamID uint `param:"teamId" validate:"required,numeric,gte=0"`
141+ MonitorID uint `param:"monitorId" validate:"required,numeric,gte=0"`
142+ Offset * int `query:"offset" validate:"omitempty,numeric,gte=0"`
143+ Limit * int `query:"limit" validate:"omitempty,numeric,gte=0,max=255"`
144+ }
145+
146+ type GetMonitorIncidentsResponse struct {
147+ Incidents []GetMonitorIncidentsResponseIncident `json:"incidents"`
148+ }
149+
150+ type GetMonitorIncidentsResponseIncident struct {
151+ ID uint `json:"id"`
152+ TeamID uint `json:"teamId"`
153+ MonitorID uint `json:"monitorId"`
154+ Title string `json:"title"`
155+ Description string `json:"description"`
156+ CreatedAt string `json:"createdAt"`
157+ }
158+
159+ func (h * Handlers ) GetMonitorIncidents (c hs.AuthenticatedContext ) error {
160+ req , err := helpers.Bind [GetMonitorIncidentsRequest ](c )
161+ if err != nil {
162+ c .Log .WithError (err ).Debug ("failed to bind GetMonitorIncidentsRequest" )
163+
164+ return echo .ErrBadRequest
165+ }
166+
167+ ctx := c .Request ().Context ()
168+
169+ incidents , err := h .IncidentService .GetByTeamIDPaginated (
170+ ctx ,
171+ req .TeamID ,
172+ req .Offset ,
173+ req .Limit )
174+ if err != nil {
175+ c .Log .WithError (err ).Error ("failed to get incidents" )
176+
177+ return echo .ErrInternalServerError
178+ }
179+
180+ resp := h .newGetIncidentResponse (incidents )
181+
182+ return c .JSON (http .StatusOK , resp )
183+ }
184+
185+ func (h * Handlers ) GetMonitorIncidentsResponse (incidents * []entities.Incident ) * GetMonitorIncidentsResponse {
186+ resp := & GetMonitorIncidentsResponse {
187+ Incidents : make ([]GetMonitorIncidentsResponseIncident , len (* incidents )),
188+ }
189+
190+ for i , incident := range * incidents {
191+ resp .Incidents [i ] = GetMonitorIncidentsResponseIncident {
192+ ID : incident .ID ,
193+ TeamID : incident .TeamID ,
194+ MonitorID : incident .MonitorID ,
195+ Title : incident .Title ,
196+ Description : * incident .Description ,
197+ CreatedAt : incident .CreatedAt .Format ("2006-01-02T15:04:05Z07:00" ),
198+ }
199+ }
200+
201+ return resp
202+ }
0 commit comments