Skip to content

Commit

Permalink
Merge pull request #67 from ReadNow-C14/readnow-juno
Browse files Browse the repository at this point in the history
edit pinjam buku
  • Loading branch information
hrjuno authored Dec 20, 2023
2 parents d4a03a8 + 07b0da9 commit 53f03ec
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions pinjam_buku/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@
path('borrow-book-flutter/<int:book_id>/', borrow_book_flutter, name='borrow_book_flutter'),
path('return-borrowed-book-flutter/<int:book_id>/', return_borrowed_book_flutter, name='return_borrowed_book_flutter'),
path('borrow-flutter/<int:book_id>/', borrow_flutter, name='borrow_flutter'),
path('add-wishlist-flutterr/<int:book_id>/', add_wishlist_flutterr, name='add_wishlist_flutterr'),
]
17 changes: 17 additions & 0 deletions pinjam_buku/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from django.http import JsonResponse
import json
from django.contrib.auth import get_user
from wishlist.models import Wishlist

# Create your views here.

Expand Down Expand Up @@ -97,6 +98,22 @@ def borrow_flutter(request, book_id):
else:
return JsonResponse({"status": "error"}, status=401)

@login_required(login_url='/login')
@csrf_exempt
def add_wishlist_flutterr(request, book_id):
if request.method == 'POST':
# Ambil buku yang sesuai dengan book_id
book = Book.objects.get(pk=book_id)
user = request.user
# Cek apakah buku sudah ada di wishlist
if Wishlist.objects.filter(user=user, book=book).exists():
# Kirim status bahwa data sudah ada
return JsonResponse({"status": "existed"}, status=200)
wishlist = Wishlist(user=user, book=book)
wishlist.save()
return JsonResponse({"status": "success"}, status=201)
else:
return JsonResponse({"status": "error"}, status=401)

@csrf_exempt
def return_book_ajax(request, id):
Expand Down

0 comments on commit 53f03ec

Please sign in to comment.