Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
L
library-app-django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ilham Maulana
library-app-django
Commits
03d0b7ba
Commit
03d0b7ba
authored
Jul 11, 2024
by
impfundev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: api upcoming and overdued loans
parent
885bdf7e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
1 deletion
+29
-1
urls.py
api/urls.py
+9
-1
views.py
api/views.py
+20
-0
No files found.
api/urls.py
View file @
03d0b7ba
...
...
@@ -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
)),
...
...
api/views.py
View file @
03d0b7ba
...
...
@@ -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
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment