권주희

add root folder for main folder

# Generated by Django 3.0.6 on 2020-06-11 15:29
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('api', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='user',
name='root_folder',
field=models.IntegerField(null=True),
),
migrations.AlterField(
model_name='item',
name='parent',
field=models.IntegerField(null=True),
),
]
......@@ -8,7 +8,7 @@ class Item(models.Model):
file_type = models.CharField(max_length=100, null=True) # signed_url 생성을 위해 file type 세팅
path = models.TextField()
#parent = models.ForeignKey('Item', on_delete=models.CASCADE, null=True) #related_name
parent = models.IntegerField()
parent = models.IntegerField(null=True) # root 폴더의 경우 null임
user_id = models.IntegerField()
size = models.IntegerField()
is_deleted = models.BooleanField(default = False)
......@@ -37,6 +37,7 @@ class User(models.Model):
user_id = models.CharField(max_length = 50)
name = models.CharField(max_length = 50)
password = models.CharField(max_length = 20)
root_folder = models.IntegerField(null=True)
total_size = models.IntegerField()
current_size = models.IntegerField()
created_time = models.DateTimeField(auto_now=True)
......
......@@ -13,14 +13,15 @@ from rest_framework.response import Response
from rest_framework.decorators import action
from rest_framework.permissions import IsAuthenticated, AllowAny
from api.models import Item, SharedItem, User
from api.serializers import UserSerializer,GroupSerializer,ItemSerializer
from .models import Item, SharedItem, User
from .serializers import UserSerializer,GroupSerializer,ItemSerializer
from rest_framework import status
from annoying.functions import get_object_or_None
from django.conf import settings
import jwt
from django.http import HttpResponse, JsonResponse
class UserViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows users to be viewed or edited.
......@@ -42,11 +43,15 @@ class UserViewSet(viewsets.ModelViewSet):
if user == None:
user = User(user_id = user_id, name = name, password = password, total_size=100000, current_size = 0)
user.save()
root = Item(is_folder=True, name="root", file_type="folder", path="", user_id=user.int_id, size=0,
status=True)
root.save()
return Response({
'message': 'user created',
'int_id': user.int_id,
'user_id': user.user_id,
'name': user.name,
'root_folder':root.item_id,
'total_size': user.total_size,
'current_size': user.current_size,
'created_time': user.created_time
......