diff --git a/Backend/accounts/saving/urls.py b/Backend/accounts/saving/urls.py index eddeb0b3..1ff6ca6e 100644 --- a/Backend/accounts/saving/urls.py +++ b/Backend/accounts/saving/urls.py @@ -1,11 +1,12 @@ from django.urls import path, include from rest_framework.routers import DefaultRouter -from .views import UserProfileViewSet, ArtistPortfolioViewSet +from .views import UserProfileViewSet, ArtistPortfolioViewSet, ProfileUploadView router = DefaultRouter() router.register(r'user-profile', UserProfileViewSet, basename='user-profile') router.register(r'artist-portfolio', ArtistPortfolioViewSet, basename='artist-portfolio') urlpatterns = [ - path('api/', include(router.urls)), + path('', include(router.urls)), + path('api/profile/', ProfileUploadView.as_view(), name='profile-upload'), ] diff --git a/Backend/accounts/saving/views.py b/Backend/accounts/saving/views.py index 790c3e40..05742e4f 100644 --- a/Backend/accounts/saving/views.py +++ b/Backend/accounts/saving/views.py @@ -1,9 +1,15 @@ +import logging from rest_framework import status, viewsets from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated +from rest_framework.views import APIView +from rest_framework.parsers import MultiPartParser, FormParser from .models import Customer, ArtistPortfolio from .serializers import UserProfileSerializer, ArtistPortfolioSerializer +# Set up logging +logger = logging.getLogger(__name__) + class UserProfileViewSet(viewsets.ModelViewSet): queryset = Customer.objects.all() serializer_class = UserProfileSerializer @@ -19,14 +25,43 @@ class ArtistPortfolioViewSet(viewsets.ModelViewSet): serializer_class = ArtistPortfolioSerializer permission_classes = [IsAuthenticated] - def perform_create(self, serializer): - # Attempt to get the existing user profile - user_profile = Customer.objects.filter(firebase_user_id=self.request.user.uid).first() - + def create(self, request, *args, **kwargs): + user_profile = Customer.objects.filter(firebase_user_id=request.user.uid).first() + if not user_profile: return Response( {"detail": "User profile not found. Please create a profile first."}, status=status.HTTP_400_BAD_REQUEST ) + serializer = self.get_serializer(data=request.data) + serializer.is_valid(raise_exception=True) serializer.save(user_profile=user_profile) + headers = self.get_success_headers(serializer.data) + return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers) + +class ProfileUploadView(APIView): + parser_classes = (MultiPartParser, FormParser) + + def post(self, request, *args, **kwargs): + try: + business_name = request.data.get('business_name') + bio = request.data.get('bio') + profile_picture = request.FILES.get('profile_picture') + photos = request.FILES.getlist('photos') + + # Log data (replace this with database saving logic if needed) + logger.info(f'Business Name: {business_name}') + logger.info(f'Bio: {bio}') + logger.info(f'Profile Picture: {profile_picture}') + logger.info(f'Photos: {photos}') + + # Save logic here if applicable + + return Response({'message': 'Portfolio saved successfully!'}, status=status.HTTP_200_OK) + except Exception as e: + logger.error('Error saving portfolio:', exc_info=True) + return Response( + {'message': 'Failed to save portfolio. Please try again.'}, + status=status.HTTP_500_INTERNAL_SERVER_ERROR + ) diff --git a/next.config.mjs b/next.config.mjs index a58e2393..4678774e 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,4 @@ /** @type {import('next').NextConfig} */ const nextConfig = {}; -export default nextConfig; \ No newline at end of file +export default nextConfig;