Skip to content

Commit

Permalink
chore : merge fe be
Browse files Browse the repository at this point in the history
  • Loading branch information
bicco2 committed Jul 17, 2022
1 parent 1cffd81 commit a26199a
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 80 deletions.
69 changes: 68 additions & 1 deletion backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env('DEBUG')

ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['*']

# Application definition

Expand All @@ -39,6 +39,7 @@
# local apps
'rebikeuser',
'rebiketrash',
'corsheaders',
]

MIDDLEWARE = [
Expand All @@ -49,8 +50,12 @@
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'corsheaders.middleware.CorsMiddleware',
]

CORS_ORIGIN_WHITELIST = ['http://127.0.0.1:3000', 'http://localhost:3000']
CORS_ALLOW_CREDENTIALS = True

ROOT_URLCONF = 'backend.urls'

TEMPLATES = [
Expand Down Expand Up @@ -116,3 +121,65 @@
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

# ================로깅 테스트===================
# 로깅설정
# LOGGING = {
# 'version': 1,
# 'disable_existing_loggers': False,
# 'filters': {
# 'require_debug_false': {
# '()': 'django.utils.log.RequireDebugFalse',
# },
# 'require_debug_true': {
# '()': 'django.utils.log.RequireDebugTrue',
# },
# },
# 'formatters': {
# 'django.server': {
# '()': 'django.utils.log.ServerFormatter',
# 'format': '[{server_time}] {message}',
# 'style': '{',
# },
# 'standard': {
# 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s'
# },
# },
# 'handlers': {
# 'console': {
# 'level': 'INFO',
# 'filters': ['require_debug_true'],
# 'class': 'logging.StreamHandler',
# },
# 'django.server': {
# 'level': 'INFO',
# 'class': 'logging.StreamHandler',
# 'formatter': 'django.server',
# },
# 'mail_admins': {
# 'level': 'ERROR',
# 'filters': ['require_debug_false'],
# 'class': 'django.utils.log.AdminEmailHandler'
# },
# 'file': {
# 'level': 'INFO',
# 'filters': ['require_debug_false'],
# 'class': 'logging.handlers.RotatingFileHandler',
# 'filename': BASE_DIR / 'logs/mylog.log',
# 'maxBytes': 1024*1024*5, # 5 MB
# 'backupCount': 5,
# 'formatter': 'standard',
# },
# },
# 'loggers': {
# 'django': {
# 'handlers': ['console', 'mail_admins', 'file'],
# 'level': 'INFO',
# },
# 'django.server': {
# 'handlers': ['django.server'],
# 'level': 'INFO',
# 'propagate': False,
# },
# }
# }
13 changes: 11 additions & 2 deletions backend/backend/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@

from django.contrib import admin
from django.urls import path, include
from django.contrib import admin
from django.urls import path, include
from rest_framework.permissions import AllowAny
from django.contrib import admin
from django.urls import path, include
from rest_framework import permissions
from django.urls import include, re_path
from rest_framework.permissions import AllowAny


urlpatterns = [
path('admin/', admin.site.urls),
path('users/', include('rebikeuser.urls')),
path('trashs/', include('rebiketrash.urls')),
path('user/', include('rebikeuser.urls')),
path('trash/', include('rebiketrash.urls')),
]
2 changes: 1 addition & 1 deletion backend/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ COPY ./ ./

EXPOSE 8080

RUN pip install -r requirements.txt
RUN pip install -r requirements.txt
14 changes: 14 additions & 0 deletions backend/rebiketrash/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.contrib import admin

from .models import trash_kind, uploaded_trash_image

@admin.register(trash_kind)
class TrashkindAdmin(admin.ModelAdmin):
list_display = ['kind', 'way']
search_fields = ['kind']

@admin.register(uploaded_trash_image)
class UploadedtrashimageAdmin(admin.ModelAdmin):
list_display = ['uploaded_trash_image_id', 'img', 'created_at', 'updated_at','user_id', 'trash_kind']
search_fields = ['uploaded_trash_image_id']

Empty file.
5 changes: 4 additions & 1 deletion backend/rebiketrash/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
class trash_kind(models.Model):
kind = models.CharField(primary_key=True, max_length=30)
way = models.CharField(max_length=200)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()

class Meta:
managed = False
Expand All @@ -13,6 +15,7 @@ class Meta:

class uploaded_trash_image(models.Model):
uploaded_trash_image_id = models.AutoField(primary_key=True)
active = models.IntegerField(default=1)
img = models.CharField(max_length=200)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()
Expand All @@ -21,4 +24,4 @@ class uploaded_trash_image(models.Model):

class Meta:
managed = False
db_table = 'uploaded_trash_image'
db_table = 'uploaded_trash_image'
13 changes: 13 additions & 0 deletions backend/rebiketrash/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from rest_framework import serializers
from .models import trash_kind, uploaded_trash_image

class TrashkindSerializer(serializers.ModelSerializer) :
class Meta :
model = trash_kind # product 모델 사용
fields = '__all__' # 모든 필드 포함


class UploadedtrashimageSerializer(serializers.ModelSerializer) :
class Meta :
model = uploaded_trash_image # product 모델 사용
fields = '__all__' # 모든 필드 포함
18 changes: 16 additions & 2 deletions backend/rebiketrash/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
from django.urls import path
from django.urls import path, re_path
from . import views

from django.contrib import admin
from django.urls import include, path, re_path

urlpatterns = [


urlpatterns =[
path('mainpage/trashkind/',views.TrashkindListAPI.as_view()),
path('mypage/<user_id>/image/',views.histories, name='histories'),
path('mypage/<user_id>/image/<uploaded_trash_image_id>/',views.UploadedtrashimageListAPI.as_view()),
#path('mypage/<user_id>/statistics/',views.statistics, name='statistics'),
]


### 유저 페이지 진입 시 액티브된 계정인지(있는지 없는지 확인)
### 통계페이지 (액티브 상관 없이 받아오기!)
### 자주 쓰이는 코드 유틸화 trashUtils.py

### swagger, postman 확인 -> 성빈님
42 changes: 41 additions & 1 deletion backend/rebiketrash/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,43 @@
from django.shortcuts import render
from audioop import reverse
from django.shortcuts import render, HttpResponse
from django.db.models import Count

from .models import trash_kind, uploaded_trash_image
from rebikeuser.models import user

from rest_framework import status
from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.decorators import api_view
from .serializers import TrashkindSerializer, UploadedtrashimageSerializer

# Create your views here.
class TrashkindListAPI(APIView):
def get(self, request):
queryset = trash_kind.objects.all()
print(queryset)
serializer = TrashkindSerializer(queryset, many=True)
return Response(serializer.data)

@api_view(['GET'])
def histories(request,user_id):
uploadedTrashs = uploaded_trash_image.objects.filter(user_id=user_id, active=1)
serializer = UploadedtrashimageSerializer(uploadedTrashs, many=True)
return Response(serializer.data)

class UploadedtrashimageListAPI(APIView):
def get(self, request, user_id, uploaded_trash_image_id):
uploadedTrashs = uploaded_trash_image.objects.filter(user_id=user_id, active=1, uploaded_trash_image_id = int(uploaded_trash_image_id))
serializer = UploadedtrashimageSerializer(uploadedTrashs, many=True)
return Response(serializer.data)

def delete(self, request, user_id, uploaded_trash_image_id):
uploadedTrashs = uploaded_trash_image.objects.filter(user_id=user_id, active=1, uploaded_trash_image_id = int(uploaded_trash_image_id))
uploadedTrashs.delete()
return Response(status=status.HTTP_204_NO_CONTENT)

@api_view(['GET'])
def statistics(request,user_id):
uploadedTrashs = uploaded_trash_image.objects.filter(user_id=user_id).values('trash_kind')
serializer = UploadedtrashimageSerializer(uploadedTrashs, many=True)
return Response(serializer.data)
6 changes: 6 additions & 0 deletions backend/rebikeuser/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.contrib import admin
from .models import user

@admin.register(user)
class UserAdmin(admin.ModelAdmin):
list_display = ['id', 'name', 'alias', 'pw', 'salt', 'email']
3 changes: 2 additions & 1 deletion backend/rebikeuser/migrations/0002_alter_user_table.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Generated by Django 4.0.6 on 2022-07-14 19:46

# Generated by Django 4.0.6 on 2022-07-14 18:12

from django.db import migrations

Expand Down
10 changes: 7 additions & 3 deletions backend/rebikeuser/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
from django.db import models
import uuid


class user(models.Model):
id = models.UUIDField(primary_key=True, editable=False)
name = models.CharField(unique=True, max_length=20)
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(unique=True, max_length=20, null=True, blank=True)
alias = models.CharField(unique=True, max_length=20)
pw = models.BinaryField(max_length=60)
salt = models.BinaryField(max_length=29)
email = models.CharField(unique=True, max_length=50)
active = models.IntegerField(default=1)
created_at = models.DateTimeField()
updated_at = models.DateTimeField()

class Meta:
managed = False
db_table = 'user'
#, default=str(uuid.uuid4())

25 changes: 24 additions & 1 deletion backend/rebikeuser/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@


class UserSerializer(serializers.ModelSerializer):
name = serializers.CharField(max_length=20)
alias = serializers.CharField(max_length=20)
email = serializers.CharField(max_length=50)

class Meta:
model = user
fields = ['name', 'alias', 'email'] # Front에 3필드만


# rebikeuser/serializers.py
class UserSignupResponse(serializers.ModelSerializer):
class Meta:
model = user
fields = ['id'] # 프론트에주는 값


class SignupInput(serializers.ModelSerializer):
# 검증부
email = serializers.EmailField()
pw = serializers.CharField(max_length=60)
alias = serializers.CharField(max_length=20)
name = serializers.CharField(max_length=20)

class Meta:
model = user
fields = ['name', 'alias', 'email'] #Front에 3필드만
fields = ['name', 'pw', 'alias', 'email'] # 실제 response할 필드
7 changes: 4 additions & 3 deletions backend/rebikeuser/urls.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.urls import path
from . import views
from .views import UserSignupAPI


#rebikeuser/urls.py
urlpatterns = [
path('login/', views.user_login),
path('signup/', views.user_signup),
path('signup/', views.UserSignupAPI.as_view()),
path('changepw/', views.user_pw_change),
path('changealias/', views.user_alias_change),
]
]
Loading

0 comments on commit a26199a

Please sign in to comment.