33from typing import Optional
44
55from django .http import HttpResponse
6+ from drf_spectacular .types import OpenApiTypes
7+ from drf_spectacular .utils import extend_schema
68from rest_framework .decorators import action
79from rest_framework .exceptions import ValidationError
810from rest_framework .request import Request
911from rest_framework .response import Response
12+ from rest_framework .status import HTTP_200_OK
1013from rest_framework .views import APIView
1114
1215from application .authorization .services .authorization import user_has_permission_or_403
1518from application .core .models import Product
1619from application .core .queries .product import get_product_by_id
1720from application .core .types import Severity
21+ from application .metrics .api .serializers import (
22+ ProductMetricsSerializer ,
23+ ProductMetricsStatusSerializer ,
24+ )
1825from application .metrics .models import Product_Metrics_Status
1926from application .metrics .services .export_metrics import (
2027 export_product_metrics_csv ,
2835
2936
3037class ProductMetricsTimelineView (APIView ):
38+ @extend_schema (
39+ methods = ["GET" ],
40+ request = None ,
41+ responses = {HTTP_200_OK : dict },
42+ )
3143 @action (detail = False , methods = ["get" ])
3244 def get (self , request : Request ) -> Response :
3345 product = _get_and_check_product (request )
@@ -36,13 +48,25 @@ def get(self, request: Request) -> Response:
3648
3749
3850class ProductMetricsCurrentView (APIView ):
51+ @extend_schema (
52+ methods = ["GET" ],
53+ request = None ,
54+ responses = {HTTP_200_OK : ProductMetricsSerializer },
55+ )
3956 @action (detail = False , methods = ["get" ])
4057 def get (self , request : Request ) -> Response :
4158 product = _get_and_check_product (request )
4259 return Response (get_product_metrics_current (product ))
4360
4461
4562class ProductMetricsExportExcelView (APIView ):
63+ @extend_schema (
64+ methods = ["GET" ],
65+ request = None ,
66+ responses = {
67+ (HTTP_200_OK , "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" ): OpenApiTypes .BINARY
68+ },
69+ )
4670 @action (detail = False , methods = ["get" ])
4771 def get (self , request : Request ) -> HttpResponse :
4872 product = _get_and_check_product (request )
@@ -65,6 +89,11 @@ def get(self, request: Request) -> HttpResponse:
6589
6690
6791class ProductMetricsExportCsvView (APIView ):
92+ @extend_schema (
93+ methods = ["GET" ],
94+ request = None ,
95+ responses = {(HTTP_200_OK , "text/csv" ): OpenApiTypes .BINARY },
96+ )
6897 @action (detail = False , methods = ["get" ])
6998 def get (self , request : Request ) -> HttpResponse :
7099 product = _get_and_check_product (request )
@@ -78,6 +107,11 @@ def get(self, request: Request) -> HttpResponse:
78107
79108
80109class ProductMetricsExportCodeChartaView (APIView ):
110+ @extend_schema (
111+ methods = ["GET" ],
112+ request = None ,
113+ responses = {(HTTP_200_OK , "text/csv" ): OpenApiTypes .BINARY },
114+ )
81115 @action (detail = False , methods = ["get" ])
82116 def get (self , request : Request ) -> HttpResponse :
83117 product = _get_and_check_product (request )
@@ -111,6 +145,11 @@ def get(self, request: Request) -> HttpResponse:
111145
112146
113147class ProductMetricsStatusView (APIView ):
148+ @extend_schema (
149+ methods = ["GET" ],
150+ request = None ,
151+ responses = {HTTP_200_OK : ProductMetricsStatusSerializer },
152+ )
114153 @action (detail = False , methods = ["get" ])
115154 def get (self , request : Request ) -> Response :
116155 settings = Settings .load ()
0 commit comments