Skip to content

Commit

Permalink
added report and suggestion models, serializers, viewsets, and url paths
Browse files Browse the repository at this point in the history
  • Loading branch information
purple-void committed Aug 13, 2024
1 parent eb9f5d8 commit d2e99b5
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
44 changes: 44 additions & 0 deletions backend/core/migrations/0012_report_alter_post_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 5.0.7 on 2024-08-13 23:02

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("core", "0011_rename_createdat_post_created_and_more"),
]

operations = [
migrations.CreateModel(
name="Report",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("ownerUserId", models.IntegerField(null=True)),
("parentId", models.IntegerField(null=True)),
("body", models.TextField()),
("created", models.DateTimeField(auto_now_add=True)),
],
),
migrations.AlterField(
model_name="post",
name="type",
field=models.CharField(
choices=[
("argument", "argument"),
("rebuttal", "rebuttal"),
("comment", "comment"),
("suggestion", "suggestion"),
],
default="argument",
max_length=10,
),
),
]
9 changes: 9 additions & 0 deletions backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
ARGUMENT = "argument"
REBUTTAL = "rebuttal"
COMMENT = "comment"
SUGGESTION = "suggestion"
POST_TYPES = [
(ARGUMENT, "argument"),
(REBUTTAL, "rebuttal"),
(COMMENT, "comment"),
(SUGGESTION, "suggestion"),
]
UPVOTE = "upvote"
DOWNVOTE = "downvote"
Expand All @@ -38,6 +40,13 @@ class Post(models.Model):
updated: models.DateTimeField = models.DateTimeField(auto_now=True)


class Report(models.Model):
ownerUserId: models.IntegerField = models.IntegerField(null=True)
parentId: models.IntegerField = models.IntegerField(null=True)
body: models.TextField = models.TextField()
created: models.DateTimeField = models.DateTimeField(auto_now_add=True)


class UserProfile(models.Model):
# Public
user: models.OneToOneField = models.OneToOneField(
Expand Down
20 changes: 19 additions & 1 deletion backend/core/serializers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from rest_framework import serializers

from .models import Post, UserProfile, Vote
from .models import Post, Report, UserProfile, Vote


class ArgumentSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -46,6 +46,24 @@ class Meta:
]


class ReportSerializer(serializers.ModelSerializer):
class Meta:
model = Report
fields = "__all__"
read_only_fields = [
"ownerUserId",
]


class SuggestionSerializer(serializers.ModelSerializer):
class Meta:
model = Post
fields = "__all__"
read_only_fields = [
"ownerUserId",
]


class VoteSerializer(serializers.ModelSerializer):
class Meta:
model = Vote
Expand Down
38 changes: 38 additions & 0 deletions backend/core/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from djoser.views import UserViewSet
from drf_spectacular.utils import OpenApiParameter, extend_schema
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.pagination import CursorPagination
from rest_framework.permissions import (
SAFE_METHODS,
Expand All @@ -18,6 +19,8 @@
CommentSerializer,
PostSerializer,
RebuttalSerializer,
ReportSerializer,
SuggestionSerializer,
UserProfileSerializer,
VoteSerializer,
)
Expand Down Expand Up @@ -76,6 +79,21 @@ def get_permissions(self):
return [IsOwnerOrReadOnly()]
return [AllowAny()]

@action(detail=True, url_path="reports/add", methods=["post"])
def add_reports(self):
# put your code here
print("test")

@action(detail=True, url_path="reports/options", methods=["get"])
def reports_options(self):
# put your code here
print("test")

@action(detail=True, url_path="suggest-edit", methods=["post"])
def suggest_edit(self):
# put your code here
print("test")


class RebuttalViewSet(viewsets.ModelViewSet):
serializer_class = RebuttalSerializer
Expand Down Expand Up @@ -149,6 +167,26 @@ def get_permissions(self):
return [AllowAny()]


class ReportViewSet(viewsets.ModelViewSet):
serializer_class = ReportSerializer
pagination_class = CursorPaginationViewSet

def get_queryset(self):
# gets all upvotes
queryset = Vote.objects.filter(type="report")
return queryset


class SuggestionViewSet(viewsets.ModelViewSet):
serializer_class = SuggestionSerializer
pagination_class = CursorPaginationViewSet

def get_queryset(self):
# gets all upvotes
queryset = Vote.objects.filter(type="suggestion")
return queryset


class UserProfileViewSet(viewsets.ModelViewSet):
serializer_class = UserProfileSerializer
pagination_class = CursorPaginationViewSet
Expand Down

0 comments on commit d2e99b5

Please sign in to comment.