Skip to content

Commit

Permalink
Base models for subscriptions, reivews, shops, gallery, and images
Browse files Browse the repository at this point in the history
  • Loading branch information
miclemabasie committed Feb 16, 2024
1 parent 2e200f5 commit 2ef7095
Show file tree
Hide file tree
Showing 33 changed files with 207 additions and 29 deletions.
10 changes: 6 additions & 4 deletions src/LMA/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@
"apps.profiles.apps.ProfilesConfig",
"apps.orders.apps.OrdersConfig",
"apps.customers.apps.CustomersConfig",
"apps.gallery.apps.GalleyConfig",
"apps.shop.apps.ShopConfig"
"apps.gallery.apps.GalleryConfig",
"apps.shop.apps.ShopConfig",
"apps.subscriptions.apps.SubscriptionsConfig",
"apps.reviews.apps.ReviewsConfig"
]


INSTALLED_APPS = DJANGO_APPS + THRID_PARTY_APPS + LOCAL_APPS

MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
Expand Down Expand Up @@ -177,7 +179,7 @@
"USERNAME_RESET_CONFIRM_URL": "email/reset/confirm/{uid}/{token}",
"ACTIVATION_URL": "activate/{uid}/{token}",
"SEND_ACTIVATION_EMAIL": True,
'ACTIVATION_EMAIL_HTML_TEMPLATE': 'djoseer.templates.email.activation.html',
"ACTIVATION_EMAIL_HTML_TEMPLATE": "djoseer.templates.email.activation.html",
# 'ACTIVATION_EMAIL_PLAIN_TEMPLATE': 'path/to/custom_activation_email.txt',
}

Expand Down
9 changes: 4 additions & 5 deletions src/apps/common/views.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from django.shortcuts import render
from django.core.mail import send_mail
from rest_framework.response import Response
from rest_framework.decorators import api_view,permission_classes
from rest_framework.decorators import api_view, permission_classes
from rest_framework import permissions


@api_view(["GET"])
def test_send_mail(request):
send_mail(
subject="Test Mail",
message="This is just a test mail",
message="This is just a test mail",
from_email="[email protected]",
recipient_list=["[email protected]"]
recipient_list=["[email protected]"],
)

return Response({"message": "mail was sent!"})
Expand All @@ -26,5 +26,4 @@ def js_test_rout(request):
"username": "miclemabasie",
}


return Response(data)
return Response(data)
1 change: 0 additions & 1 deletion src/apps/core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from django.db import models

# Create your models here.

2 changes: 1 addition & 1 deletion src/apps/customers/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
path("<str:pkid>/", views.customer_detail_view, name="customer-detail"),
path("update/<str:pkid>/", views.customer_update_view, name="customer-update"),
path("delete/<str:pkid>/", views.customer_delete_view, name="customer-delete"),
]
]
26 changes: 17 additions & 9 deletions src/apps/customers/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from rest_framework import status


@api_view(["GET"])
@permission_classes([permissions.IsAuthenticated])
def customer_list_view(request):
Expand All @@ -29,35 +30,41 @@ def customer_detail_view(request, pkid, *a, **kw):
try:
customer = Customer.objects.get(pkid=pkid)
except Customer.DoesNotExist:
return Response({"error": "Customer with does not exist"}, status.HTTP_400_BAD_REQUEST)

return Response(
{"error": "Customer with does not exist"}, status.HTTP_400_BAD_REQUEST
)

serializer = CustomerSerializer(customer)

namespaced_response = {"customer": serializer.data}
return Response(namespaced_response, status=status.HTTP_200_OK)


@api_view(["PATCH"])
@permission_classes([permissions.IsAuthenticated])
def customer_update_view(request, pkid, *a, **kw):
try:
customer = Customer.objects.get(pkid=pkid)
except Customer.DoesNotExist:
return Response({"error": "Customer with does not exist"}, status.HTTP_400_BAD_REQUEST)
return Response(
{"error": "Customer with does not exist"}, status.HTTP_400_BAD_REQUEST
)
serializer = CustomerSerializer(instance=customer, data=request.data, partial=True)
if serializer.is_valid():
serializer.save()
return Response({"success": "Customer updated!"})
return Response({"error": serializer.errors})



@api_view(["DELETE"])
@permission_classes([permissions.IsAuthenticated])
def customer_delete_view(request, pkid, *a, **kw):
try:
customer = Customer.objects.get(pkid=pkid)
except Customer.DoesNotExist:
return Response({"error": "Customer with does not exist"}, status.HTTP_400_BAD_REQUEST)
return Response(
{"error": "Customer with does not exist"}, status.HTTP_400_BAD_REQUEST
)
customer.delete()
return Response({"success": "Customer Successfully deleted"})

Expand All @@ -67,15 +74,16 @@ def customer_delete_view(request, pkid, *a, **kw):
def customer_create_view(request):
data = request.data
# Check if customer with credentials already exists
name = data['name']
phone = data['phone_number']
name = data["name"]
phone = data["phone_number"]
serializer = CustomerSerializer(data=data)
if serializer.is_valid():
# Check customer with same info
customer, created = Customer.objects.get_or_create(name=name, phone_number=phone)
customer, created = Customer.objects.get_or_create(
name=name, phone_number=phone
)
customer.save()
serializer = CustomerSerializer(customer)
if created:
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

4 changes: 2 additions & 2 deletions src/apps/gallery/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class GalleryConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'gallery'
default_auto_field = "django.db.models.BigAutoField"
name = "apps.gallery"
19 changes: 18 additions & 1 deletion src/apps/gallery/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
from django.db import models
from apps.common.models import TimeStampedUUIDModel
from django.utils.translation import gettext_lazy as _
from apps.shop.models import Shop

# Create your models here.
class Image(TimeStampedUUIDModel):
gallery = models.OneToOneField("Gallery", related_name="images", on_delete=models.CASCADE, verbose_name="Gallery")
name = models.CharField(verbose_name=_("Image Name"), max_length=200)
image = models.ImageField(
verbose_name=_("Gallery Photo"), upload_to="galleries"
)


class Gallery(TimeStampedUUIDModel):
shop = models.OneToOneField(Shop, related_name="gallery", on_delete=models.CASCADE)
max_photos = models.PositiveIntegerField(default=0)


def __str__(self):
return f"Gallery - {self.shop.shop_name}"
2 changes: 1 addition & 1 deletion src/apps/orders/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
path("<str:transaction_id>", views.order_detail_view, name="order-detail"),
path("create/", views.create_order_view, name="order-create"),
path("update/<str:transaction_id>/", views.update_order_view, name="order-update"),
path("delete/<str:transaction_id>/", views.delete_order_view, name="order-delete")
path("delete/<str:transaction_id>/", views.delete_order_view, name="order-delete"),
]
3 changes: 1 addition & 2 deletions src/apps/orders/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ def order_detail_view(request, transaction_id):
return Response(namespaced_data)



@api_view(["GET"])
@permission_classes([permissions.IsAuthenticated])
def orderitem_list_view(request):
Expand Down Expand Up @@ -111,4 +110,4 @@ def delete_order_view(reqeust, transaction_id, *a, **kw):
return Response({"error": "Order with this id does not exist!"})

order.delete()
return Response({"success": "Order has been successfully deleted."})
return Response({"success": "Order has been successfully deleted."})
10 changes: 10 additions & 0 deletions src/apps/profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@ class Gender(models.TextChoices):
OTHER = "Other", _("Other")


class PROFILE_TYPES(models.TextChoices):
SHOP_OWNDER = "shop_owner", _("Shop Owner")
SHOP_STAFF = "shop_staff", _("Shop Staff")
CUSTOMER = "customer", _("Customer")


class Profile(TimeStampedUUIDModel):

user = models.OneToOneField(User, related_name="profile", on_delete=models.CASCADE)
phone_number = PhoneNumberField(
verbose_name=_("Phone Number"), max_length=30, default="+237680672888"
Expand All @@ -42,6 +49,9 @@ class Profile(TimeStampedUUIDModel):
blank=False,
null=False,
)
profile_type = models.CharField(
max_length=20, choices=PROFILE_TYPES.choices, default=PROFILE_TYPES.CUSTOMER
)

def __str__(self):
return f"{self.user.username}'s profile"
Empty file added src/apps/reviews/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions src/apps/reviews/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions src/apps/reviews/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ReviewsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.reviews'
Empty file.
28 changes: 28 additions & 0 deletions src/apps/reviews/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.db import models
from django.contrib.auth import get_user_model
from apps.shop.models import Shop
from apps.common.models import TimeStampedUUIDModel
from django.utils.translation import gettext_lazy as _
from django.core.validators import MinValueValidator, MaxValueValidator

User = get_user_model()

class Review(TimeStampedUUIDModel):
RATING_CHOICES = (
(1, '1 - Poor'),
(2, '2 - Below Average'),
(3, '3 - Average'),
(4, '4 - Good'),
(5, '5 - Excellent')
)
user = models.ForeignKey(User, related_name="reviews", on_delete=models.CASCADE)
shop = models.ForeignKey(Shop, related_name="reviews", on_delete=models.CASCADE)
rating = models.IntegerField(choices=RATING_CHOICES, validators=[MinValueValidator(1), MaxValueValidator(5)])
comment = models.TextField()


class Meta:
unique_together = ["user", "shop"]

def __str__(self):
return f"{self.user.username} - {self.shop.shop_name} Review"
3 changes: 3 additions & 0 deletions src/apps/reviews/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions src/apps/reviews/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Empty file added src/apps/settings/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions src/apps/settings/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions src/apps/settings/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class SettingsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.settings'
Empty file.
1 change: 1 addition & 0 deletions src/apps/settings/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from django.db import models
3 changes: 3 additions & 0 deletions src/apps/settings/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions src/apps/settings/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
4 changes: 2 additions & 2 deletions src/apps/shop/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@


class ShopConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'shop'
default_auto_field = "django.db.models.BigAutoField"
name = "apps.shop"
43 changes: 42 additions & 1 deletion src/apps/shop/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
from django.db import models
from django.contrib.auth import get_user_model
from apps.subscriptions.models import Subscription
from apps.common.models import TimeStampedUUIDModel
from django.utils.translation import gettext_lazy as _

# Create your models here.

User = get_user_model()


class Shop(TimeStampedUUIDModel):
user = models.ForeignKey(User, related_name="shop", on_delete=models.CASCADE)
subscription = models.OneToOneField(
Subscription, related_name="shop", on_delete=models.CASCADE
)
shop_name = models.CharField(
verbose_name=_("Shop Name"), max_length=200, unique=True
)
description = models.TextField(verbose_name=_("Description"))
Location = models.CharField(verbose_name=_("Loaction"), max_length=200)
is_verified = False

def __str__(self):
return f"Shop-{self.shop_name}"


class StaffMember(TimeStampedUUIDModel):
STAFF_ROLES = (
(1, "1 - Poor"),
(2, "2 - Below Average"),
(3, "3 - Average"),
(4, "4 - Good"),
(5, "5 - Excellent"),
)
shop = models.ForeignKey(
Shop, related_name="staff_members", on_delete=models.CASCADE
)
user = models.ForeignKey(User, on_delete=models.CASCADE)
role = models.CharField(
verbose_name=_("Staff Role"), max_length=20, choices=STAFF_ROLES
)

def __str__(self):
return f"{self.user.username} staff for {self.shop.name}"
Empty file.
3 changes: 3 additions & 0 deletions src/apps/subscriptions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions src/apps/subscriptions/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class SubscriptionsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.subscriptions'
Empty file.
29 changes: 29 additions & 0 deletions src/apps/subscriptions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from django.db import models
from apps.common.models import TimeStampedUUIDModel
from django.utils.translation import gettext_lazy as _
from django.contrib.auth import get_user_model

User = get_user_model()


class Subscription(TimeStampedUUIDModel):

PLAN_CHOICES = [
("basic", "Basic"),
("standard", "Standard"),
("premium", "Premium"),
]

transaction_id = models.CharField(
verbose_name=_("Transaction_id"), max_length=20, unique=True
)
shop_owner = models.ForeignKey(User, related_name="subscriptions", on_delete=models.CASCADE)
price = models.DecimalField(max_digits=10, decimal_places=2)
plan_type = models.CharField(verbose_name=_("Plan Type"), max_length=20, choices=PLAN_CHOICES)
start_data = models.DateTimeField()
end_data = models.DateTimeField()
is_active = models.BooleanField(default=False)


def __str__(self):
return f"subscription-{self.shop}"
3 changes: 3 additions & 0 deletions src/apps/subscriptions/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions src/apps/subscriptions/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.

0 comments on commit 2ef7095

Please sign in to comment.