File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ apiVersion : v1
2+ kind : Service
3+ metadata :
4+ labels :
5+ io.kompose.service : service
6+ name : service
7+ spec :
8+ type : NodePort
9+ ports :
10+ - port : 8080
11+ protocol : TCP
12+ name : http
13+ selector :
14+ io.kompose.service : service
15+ ---
16+ apiVersion : apps/v1
17+ kind : Deployment
18+ metadata :
19+ annotations :
20+ kompose.cmd : kompose convert
21+ kompose.version : 1.16.0 (0c01309)
22+ creationTimestamp : null
23+ labels :
24+ io.kompose.service : service
25+ name : service
26+ spec :
27+ selector :
28+ matchLabels :
29+ io.kompose.service : service
30+ replicas : 1
31+ template :
32+ metadata :
33+ creationTimestamp : null
34+ labels :
35+ io.kompose.service : service
36+ spec :
37+ containers :
38+ - env :
39+ - name : MONGO_URI
40+ value : mongodb://mongo:27017
41+ image : nginx
42+ name : service
43+ imagePullPolicy : Always
44+ ports :
45+ - containerPort : 8080
46+ resources : {}
47+ restartPolicy : Always
48+ status : {}
Original file line number Diff line number Diff line change @@ -42,4 +42,21 @@ def get_student_by_id(student_id): # noqa: E501
4242 """
4343 return get_by_id (student_id )
4444
45+ def get_student_average_grade (student_id ):
46+ """gets student's average grade
47+
48+ Returns a single grade
49+
50+ :param student_id: the uid
51+ :type student_id:
52+
53+ :rtype: Float
54+ """
55+ student = get_by_id (student_id )
56+ grades = [grade_record .get ("grade" ) for grade_record in student .get ('grade_records' )]
57+ if not grades :
58+ return 'no grades' , 404
59+ average_grade = sum (grades ) / len (grades )
60+ return average_grade
61+
4562
Original file line number Diff line number Diff line change @@ -68,6 +68,35 @@ paths:
6868 " 404 " :
6969 description : Student with specified student_id cannot be found
7070 x-openapi-router-controller : swagger_server.controllers.default_controller
71+ /student/{student_id}/average_grade :
72+ get :
73+ summary : get average grade of the student
74+ description : Returns the average grade for a specific student
75+ operationId : get_student_average_grade
76+ parameters :
77+ - name : student_id
78+ in : path
79+ description : the uid
80+ required : true
81+ style : simple
82+ explode : false
83+ schema :
84+ type : string
85+ format : uuid
86+ responses :
87+ " 200 " :
88+ description : Successful operation
89+ content :
90+ application/json :
91+ schema :
92+ type : number
93+ format : float
94+ example : 8.5
95+ " 400 " :
96+ description : Invalid ID
97+ " 404 " :
98+ description : Not found
99+ x-openapi-router-controller : swagger_server.controllers.default_controller
71100 /student :
72101 post :
73102 summary : Add a new student
Original file line number Diff line number Diff line change @@ -48,6 +48,17 @@ def test_get_student_by_id(self):
4848 self .assert200 (response ,
4949 'Response body is : ' + response .data .decode ('utf-8' ))
5050
51+ def test_student_average_grade (self ):
52+ """Test case for get_student_by_id
53+
54+ gets student
55+ """
56+ response = self .client .open (
57+ '/tutorial/1.0.0/student/{student_id}/average_grade' .format (student_id = '38400000-8cf0-11bd-b23e-10b96e4ef00d' ),
58+ method = 'GET' )
59+ self .assert200 (response ,
60+ 'Response body is : ' + response .data .decode ('utf-8' ))
61+
5162
5263if __name__ == '__main__' :
5364 import unittest
You can’t perform that action at this time.
0 commit comments