Repository: NSS-Day-Cohort-71/bangazon-api-ctrl-alt-elite
Issue category: Feature Request

Issue:
Feature: Users can create a store in order to sell items
**Given** a user clicks on the profile icon in the navbar
**And** the user has not created a store yet
**When** the _Interested in selling?_ option is chosen
**Then** the user should see a form to create a store with a text field for store name, and a textarea for store description

**Given** a user has filled out the store form
**When** the **Save** button is clicked
**Then** a new store should be created for the user
**And** the user should be shown the **My Store** view





Hints:

Patch:
diff --git a/bangazonapi/models/customer.py b/bangazonapi/models/customer.py
index a6d4cdd..61bf2e6 100644
--- a/bangazonapi/models/customer.py
+++ b/bangazonapi/models/customer.py
@@ -14,4 +14,12 @@ def recommends(self):
 
     @recommends.setter
     def recommends(self, value):
-        self.__recommends = value
\ No newline at end of file
+        self.__recommends = value
+
+    @property
+    def store(self):
+        return self.__store
+    
+    @store.setter
+    def store(self, value):
+        self.__store = value
\ No newline at end of file
diff --git a/bangazonapi/models/store.py b/bangazonapi/models/store.py
index af288df..e92b3a8 100644
--- a/bangazonapi/models/store.py
+++ b/bangazonapi/models/store.py
@@ -5,4 +5,10 @@ class Store(models.Model):
     description = models.TextField()
     seller = models.ForeignKey('Customer', on_delete=models.CASCADE)  # Linking to Customer
 
-    # Use reverse relationship in views to access products
+    # Define a many-to-many relationship through a separate table
+    products = models.ManyToManyField('Product', through='StoreProduct', related_name='stores')
+
+class StoreProduct(models.Model):
+    store = models.ForeignKey(Store, on_delete=models.CASCADE)
+    product = models.ForeignKey('Product', on_delete=models.CASCADE)
+    # Additional fields if needed
\ No newline at end of file
diff --git a/bangazonapi/views/profile.py b/bangazonapi/views/profile.py
index 7c5d4dd..9d23753 100644
--- a/bangazonapi/views/profile.py
+++ b/bangazonapi/views/profile.py
@@ -8,12 +8,12 @@
 from rest_framework.permissions import IsAuthenticatedOrReadOnly
 from rest_framework.response import Response
 from rest_framework.viewsets import ViewSet
-from bangazonapi.models import Order, Customer, Product
+from bangazonapi.models import Order, Customer, Product, Store
 from bangazonapi.models import OrderProduct, Favorite
 from bangazonapi.models import Recommendation
 from .product import ProductSerializer
 from .order import OrderSerializer
-
+from .store import StoreSerializer
 
 class Profile(ViewSet):
     """Request handlers for user profile info in the Bangazon Platform"""
@@ -87,6 +87,9 @@ def list(self, request):
             current_user.recommends = Recommendation.objects.filter(
                 recommender=current_user
             )
+            current_user.store = Store.objects.get(
+                seller_id = current_user
+            )
 
             serializer = ProfileSerializer(
                 current_user, many=False, context={"request": request}
@@ -397,6 +400,7 @@ class ProfileSerializer(serializers.ModelSerializer):
 
     user = UserSerializer(many=False)
     recommends = RecommenderSerializer(many=True)
+    store = StoreSerializer(many=False, read_only=True)
 
     class Meta:
         model = Customer
@@ -408,6 +412,7 @@ class Meta:
             "address",
             "payment_types",
             "recommends",
+            "store",
         )
         depth = 1
 
diff --git a/bangazonapi/views/store.py b/bangazonapi/views/store.py
index d2bc926..906c803 100644
--- a/bangazonapi/views/store.py
+++ b/bangazonapi/views/store.py
@@ -11,7 +11,7 @@ class StoreSellerSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = Customer
-        fields = ('first_name', 'last_name')
+        fields = ('first_name', 'last_name', 'id')
 
 class StoreProductSerializer(serializers.ModelSerializer):
     """JSON serializer for products in a store"""
@@ -28,7 +28,7 @@ class StoreSerializer(serializers.ModelSerializer):
 
     class Meta:
         model = Store
-        fields = ('id', 'name', 'description', 'seller', 'products')
+        fields = ('id', 'name', 'description', 'seller', 'products', 'seller_id')
 
 class StoreViewSet(ViewSet):
     """View for handling requests about stores"""
@@ -53,3 +53,12 @@ def create(self, request):
         print("Store Created with ID:", new_store.id)  # Debugging log for backend
         print("Serialized data:", serializer.data)  # Add this log for debugging
         return Response(serializer.data, status=status.HTTP_201_CREATED)
+    
+    def retrieve(self, request, pk=None):
+        """GET a single store by ID"""
+        try:
+            store = Store.objects.get(pk=pk)
+            serializer = StoreSerializer(store)
+            return Response(serializer.data, status=status.HTTP_200_OK)
+        except Store.DoesNotExist:
+            return Response({'message': 'Store not found.'}, status=status.HTTP_404_NOT_FOUND)
\ No newline at end of file


Test patch: