-
Notifications
You must be signed in to change notification settings - Fork 0
feature: added view that shows all books info in json #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
books/serializer.py
Outdated
| from books.models import Book | ||
|
|
||
|
|
||
| def serialize_book(book: Book) -> dict: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тут бы тайпеддикт в аннотации в идеале сделать
books/views.py
Outdated
| def get_all_books_json_view(request): | ||
| books = Book.objects.all() | ||
| if not books: | ||
| return JsonResponse(data={'data': {}, 'error': 'No books found'}, status=404) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Для списка сущностей пустой список – штатная ситуция, не надо делать 404
books/serializer.py
Outdated
| year_of_publishing: int | ||
| copies_printed: int | ||
| short_description: str | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Пустой строки не хватает
books/serializer.py
Outdated
| from books.models import Book | ||
|
|
||
|
|
||
| class SerializedBook(TypedDict): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я такие типы предпочитаю селить в отдельный файл, тогда реже циклические импорты возникают.
books/views.py
Outdated
| def get_all_books_json_view(request: HttpResponse) -> HttpResponse: | ||
| books = Book.objects.all() | ||
| if not books: | ||
| return JsonResponse(data={'data': {}, 'error': 'No books found'}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Да говорю ж: если книг нету, это не ошибка, в дате будет пустой список, это значит шо книг нету, это норм. Избавься от этого ифа.
| from books.serializer import serialize_book | ||
|
|
||
|
|
||
| class Get_All_Books_Json_View(View): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Подчёркивания лишние, классы называем КемелКейсом
No description provided.