Skip to content

Commit

Permalink
신고기능 오류
Browse files Browse the repository at this point in the history
  • Loading branch information
haeunia committed Jan 8, 2025
1 parent 862974c commit 65d3533
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
14 changes: 14 additions & 0 deletions market/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
from market.managers import MarketManager, ServiceManager, ServiceMaterialManager
from users.models.reformer import Reformer

from django.db import models
from django.contrib.auth.models import User

def get_market_thumbnail_upload_path(instance, filename):
email_name = instance.reformer.user.email.split("@")[0]
Expand Down Expand Up @@ -154,3 +156,15 @@ class ServiceOptionImage(TimeStampedModel):

class Meta:
db_table = "market_service_option_image"

class Report(models.Model):
reported_user = models.ForeignKey(User, related_name="reports_received", on_delete=models.CASCADE)
reporter_user = models.ForeignKey(User, related_name="reports_made", on_delete=models.CASCADE)
reason = models.CharField(max_length=255)
details = models.TextField(blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"Report against {self.reported_user.username} by {self.reporter_user.username}"


8 changes: 8 additions & 0 deletions market/serializers/market_serializers/market_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

from market.models import Market

from rest_framework import serializers
from market.models import Report

class ReportSerializer(serializers.ModelSerializer):
class Meta:
model = Report
fields = ['reported_user', 'reporter_user', 'reason', 'details']


class MarketSerializer(serializers.ModelSerializer):
market_uuid = serializers.UUIDField(read_only=True)
Expand Down
7 changes: 7 additions & 0 deletions market/serializers/report_serializer/ReporterSerialzer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from market.models import Report

class ReportSerializer(serializers.ModelSerializer):
class Meta:
model = Report
fields = ['reported_user', 'reporter_user', 'reason', 'details']
Empty file.
5 changes: 4 additions & 1 deletion market/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ServiceStyleCreateListView,
ServiceStyleView,
)

from market.views.report_views import ReportUserView
urlpatterns = [
path("", MarketCreateListView.as_view(), name="market_create_list"),
path(
Expand Down Expand Up @@ -83,4 +83,7 @@
ServiceOptionImageUploadView.as_view(),
name="market_service_option_image_upload",
),
path('report/', ReportUserView.as_view(), name='report_user'),

]

48 changes: 48 additions & 0 deletions market/views/report_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# market/views/report_views.py

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from django.contrib.auth.models import User
from market.models import Report
from market.serializers.report_serializer.ReporterSerializer import ReportSerializer


class ReportUserView(APIView):
def post(self, request):
data = request.data
try:
reported_user = User.objects.get(id=data['reported_user_id'])
reporter_user = User.objects.get(id=data['reporter_user_id'])


report = Report.objects.create(
reported_user=reported_user,
reporter_user=reporter_user,
reason=data['reason'],
details=data.get('details', '')
)


report_count = Report.objects.filter(reported_user=reported_user).count()


if report_count >= 5:
reported_user.is_active = False
reported_user.save()

return Response({
"status": "success",
"message": "신고가 접수되었으며, 해당 사용자의 서비스가 중단됩니다."
}, status=status.HTTP_200_OK)

return Response({
"status": "success",
"message": "신고가 접수되었습니다."
}, status=status.HTTP_201_CREATED)

except User.DoesNotExist:
return Response({
"status": "error",
"message": "사용자를 찾을 수 없습니다."
}, status=status.HTTP_404_NOT_FOUND)

0 comments on commit 65d3533

Please sign in to comment.