Skip to content

Commit

Permalink
add: get rec by id
Browse files Browse the repository at this point in the history
  • Loading branch information
Meefx committed Dec 5, 2023
1 parent dcc380c commit 3f9d952
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions rekomendasi/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
urlpatterns = [
path('similar-books/<int:id>', similar_books, name='similar_books'),
path('json/', get_recommendations_json, name='get_recommendations_json'),
path('json/<int:id>', get_recommendations_json_by_id, name='get_recommendations_json_by_id'),
path('filter-books-ajax/<int:id>', filter_books_ajax, name='filter_books_ajax'),
path('isbn-search/',isbn_search,name="isbn_search")
]
10 changes: 10 additions & 0 deletions rekomendasi/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ def get_recommendations_json(request):
data = BookRecommendation.objects.all()
return HttpResponse(serializers.serialize("json",data),content_type="application/json")

def get_recommendations_json_by_id(request, id):
book = Book.objects.get(pk = id)

# Periksa apakah rekomendasi sudah ada
if not has_recommendations(book):
init_recommend_book(book)

recommendation_books = BookRecommendation.objects.filter(source_book=book)
return HttpResponse(serializers.serialize("json",recommendation_books),content_type="application/json")

@csrf_exempt
def filter_books_ajax(request, id):
book = Book.objects.get(pk = id)
Expand Down

0 comments on commit 3f9d952

Please sign in to comment.