get weekdays
This commit is contained in:
1
.idea/runConfigurations/vue01.xml
generated
1
.idea/runConfigurations/vue01.xml
generated
@@ -1,5 +1,6 @@
|
||||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="vue01" type="Python.FastAPI">
|
||||
<option name="additionalOptions" value="--reload --host 0.0.0.0 --port 4433" />
|
||||
<option name="file" value="$PROJECT_DIR$/backend/main.py" />
|
||||
<module name="vue01" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
|
||||
@@ -1,6 +1,27 @@
|
||||
from fastapi import FastAPI
|
||||
from contextlib import asynccontextmanager
|
||||
|
||||
app = FastAPI()
|
||||
from fastapi import FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
|
||||
from backend.src import router
|
||||
|
||||
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
yield
|
||||
|
||||
|
||||
app = FastAPI(lifespan=lifespan)
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=["*"],
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
app.include_router(router.calendar)
|
||||
|
||||
|
||||
@app.get("/")
|
||||
|
||||
0
backend/src/__init__.py
Normal file
0
backend/src/__init__.py
Normal file
1
backend/src/router/__init__.py
Normal file
1
backend/src/router/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .calendar import calendar
|
||||
41
backend/src/router/calendar.py
Normal file
41
backend/src/router/calendar.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import datetime
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
calendar = APIRouter(
|
||||
prefix="/calendar",
|
||||
tags=["calendar"],
|
||||
)
|
||||
|
||||
|
||||
@calendar.get("/", response_model=list[datetime.date])
|
||||
async def get_calendar(
|
||||
year: int = None,
|
||||
month: int = None,
|
||||
):
|
||||
"""Get a list of weekday dates for a month.
|
||||
|
||||
By default, the current month is used.
|
||||
|
||||
If **year** is provided, **month** must be provided, too.
|
||||
"""
|
||||
if year is not None:
|
||||
if month is None:
|
||||
raise HTTPException(status_code=422,
|
||||
detail=[
|
||||
dict(type="missing parameter",
|
||||
loc=["query", "month"],
|
||||
msg="month must be provided when year is provided")])
|
||||
else:
|
||||
today = datetime.date.today()
|
||||
month = today.month
|
||||
year = today.year
|
||||
date = datetime.date(year, month, 1)
|
||||
end_date = date + relativedelta(day=31)
|
||||
result = []
|
||||
while date <= end_date:
|
||||
if date.isoweekday() < 6:
|
||||
result.append(date)
|
||||
date += relativedelta(days=1)
|
||||
return result
|
||||
@@ -1,11 +1,11 @@
|
||||
# Test your FastAPI endpoints
|
||||
|
||||
GET http://127.0.0.1:8000/
|
||||
GET http://127.0.0.1:4433/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET http://127.0.0.1:8000/hello/User
|
||||
GET http://127.0.0.1:4433/hello/User
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
@@ -5,5 +5,6 @@ description = "Add your description here"
|
||||
requires-python = ">=3.13"
|
||||
dependencies = [
|
||||
"fastapi>=0.116.1",
|
||||
"python-dateutil>=2.9.0.post0",
|
||||
"uvicorn>=0.35.0",
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user