-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
121 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Generated by Django 5.1.1 on 2025-01-11 07:01 | ||
|
||
import django.db.models.deletion | ||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("market", "0003_service_suspended"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Report", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("reason", models.CharField(max_length=255)), | ||
("details", models.TextField(blank=True, null=True)), | ||
("created_at", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"reported_user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="reports_received", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"reporter_user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="reports_made", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 5.1.1 on 2025-01-11 07:03 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("market", "0004_report"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterModelTable( | ||
name="report", | ||
table="report", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...rs/report_serializer/ReporterSerialzer.py → .../report_serializer/reporter_serializer.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
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'] | ||
fields = ["reported_user", "reporter_user", "reason", "details"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,47 @@ | ||
# 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 rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from market.models import Report | ||
from market.serializers.report_serializer.ReporterSerializer import ReportSerializer | ||
from market.serializers.report_serializer.reporter_serializer import ReportSerializer | ||
from users.models.user import User | ||
|
||
|
||
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']) | ||
reported_user = User.objects.get(id=data["reported_user_id"]) | ||
reporter_user = User.objects.get(id=request.user.id) | ||
|
||
|
||
report = Report.objects.create( | ||
report: Report = Report.objects.create( | ||
reported_user=reported_user, | ||
reporter_user=reporter_user, | ||
reason=data['reason'], | ||
details=data.get('details', '') | ||
reason=data["reason"], | ||
details=data.get("details", ""), | ||
) | ||
|
||
serializer = ReportSerializer(instance=report) | ||
|
||
report_count = Report.objects.filter(reported_user=reported_user).count() | ||
serializer.data["report_count"] = report_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(data=serializer.data, status=status.HTTP_200_OK) | ||
|
||
return Response({ | ||
"status": "success", | ||
"message": "신고가 접수되었습니다." | ||
}, status=status.HTTP_201_CREATED) | ||
return Response(data=serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
except User.DoesNotExist: | ||
return Response({ | ||
"status": "error", | ||
"message": "사용자를 찾을 수 없습니다." | ||
}, status=status.HTTP_404_NOT_FOUND) | ||
return Response( | ||
{"status": "error", "message": "사용자를 찾을 수 없습니다."}, | ||
status=status.HTTP_404_NOT_FOUND, | ||
) | ||
except Exception as e: | ||
return Response( | ||
data={"status": "error", "details": str(e)}, | ||
status=status.HTTP_500_INTERNAL_SERVER_ERROR, | ||
) |