File tree Expand file tree Collapse file tree 4 files changed +28
-1
lines changed
Expand file tree Collapse file tree 4 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 44 Changelog
55=========
66
7+ - :release: `1.6.0 <09th March 2023> `
8+ - :feature: `21 ` Add random number generation
9+
710- :release: `1.5.0 <28th February 2023> `
811- :feature: `17 ` Pin the Docker image to a specific SHA-256 digest to help with reproducible builds
912
Original file line number Diff line number Diff line change 11"""Public API for our projects"""
22
3- __version__ = "1.5 .0"
3+ __version__ = "1.6 .0"
Original file line number Diff line number Diff line change 11"""API server definition"""
22
33from os import getenv
4+ from random import randint
45
56import sentry_sdk
67from fastapi import APIRouter , FastAPI
@@ -31,6 +32,13 @@ class TextModel(BaseModel):
3132 text : str
3233
3334
35+ class Numbers (BaseModel ):
36+ """Model to hold a list of numbers"""
37+
38+ numbers : list [int ]
39+ total : int
40+
41+
3442app = FastAPI (
3543 title = "Let's Build A API" ,
3644 description = "An API to host Let's Build A's projects" ,
@@ -60,4 +68,11 @@ async def uwuify_route(text: TextModel):
6068 return {"text" : uwuify (text .text )}
6169
6270
71+ @router_fun .get ("/random-numbers/{quantity}/{range_high}" )
72+ async def random_numbers (quantity : int , range_high : int ) -> Numbers :
73+ """Generate bulk random numbers"""
74+ numbers = [randint (1 , range_high ) for _ in range (quantity )]
75+ return Numbers (numbers = numbers , total = sum (numbers ))
76+
77+
6378app .include_router (router_fun )
Original file line number Diff line number Diff line change @@ -15,3 +15,12 @@ def test_read_main():
1515 "message" : "Welcome to the API" ,
1616 "version" : __version__ ,
1717 }
18+
19+
20+ def test_read_random_numbers ():
21+ response = client .get ("/fun/random-numbers/1/1" )
22+ assert response .status_code == 200
23+ assert response .json () == {
24+ "numbers" : [1 ],
25+ "total" : 1 ,
26+ }
You can’t perform that action at this time.
0 commit comments