Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 편지 주요 기능 구현 #13

Merged
merged 8 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions rememB/balanceapp/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions rememB/balanceapp/apps.py

This file was deleted.

15 changes: 0 additions & 15 deletions rememB/balanceapp/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions rememB/balanceapp/tests.py

This file was deleted.

6 changes: 0 additions & 6 deletions rememB/balanceapp/urls.py

This file was deleted.

3 changes: 0 additions & 3 deletions rememB/balanceapp/views.py

This file was deleted.

3 changes: 2 additions & 1 deletion rememB/letterapp/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib import admin
from .models import Letter

# Register your models here.
admin.site.register(Letter)
25 changes: 25 additions & 0 deletions rememB/letterapp/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1 on 2022-08-11 00:57

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Letter',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('content', models.TextField()),
('imgfolder_no', models.IntegerField()),
('img_no', models.IntegerField()),
('position_x', models.IntegerField()),
('position_y', models.IntegerField()),
],
),
]
18 changes: 18 additions & 0 deletions rememB/letterapp/migrations/0002_letter_created_at.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1 on 2022-08-11 01:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('letterapp', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='letter',
name='created_at',
field=models.DateTimeField(auto_now=True),
),
]
18 changes: 18 additions & 0 deletions rememB/letterapp/migrations/0003_alter_letter_imgfolder_no.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.1 on 2022-08-11 01:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('letterapp', '0002_letter_created_at'),
]

operations = [
migrations.AlterField(
model_name='letter',
name='imgfolder_no',
field=models.IntegerField(null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.1 on 2022-08-11 01:56

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('letterapp', '0003_alter_letter_imgfolder_no'),
]

operations = [
migrations.AlterField(
model_name='letter',
name='img_no',
field=models.IntegerField(null=True),
),
migrations.AlterField(
model_name='letter',
name='position_x',
field=models.IntegerField(null=True),
),
migrations.AlterField(
model_name='letter',
name='position_y',
field=models.IntegerField(null=True),
),
]
25 changes: 25 additions & 0 deletions rememB/letterapp/migrations/0005_letter_user_alter_letter_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.1 on 2022-08-11 02:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('userapp', '0004_alter_user_refreshtoken'),
('letterapp', '0004_alter_letter_img_no_alter_letter_position_x_and_more'),
]

operations = [
migrations.AddField(
model_name='letter',
name='user',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='userapp.user'),
),
migrations.AlterField(
model_name='letter',
name='id',
field=models.AutoField(primary_key=True, serialize=False),
),
]
File renamed without changes.
17 changes: 10 additions & 7 deletions rememB/letterapp/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from django.db import models

from userapp.models import User

class Letter(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE) # 유저와 연동
letter_content = models.CharField(max_length=300)
img_no = models.IntegerField()
id = models.AutoField(primary_key=True, null=False, blank=False)
user = models.ForeignKey(User, on_delete=models.CASCADE, null=True)
content = models.TextField()
imgfolder_no=models.IntegerField(null=True)
img_no = models.IntegerField(null=True)
created_at = models.DateTimeField(auto_now=True)
position_x = models.IntegerField()
position_y = models.IntegerField()

position_x = models.IntegerField(null=True)
position_y = models.IntegerField(null=True)

def __str__(self):
return self.content[:7]

19 changes: 19 additions & 0 deletions rememB/letterapp/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from rest_framework import serializers
from .models import *

class LetterSerializer(serializers.ModelSerializer):
#user=serializers.ReadOnlyField(source='user.uuid')
class Meta:
model=Letter
fields=('id','user','content','imgfolder_no','img_no','position_x','position_y','created_at')


class LetterDetailSerializer(serializers.ModelSerializer):
class Meta:
model=Letter
fields=('id','user','get_img','content')

class LetterSumSerializer(serializers.ModelSerializer):
class Meta:
model=Letter
fields=['id','user','content','created_at']
5 changes: 4 additions & 1 deletion rememB/letterapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
from . import views

urlpatterns=[

path('admin/',views.LetterList.as_view()), #전체 편지 조회
path('<int:userpk>/send/',views.LetterSend.as_view()), #userpk에게 편지 작성
path('<int:letterpk>/',views.LetterDetail.as_view()), #letterpk의 편지 디테일
path('<int:userpk>/list/',views.LetterUserList.as_view()), #userpk의 편지만 조회
]
62 changes: 60 additions & 2 deletions rememB/letterapp/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
from django.shortcuts import render
from .serializers import *
from .models import Letter, User
from rest_framework import viewsets
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import status
from django.http import Http404
from django.shortcuts import get_object_or_404

# Create your views here.

class LetterSend(APIView):
#userpk에게 편지 작성
def post(self, request, userpk):
user=get_object_or_404(User,pk=userpk)
serializer=LetterSerializer(data=request.data)
if serializer.is_valid():
serializer.save(user=user)
return Response(serializer.data, status=status.HTTP_201_CREATED)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

class LetterList(APIView):
#전체 편지 조회
def get(self, request):
letters=Letter.objects.all()
serializer=LetterSerializer(letters, many=True)
return Response(serializer.data)

class LetterUserList(APIView):
#userpk의 편지만 조회
def get(self,request,userpk):
user_letters=Letter.objects.filter(user=userpk)
serializer=LetterSerializer(user_letters, many=True)
return Response(serializer.data)


class LetterDetail(APIView):
def get_object(self, letterpk):
try:
return Letter.objects.get(pk=letterpk)
except Letter.DoesNotExist:
raise Http404

def get(self, request, letterpk):
letter=self.get_object(letterpk)
serializer=LetterSerializer(letter)
return Response(serializer.data)

#기능 구현 필요없음
def put(self, request, letterpk):
letter=self.get_object(letterpk)
serializer=LetterSerializer(letter,data=request.data)
if serializer.is_valid():
serializer.save()
return Response(serializer.data, status=status.HTTP_200_OK)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

#기능 구현 필요없음
def delete(self, request, letterpk):
letter=self.get_object(letterpk)
letter.delete()
return Response(status=status.HTTP_204_NO_CONTENT)
1 change: 0 additions & 1 deletion rememB/mainapp/admin.py

This file was deleted.

6 changes: 0 additions & 6 deletions rememB/mainapp/apps.py

This file was deleted.

3 changes: 0 additions & 3 deletions rememB/mainapp/models.py

This file was deleted.

3 changes: 0 additions & 3 deletions rememB/mainapp/tests.py

This file was deleted.

6 changes: 0 additions & 6 deletions rememB/mainapp/urls.py

This file was deleted.

1 change: 0 additions & 1 deletion rememB/mainapp/views.py

This file was deleted.

Loading