Skip to content

Commit

Permalink
Merge pull request #37 from rkshaon/rkshaon
Browse files Browse the repository at this point in the history
deploy, backend, frontend
  • Loading branch information
rkshaon authored Sep 12, 2024
2 parents fd98266 + 0c4bd8f commit fe1f6d5
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/book_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class BookAdmin(admin.ModelAdmin):
list_display = [
'id', 'book_code', 'title', 'cover', 'edition',
'isbn', 'published_date', 'language',
'is_deleted',
'is_deleted', 'uploader',
]

@admin.display(boolean=True)
Expand Down
4 changes: 4 additions & 0 deletions backend/book_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class Book(models.Model):
def cover(self) -> bool:
return bool(self.cover_image)

@property
def uploader(self):
return self.added_by

def __str__(self):
authors = ", ".join([
author.full_name for author in self.authors.all()
Expand Down
8 changes: 5 additions & 3 deletions backend/user_api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
@admin.register(User)
class UserAdmin(admin.ModelAdmin):
list_display = (
'id', 'username', 'email', 'role', 'is_active',
'id', 'full_name', 'username', 'email', 'role', 'is_active',
'is_staff', 'is_superuser',
)
list_display_links = ('id', 'username', 'email')
list_display_links = ['id', 'full_name', 'username', 'email']
list_filter = ('role', 'is_active', 'is_staff')
search_fields = ('username', 'email')
search_fields = [
'username', 'email', 'full_name'
]
readonly_fields = ('id',)
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.1.1 on 2024-09-12 18:06

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('user_api', '0002_remove_user_is_private'),
]

operations = [
migrations.AddField(
model_name='user',
name='middle_name',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='user',
name='first_name',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='user',
name='last_name',
field=models.CharField(blank=True, max_length=255, null=True),
),
]
28 changes: 28 additions & 0 deletions backend/user_api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ class User(AbstractUser):
(3, 'Reader'),
)

first_name = models.CharField(
max_length=255, blank=True, null=True
)
middle_name = models.CharField(
max_length=255, blank=True, null=True
)
last_name = models.CharField(
max_length=255, blank=True, null=True
)
email = models.EmailField(unique=True)
username = models.CharField(
max_length=50,
Expand All @@ -47,5 +56,24 @@ class User(AbstractUser):
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username', 'role']

@property
def full_name(self) -> str:
name = ""

if self.first_name:
name += f"{self.first_name}"

if self.middle_name:
if name:
name += f" {self.middle_name}"
else:
name += f"{self.middle_name}"

if self.last_name:
if name:
name += f" {self.last_name}"
else:
name += f"{self.last_name}"

def __str__(self):
return self.email
1 change: 1 addition & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ python manage.py migrate
echo -e "${BLUE}Restart Backend Gunicorn Service${RESET}"
echo -e "${YELLOW}=======================================${RESET}"
systemctl restart gunicorn-bookshelf.service
systemctl status gunicorn-bookshelf.service

echo -e "${RED}Finish${RESET}..."
32 changes: 24 additions & 8 deletions frontend/src/pages/HomePage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,34 @@
Explore a vast collection of books, share your reviews, and connect with other book lovers.
</p>
</div>
<div class="flex justify-between mt-8 mb-8">
<div v-if="previousPage" class="flex-1">
<button @click="fetchBooks(previousPage)" class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Previous
</button>
</div>
<div class="flex-1"></div>
<div v-if="nextPage" class="flex-1 text-right">
<button @click="fetchBooks(nextPage)" class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Next
</button>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
<BookCardComponent v-for="(book, index) in books" :key="index" :book="book" />
</div>
<div class="flex justify-between mt-8">
<button v-if="previousPage" @click="fetchBooks(previousPage)"
class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Previous
</button>
<button v-if="nextPage" @click="fetchBooks(nextPage)"
class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Next
</button>
<div v-if="previousPage" class="flex-1">
<button @click="fetchBooks(previousPage)" class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Previous
</button>
</div>
<div class="flex-1"></div>
<div v-if="nextPage" class="flex-1 text-right">
<button @click="fetchBooks(nextPage)" class="bg-blue-500 text-white py-2 px-4 rounded hover:bg-blue-600">
Next
</button>
</div>
</div>
</main>
</template>
Expand Down

0 comments on commit fe1f6d5

Please sign in to comment.