Skip to content

Commit 73805a5

Browse files
committed
fix: update README and fix bugs
1 parent f92a7c9 commit 73805a5

5 files changed

Lines changed: 13 additions & 10 deletions

File tree

src/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import candidates.urls
1111
import database
1212
import elections.urls
13+
import mountain_madness._2026.urls
1314
import nominees.urls
1415
import officers.urls
1516
import permission.urls
@@ -53,6 +54,7 @@
5354
app.include_router(nominees.urls.router)
5455
app.include_router(officers.urls.router)
5556
app.include_router(permission.urls.router)
57+
app.include_router(mountain_madness._2026.urls.router)
5658

5759

5860
@app.get("/")
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
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
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from counter import CounterFile
2-
1+
from .counter import CounterFile
32
from .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
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from pydantic import BaseModel
1+
from pydantic import BaseModel, ConfigDict
22

33

44
class CounterResponse(BaseModel):
5+
model_config = ConfigDict(from_attributes=True)
56
good: int
67
evil: int

src/mountain_madness/_2026/urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
operation_id="mm_get_counters",
1717
)
1818
async 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
)
2929
async 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
)
4141
async def increment_evil():
4242
mm_counter.increment("evil")
43-
return mm_counter.get_all_counters()
43+
return CounterResponse(**mm_counter.get_all_counters())

0 commit comments

Comments
 (0)