Skip to content

Commit

Permalink
Add caching and etags to the api
Browse files Browse the repository at this point in the history
  • Loading branch information
brianglass committed Nov 29, 2023
1 parent b3224c4 commit 5a1d368
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion calendarium/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
from django.utils import timezone
from django.utils.translation import get_language_from_request
from ninja import Field, NinjaAPI, Redoc, Schema
from ninja.decorators import decorate_view
from ninja.renderers import JSONRenderer
from ninja.responses import NinjaJSONEncoder
from pydantic import AnyUrl, AnyHttpUrl, conint, constr, validator

from . import datetools, liturgics, views
from .datetools import Calendar
from orthocal.decorators import instrument_endpoint
from orthocal.decorators import cache, etag, etag_date, instrument_endpoint

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -162,6 +163,7 @@ def not_implemented_handler(request, exc):

@api.get('{cal:cal}/{year:year}/{month:month}/{day:day}/', response=DaySchema)
@instrument_endpoint
@decorate_view(etag)
async def get_calendar_day(request, cal: Calendar, year: year, month: month, day: day):
"""Get information about the liturgical day for the given calendar and date.
The *cal* path parameter should be `gregorian` or `julian`. The legacy `oca` or `rocor`
Expand All @@ -182,6 +184,8 @@ async def get_calendar_day(request, cal: Calendar, year: year, month: month, day

@api.get('{cal:cal}/{year:year}/{month:month}/', response=list[DaySchemaLite])
@instrument_endpoint
@decorate_view(cache)
@decorate_view(etag)
async def get_calendar_month(request, cal: Calendar, year: year, month: month) -> list[DaySchemaLite]:
"""Get information about all the liturgical days for the given calendar and month.
This endpoint excludes the readings and stories in order to avoid returning
Expand All @@ -200,6 +204,7 @@ async def get_calendar_month(request, cal: Calendar, year: year, month: month) -

@api.get('{cal:cal}/', response=DaySchema, summary='Get Today')
@instrument_endpoint
@decorate_view(etag_date)
async def get_calendar_default(request, cal: Calendar):
"""Get information about the current liturgical day for the given calendar.
The timezone is Pacific Time. The *cal* path parameter should be
Expand Down

0 comments on commit 5a1d368

Please sign in to comment.