-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from LikeLion-at-DGU/lsj
✨ Feat : Add feature of chat app
- Loading branch information
Showing
14 changed files
with
208 additions
and
171 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 |
---|---|---|
@@ -1,48 +1,48 @@ | ||
# Generated by Django 4.2.5 on 2023-09-30 05:33 | ||
|
||
import core.models | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Booth', | ||
fields=[ | ||
('id', models.IntegerField(primary_key=True, serialize=False)), | ||
('name', models.CharField(max_length=255)), | ||
('type', models.CharField(choices=[('주간부스', '주간부스'), ('야간부스', '야간부스')], max_length=10)), | ||
('operater', models.CharField(max_length=255)), | ||
('location', models.CharField(choices=[('사회과학관', '사회과학관'), ('혜화관', '혜화관'), ('팔정도', '팔정도'), ('원흥관', '원흥관'), ('만해광장', '만해광장'), ('학생회관', '학생회관'), ('학림관', '학림관')], max_length=10)), | ||
('description', models.CharField(max_length=255)), | ||
('start_at', models.DateTimeField(blank=True, null=True)), | ||
('end_at', models.DateTimeField(blank=True, null=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Booth_like', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('key', models.CharField(blank=True, editable=False, max_length=10)), | ||
('booth', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='likes', to='booth.booth')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Booth_image', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('image', models.ImageField(blank=True, null=True, upload_to=core.models.image_upload_path)), | ||
('booth', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='boothimages', to='booth.booth')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] | ||
# Generated by Django 4.2.5 on 2023-10-01 13:47 | ||
|
||
import core.models | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Booth', | ||
fields=[ | ||
('id', models.IntegerField(primary_key=True, serialize=False)), | ||
('name', models.CharField(max_length=255)), | ||
('type', models.CharField(choices=[('주간부스', '주간부스'), ('야간부스', '야간부스')], max_length=10)), | ||
('operater', models.CharField(max_length=255)), | ||
('location', models.CharField(choices=[('사회과학관', '사회과학관'), ('혜화관', '혜화관'), ('팔정도', '팔정도'), ('원흥관', '원흥관'), ('만해광장', '만해광장'), ('학생회관', '학생회관'), ('학림관', '학림관')], max_length=10)), | ||
('description', models.CharField(max_length=255)), | ||
('start_at', models.DateTimeField(blank=True, null=True)), | ||
('end_at', models.DateTimeField(blank=True, null=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Booth_like', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('key', models.CharField(blank=True, editable=False, max_length=10)), | ||
('booth', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='likes', to='booth.booth')), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Booth_image', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('image', models.ImageField(blank=True, null=True, upload_to=core.models.booth_image_upload_path)), | ||
('booth', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='boothimages', to='booth.booth')), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 +1,5 @@ | ||
from django.contrib import admin | ||
from .models import* | ||
|
||
# Register your models here. | ||
admin.site.register(Chat) |
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
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,4 @@ | ||
from rest_framework.pagination import PageNumberPagination | ||
|
||
class ChatPagination(PageNumberPagination): | ||
page_size = 10 |
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,12 @@ | ||
from rest_framework import serializers | ||
from .models import Chat | ||
|
||
class ChatSerializer(serializers.ModelSerializer): | ||
is_abused = serializers.BooleanField(read_only=True, default=False) | ||
|
||
# 욕설 필터링 기능 추가 예정 | ||
def get_is_abused(self, obj): | ||
return obj.is_abused | ||
class Meta: | ||
model = Chat | ||
fields = ['id', 'content', 'icon', 'is_abused', 'key'] |
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,13 @@ | ||
from django.urls import path, include | ||
from rest_framework import routers | ||
|
||
from .views import * | ||
|
||
app_name = 'chat' | ||
|
||
default_router = routers.SimpleRouter(trailing_slash=False) | ||
default_router.register('chat', ChatViewSet, basename='chat') | ||
|
||
urlpatterns = [ | ||
path('', include(default_router.urls)), | ||
] |
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,3 +1,52 @@ | ||
from django.shortcuts import render | ||
|
||
from rest_framework import mixins, viewsets, status | ||
from rest_framework.decorators import action | ||
from .models import * | ||
from .serializers import ChatSerializer | ||
from rest_framework.response import Response | ||
from .paginations import ChatPagination | ||
# Create your views here. | ||
|
||
class ChatViewSet(viewsets.GenericViewSet, mixins.CreateModelMixin, mixins.RetrieveModelMixin, mixins.ListModelMixin): | ||
# queryset 가져오는 함수 오버라이딩 (최신순으로 정렬) | ||
def get_queryset(self): | ||
queryset = Chat.objects.all().order_by('created_at') | ||
return queryset | ||
serializer_class = ChatSerializer | ||
pagination_class = ChatPagination | ||
|
||
def create(self, reqest): | ||
serializer = self.get_serializer(data=reqest.data) | ||
serializer.is_valid(raise_exception=True) | ||
self.perform_create(serializer) | ||
serializer.save() | ||
return Response(serializer.data, status=status.HTTP_201_CREATED) | ||
|
||
# 방명록의 왼쪽 열에 대한 api | ||
@action(detail=False, methods=['GET'], url_path='dataleft') | ||
def dataleft(self, request): | ||
# id가 홀수인 방명록만 가져오기 | ||
dataleft = self.get_queryset().extra(where=["id % 2 = 1"]) | ||
page = self.paginate_queryset(dataleft) | ||
|
||
if page is not None: | ||
serializer = self.get_serializer(page, many=True) | ||
return self.get_paginated_response(serializer.data) | ||
|
||
serializer = self.get_serializer(dataleft, many=True) | ||
return Response(serializer.data) | ||
|
||
|
||
# 방명록의 오른쪽 열에 대한 api | ||
@action(detail=False, methods=['GET'], url_path='dataright') | ||
def dataright(self, request): | ||
# id가 짝수인 방명록만 가져오기 | ||
dataright = self.get_queryset().extra(where=["id % 2 = 0"]) | ||
page = self.paginate_queryset(dataright) | ||
|
||
if page is not None: | ||
serializer = self.get_serializer(page, many=True) | ||
return self.get_paginated_response(serializer.data) | ||
|
||
serializer = self.get_serializer(dataright, many=True) | ||
return Response(serializer.data) |
Oops, something went wrong.