File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010import candidates .urls
1111import database
1212import elections .urls
13+ import mountain_madness ._2026 .urls
1314import nominees .urls
1415import officers .urls
1516import permission .urls
5354app .include_router (nominees .urls .router )
5455app .include_router (officers .urls .router )
5556app .include_router (permission .urls .router )
57+ app .include_router (mountain_madness ._2026 .urls .router )
5658
5759
5860@app .get ("/" )
Original file line number Diff line number Diff line change 11# A counter created for Mountain Madness 2026
22
3- * The file it writes to is ` /var/lib /mountain_madness/2026/counters .json `
3+ * The file it writes to is ` /var/www /mountain_madness/2026/counter .json `
44* It contains the four following endpoints (root is ` /api/mm2026 ` )
5+ * GET ` /counters ` : Returns the counter values
56 * POST ` /good ` : Increments the Good counter
6- * GET ` /good ` : Returns the Good count
77 * POST ` /evil ` : Increments the Evil counter
8- * GET ` /evil ` : Returns the Evil count
Original file line number Diff line number Diff line change 1- from counter import CounterFile
2-
1+ from .counter import CounterFile
32from .models import CounterResponse
43
5- mm_counter = CounterFile ("/var/lib/mountain_madness/2026/counter.json" , save_interval = 300 , save_threshold = 10 )
4+ mm_counter = CounterFile ("/var/www/mountain_madness/2026/counter.json" , save_interval = 300 , save_threshold = 10 )
5+ mm_counter .increment ("good" , 0 ) # initialize the counter with default values if it doesn't exist
6+ mm_counter .increment ("evil" , 0 ) # initialize the counter with default values if it doesn't exist
Original file line number Diff line number Diff line change 1- from pydantic import BaseModel
1+ from pydantic import BaseModel , ConfigDict
22
33
44class CounterResponse (BaseModel ):
5+ model_config = ConfigDict (from_attributes = True )
56 good : int
67 evil : int
Original file line number Diff line number Diff line change 1616 operation_id = "mm_get_counters" ,
1717)
1818async def get_all_counters ():
19- return mm_counter .get_all_counters ()
19+ return CounterResponse ( ** mm_counter .get_all_counters () )
2020
2121
2222@router .post (
@@ -28,7 +28,7 @@ async def get_all_counters():
2828)
2929async def increment_good ():
3030 mm_counter .increment ("good" )
31- return mm_counter .get_all_counters ()
31+ return CounterResponse ( ** mm_counter .get_all_counters () )
3232
3333
3434@router .post (
@@ -40,4 +40,4 @@ async def increment_good():
4040)
4141async def increment_evil ():
4242 mm_counter .increment ("evil" )
43- return mm_counter .get_all_counters ()
43+ return CounterResponse ( ** mm_counter .get_all_counters () )
You can’t perform that action at this time.
0 commit comments