Skip to content

Commit

Permalink
Merge pull request #81 from swsnu/dev
Browse files Browse the repository at this point in the history
Sprint 4
  • Loading branch information
cozitive authored Nov 25, 2022
2 parents 91df517 + 43acbf0 commit 828ca25
Show file tree
Hide file tree
Showing 188 changed files with 5,875 additions and 3,021 deletions.
11 changes: 6 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
branches:
only:
- main
- integration
- main
- integration
dist: bionic
jobs:
include:
Expand All @@ -22,15 +22,16 @@ jobs:
- pip install coveralls
script:
- cd ../frontend
- ./node_modules/.bin/eslint src/**/*.{ts,tsx}
- "./node_modules/.bin/eslint src/**/*.{ts,tsx}"
- yarn test --coverage --watchAll=false
- coveralls-lcov -v -n coverage/lcov.info > coverage.json
- cd ../backend
# - pylint **/*.py
- coverage run --source='.' manage.py test
- pylint **/*.py
- coverage run --source='./pitapat' manage.py test
- coverage xml
- coveralls --merge=../frontend/coverage.json
- cd .. && sonar-scanner
- curl -w "\n" -X PURGE https://camo.githubusercontent.com/0283f7d8d154f28339b2facac18092714ebdf99c46067b352f18342dd6aed95a/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f7377736e752f7377707066616c6c323032322d7465616d332f62616467652e7376673f6272616e63683d6d61696e266b696c6c5f63616368653d31
addons:
sonarcloud:
organization: swsnu
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,19 @@ cd frontend
yarn test --coverage --watchAll=false
```

## Backend

### Run

```shell
cd backend
python manage.py runserver
```

### Test

```shell
cd backend
coverage run --source='.' manage.py test
```

4 changes: 2 additions & 2 deletions backend/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[MASTER]
init-hook='import sys; sys.path.append("./")'
ignore-paths=venv/, user/migrations/
ignore-paths=venv/, pitapat/migrations/, manage.py
load-plugins=pylint_django
django-settings-module=backend.settings
disable=import-outside-toplevel, missing-module-docstring, missing-class-docstring, missing-function-docstring, unused-import
disable=missing-module-docstring, missing-class-docstring, missing-function-docstring, too-many-ancestors
18 changes: 16 additions & 2 deletions backend/backend/asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,22 @@

import os

from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
from channels.security.websocket import AllowedHostsOriginValidator
from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
from pitapat.routing import websocket_urlpatterns

application = get_asgi_application()

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
django_asgi_app = get_asgi_application()

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(websocket_urlpatterns))
),
}
)
Binary file modified backend/backend/secrets.tar.enc
Binary file not shown.
117 changes: 109 additions & 8 deletions backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import json
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
import pymysql

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -33,6 +34,7 @@ def get_external_value(filename: str, key: str):
except KeyError as error:
raise ImproperlyConfigured(f'key \'{key}\' does not exist') from error


SECRET_KEY = get_external_value(BASE_DIR / 'backend/.secrets/secret_key.json', 'secret_key')

# SECURITY WARNING: don't run with debug turned on in production!
Expand All @@ -41,20 +43,26 @@ def get_external_value(filename: str, key: str):
ALLOWED_HOSTS = [
'localhost',
'0.0.0.0',
'127.0.0.1',
]


# Application definition

INSTALLED_APPS = [
'user.apps.UserConfig',
'daphne',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'dj_rest_auth',
'drf_yasg',
'storages',
'pitapat',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -86,23 +94,40 @@ def get_external_value(filename: str, key: str):
]

WSGI_APPLICATION = 'backend.wsgi.application'
ASGI_APPLICATION = 'backend.asgi.application'
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
},
},
}


# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

pymysql.install_as_MySQLdb()

db = get_external_value(BASE_DIR / 'backend/.secrets/db.json', 'default')

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'ENGINE': db['ENGINE'],
'HOST': db['HOST'],
'PORT': db['PORT'],
'USER': db['USER'],
'PASSWORD': db['PASSWORD'],
'NAME': db['NAME'],
}
}


# Password validation
# Authentication
# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_USER_MODEL = 'user.User'
AUTH_USER_MODEL = 'pitapat.User'

AUTH_PASSWORD_VALIDATORS = [
{
Expand All @@ -119,13 +144,21 @@ def get_external_value(filename: str, key: str):
},
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.BasicAuthentication',
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.TokenAuthentication',
],
}


# Internationalization
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = 'ko-kr'
LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Asia/Seoul'
TIME_ZONE = 'UTC'

USE_I18N = True

Expand All @@ -140,4 +173,72 @@ def get_external_value(filename: str, key: str):
# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_AUTO_FIELD = 'pitapat.models.custom_field.unsigned_auto_field.UnsignedAutoField'

# AWS S3

IMAGE_URL = get_external_value(
BASE_DIR / 'backend/.secrets/s3.json',
'url',
)

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_S3_SECURE_URLS = False
AWS_QUERYSTRING_AUTH = False

AWS_S3_ACCESS_KEY_ID = get_external_value(
BASE_DIR / 'backend/.secrets/s3.json',
'access_key_id',
)
AWS_S3_SECRET_ACCESS_KEY = get_external_value(
BASE_DIR / 'backend/.secrets/s3.json',
'secret_access_key',
)
AWS_STORAGE_BUCKET_NAME = 'pitapatcampus'

CORS_ORIGIN_WHITELIST = (
'http://localhost:3000', # react port
)
CSRF_TRUSTED_ORIGINS = [
'http://localhost:3000'
]

# Email Verification

EMAIL_BACKEND = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'EMAIL_BACKEND',
)
EMAIL_HOST = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'EMAIL_HOST',
)
EMAIL_PORT = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'EMAIL_PORT',
)
EMAIL_HOST_USER = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'EMAIL_HOST_USER',
)
EMAIL_HOST_PASSWORD = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'EMAIL_HOST_PASSWORD',
)
EMAIL_USE_TLS = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'EMAIL_USE_TLS',
)
DEFAUKT_FROM_EMAIL = get_external_value(
BASE_DIR / 'backend/.secrets/email.json',
'DEFAULT_FROM_EMAIL',
)

CRYPTO_KEY = get_external_value(
BASE_DIR / 'backend/.secrets/aes.json',
'key',
)
CRYPTO_IV = CRYPTO_KEY = get_external_value(
BASE_DIR / 'backend/.secrets/aes.json',
'iv',
)
2 changes: 1 addition & 1 deletion backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@

urlpatterns = [
path('admin/', admin.site.urls),
path('user/', include('user.urls')),
path('', include('pitapat.urls')),
]
File renamed without changes.
18 changes: 18 additions & 0 deletions backend/pitapat/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.contrib import admin

from .models import (Chat, Chatroom, College, Introduction,
Major, Photo, Pitapat, Tag, University,
User, UserChatroom, UserTag)

admin.site.register(University)
admin.site.register(College)
admin.site.register(Major)
admin.site.register(User)
admin.site.register(Introduction)
admin.site.register(Photo)
admin.site.register(Tag)
admin.site.register(Chatroom)
admin.site.register(Chat)
admin.site.register(Pitapat)
admin.site.register(UserTag)
admin.site.register(UserChatroom)
4 changes: 2 additions & 2 deletions backend/user/apps.py → backend/pitapat/apps.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.apps import AppConfig


class UserConfig(AppConfig):
class PitapatConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'user'
name = 'pitapat'
Loading

0 comments on commit 828ca25

Please sign in to comment.