11from django .db import transaction
22from django .utils import timezone
3- from rest_framework import serializers
3+ from drf_spectacular . utils import extend_schema
44from rest_framework .request import Request
55from rest_framework .response import Response
66
77from sentry .api .authentication import DSNAuthentication
88from sentry .api .base import Endpoint , region_silo_endpoint
99from sentry .api .bases .monitor import MonitorEndpoint , ProjectMonitorPermission
1010from sentry .api .exceptions import ResourceDoesNotExist
11- from sentry .api .fields .empty_integer import EmptyIntegerField
1211from sentry .api .serializers import serialize
12+ from sentry .api .serializers .models .monitorcheckin import MonitorCheckInSerializerResponse
13+ from sentry .api .validators import MonitorCheckInValidator
14+ from sentry .apidocs .constants import (
15+ RESPONSE_ALREADY_REPORTED ,
16+ RESPONSE_BAD_REQUEST ,
17+ RESPONSE_FORBIDDEN ,
18+ RESPONSE_NOTFOUND ,
19+ RESPONSE_UNAUTHORIZED ,
20+ )
21+ from sentry .apidocs .parameters import GLOBAL_PARAMS , MONITOR_PARAMS
22+ from sentry .apidocs .utils import inline_sentry_response_serializer
1323from sentry .models import (
1424 CheckInStatus ,
1525 Monitor ,
2232from sentry .utils .sdk import bind_organization_context , configure_scope
2333
2434
25- class CheckInSerializer (serializers .Serializer ):
26- status = serializers .ChoiceField (
27- choices = (
28- ("ok" , CheckInStatus .OK ),
29- ("error" , CheckInStatus .ERROR ),
30- ("in_progress" , CheckInStatus .IN_PROGRESS ),
31- )
32- )
33- duration = EmptyIntegerField (required = False , allow_null = True )
34-
35-
3635@region_silo_endpoint
36+ @extend_schema (tags = ["Crons" ])
3737class MonitorCheckInDetailsEndpoint (Endpoint ):
3838 authentication_classes = MonitorEndpoint .authentication_classes + (DSNAuthentication ,)
3939 permission_classes = (ProjectMonitorPermission ,)
40+ public = {"GET" , "PUT" }
4041
4142 # TODO(dcramer): this code needs shared with other endpoints as its security focused
4243 # TODO(dcramer): this doesnt handle is_global roles
@@ -82,6 +83,23 @@ def convert_args(self, request: Request, monitor_id, checkin_id, *args, **kwargs
8283 kwargs .update ({"checkin" : checkin , "monitor" : monitor , "project" : project })
8384 return (args , kwargs )
8485
86+ @extend_schema (
87+ operation_id = "Retrieve a check-in" ,
88+ parameters = [
89+ GLOBAL_PARAMS .ORG_SLUG ,
90+ MONITOR_PARAMS .MONITOR_ID ,
91+ MONITOR_PARAMS .CHECKIN_ID ,
92+ ],
93+ request = None ,
94+ responses = {
95+ 201 : inline_sentry_response_serializer (
96+ "MonitorCheckIn" , MonitorCheckInSerializerResponse
97+ ),
98+ 401 : RESPONSE_UNAUTHORIZED ,
99+ 403 : RESPONSE_FORBIDDEN ,
100+ 404 : RESPONSE_NOTFOUND ,
101+ },
102+ )
85103 def get (self , request : Request , project , monitor , checkin ) -> Response :
86104 """
87105 Retrieve a check-in
@@ -100,6 +118,28 @@ def get(self, request: Request, project, monitor, checkin) -> Response:
100118
101119 return self .respond (serialize (checkin , request .user ))
102120
121+ @extend_schema (
122+ operation_id = "Update a check-in" ,
123+ parameters = [
124+ GLOBAL_PARAMS .ORG_SLUG ,
125+ MONITOR_PARAMS .MONITOR_ID ,
126+ MONITOR_PARAMS .CHECKIN_ID ,
127+ ],
128+ request = MonitorCheckInValidator ,
129+ responses = {
130+ 200 : inline_sentry_response_serializer (
131+ "MonitorCheckIn2" , MonitorCheckInSerializerResponse
132+ ),
133+ 208 : RESPONSE_ALREADY_REPORTED ,
134+ 400 : RESPONSE_BAD_REQUEST ,
135+ 401 : RESPONSE_UNAUTHORIZED ,
136+ 403 : RESPONSE_FORBIDDEN ,
137+ 404 : RESPONSE_NOTFOUND ,
138+ },
139+ examples = [
140+ # OpenApiExample()
141+ ],
142+ )
103143 def put (self , request : Request , project , monitor , checkin ) -> Response :
104144 """
105145 Update a check-in
@@ -115,7 +155,7 @@ def put(self, request: Request, project, monitor, checkin) -> Response:
115155 if checkin .status in CheckInStatus .FINISHED_VALUES :
116156 return self .respond (status = 400 )
117157
118- serializer = CheckInSerializer (
158+ serializer = MonitorCheckInValidator (
119159 data = request .data , partial = True , context = {"project" : project , "request" : request }
120160 )
121161 if not serializer .is_valid ():
0 commit comments