@@ -166,3 +166,55 @@ func (h *Handlers) GetMonitorCheck(c hs.AuthenticatedContext) error {
166166
167167 return c .JSON (http .StatusOK , resp )
168168}
169+
170+ type GeFailedMonitorCheckRequest struct {
171+ TeamID uint `param:"teamId" validate:"required,numeric,gte=0"`
172+ MonitorID uint `param:"monitorId" validate:"required,numeric,gte=0"`
173+ MonitorAssertionID uint `param:"monitorAssertionId" validate:"required,numeric,gte=0"`
174+ Offset * int `query:"offset" validate:"omitempty,numeric,gte=0"`
175+ Limit * int `query:"limit" validate:"omitempty,numeric,gte=0"`
176+ }
177+
178+ type GetFailedMonitorCheckResponse struct {
179+ GetMonitorChecksResponseCheck
180+ }
181+
182+ func (h * Handlers ) GetFailedMonitorChecks (c hs.AuthenticatedContext ) error {
183+ req , err := helpers.Bind [GeFailedMonitorCheckRequest ](c )
184+ if err != nil {
185+ c .Log .WithError (err ).Debug ("failed to bind GetMonitorsRequest" )
186+
187+ return echo .ErrBadRequest
188+ }
189+
190+ ctx := c .Request ().Context ()
191+
192+ monitorAssertion , err := h .MonitorService .GetMonitorAssertionByID (ctx , req .MonitorAssertionID )
193+ if err != nil {
194+ c .Log .WithError (err ).Error ("failed to get monitorAssertion" )
195+ return echo .ErrInternalServerError
196+ }
197+
198+ // map monitorassertion to filter
199+
200+ result , err := h .CheckService .GetMonitorIDAndAssertions (
201+ ctx ,
202+ monitorAssertion .MonitorID ,
203+ []string {"status_code == 200" },
204+ )
205+ if err != nil {
206+ if errors .Is (err , check .ErrNotFound ) {
207+ c .Log .WithError (err ).Debug ("check not found" )
208+
209+ return echo .ErrNotFound
210+ }
211+
212+ c .Log .WithError (err ).Error ("failed to get monitor check" )
213+
214+ return echo .ErrInternalServerError
215+ }
216+
217+ resp := h .newGetMonitorChecksResponse (result )
218+
219+ return c .JSON (http .StatusOK , resp )
220+ }
0 commit comments