Commit 03d0b7ba authored by impfundev's avatar impfundev

feat: api upcoming and overdued loans

parent 885bdf7e
......@@ -12,6 +12,8 @@ from api.views import (
LoginAsMember,
LogoutAsMember,
ChangePasswordAsMember,
OverduedBookLoanViewSet,
UpComingBookLoanViewSet,
)
router = routers.DefaultRouter()
......@@ -19,7 +21,13 @@ router.register(r"users", UserViewSet, basename="users")
router.register(r"books", BookViewSet, basename="books")
router.register(r"members", MemberViewSet, basename="members")
router.register(r"librarians", LibrarianViewSet, basename="librarians")
router.register(r"book_loans", BookLoanViewSet, basename="book_loans")
router.register(r"book-loans", BookLoanViewSet, basename="book_loans")
router.register(
r"overdued-loans", OverduedBookLoanViewSet, basename="book_loans_overdued"
)
router.register(
r"upcoming-loans", UpComingBookLoanViewSet, basename="book_loans_upcoming"
)
urlpatterns = [
path("", include(router.urls)),
......
......@@ -66,6 +66,26 @@ class BookLoanViewSet(viewsets.ModelViewSet):
search_fields = filterset_fields
class OverduedBookLoanViewSet(BookLoanViewSet):
now = datetime.now()
queryset = (
BookLoans.objects.all()
.filter(due_date__lte=now, return_date=None)
.order_by("created_at")
)
class UpComingBookLoanViewSet(BookLoanViewSet):
now = datetime.now()
due_date_treshold = now.today() + timedelta(days=3)
queryset = (
BookLoans.objects.all()
.filter(due_date__lte=due_date_treshold, return_date=None)
.filter(due_date__gte=now.today())
.order_by("created_at")
)
class LoginAsLibrarian(views.APIView):
def post(self, request):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment