Skip to content

Commit

Permalink
Merge pull request #119 from swsnu/release/1.2
Browse files Browse the repository at this point in the history
Release/1.2
  • Loading branch information
seuha516 authored Dec 9, 2022
2 parents 6cda311 + 8ffa447 commit 388ec47
Show file tree
Hide file tree
Showing 180 changed files with 12,098 additions and 3,904 deletions.
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ jobs:
token:
secure: IfAl2D9LGXfw1SXL+eQttQ9l+QQAY2xf7exxXLupJB9tPh8hNht2v+nYt+DThbkrBx89huEK842GQuR+cSTqWkbpU1GB66rkfO4Y7kvqnlCYpfYYxdv8U0kFB04O1Tz09DzDeU4St9YhY3BtoHvNuZkAA8AruVaP5iIkoKWNL7AZ1+UW69CVA1Bzf2K8SpG33/aDF1sZhf7GkPXuB86b0ppJPG7yen+/75Ab2MO0YAIAfCpQidMHkpycZMEPBm2kC2yuzyFPnfLmpM2aONWDtTmvwQbGhK+lk9vJxtKd/WczyIB4ddOHKFyoHVJw/qA4ZWrghBtfgMTlzQHQVt0IrTHm5huL/fjAmnINhXj3luXzso32WaxPQ7bIy2bj2o1YC67SfcVwILEH0LN0bJv/gSga4SAJE22G1VsIloUepCYlJit+l5A/uBnwT3EroUvncsQ0G9T5Mesa0OMs5ta7rMOiNyuinHAPZP3q1VK68gasDTPsiAK3jwujl31yvETFQg0qBpzjhQ8TrE7l15HISeArwxwSJpvwq1mWhMwQ9OG+hDpd4w3tngvYAmil6E2Xo4L3Kz5YLsSgX76maP7MRvOxV999clhFQZgmE2WWouNxx6Raqk5AGije0zWLPfj9Bc+tsmARLFlMAC9OxRPtYLiWA9iNBRmyx4zfpKTM5F4=
before_install:
- openssl aes-256-cbc -K $encrypted_373aa1f98b09_key -iv $encrypted_373aa1f98b09_iv -in frontend/env.tar.enc -out frontend/env.tar -d
- tar xvf frontend/env.tar -C frontend/
- openssl aes-256-cbc -K $encrypted_ad561db20640_key -iv $encrypted_ad561db20640_iv -in backend/env.tar.enc -out backend/env.tar -d
- tar xvf backend/env.tar -C backend/
- mv frontend/example.env frontend/.env
- nvm install 16
- node --version && npm --version && nvm --version && python -V
install:
Expand Down
32 changes: 19 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
# FITogether
[![Build Status](https://app.travis-ci.com/swsnu/swppfall2022-team4.svg?branch=main)](https://app.travis-ci.com/swsnu/swppfall2022-team4)
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=swsnu_swppfall2022-team4&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=swsnu_swppfall2022-team4)
[![Coverage Status](https://coveralls.io/repos/github/swsnu/swppfall2022-team4/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/swsnu/swppfall2022-team4?branch=main)
[![Coverage Status](https://coveralls.io/repos/github/swsnu/swppfall2022-team4/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/swsnu/swppfall2022-team4?branch=main)

https://fitogether.site/

## Locally Install
_**Note**: We implemented the Kakao social login feature, but this feature only works with local environment (localost:3000) due to the redirect URL problem. Also, it may not work with local environment in the future because HTTPS deployment will be done in the Sprint 5._
### Run frontend server
# node.js : v16.18.1
# Rename frontend/example.env to frontend/.env

cd frontend
yarn install
yarn start
### Test frontend
yarn test --coverage --watchAll=false
### Run backend server
# python : v3.9.5
# Rename backend/example.env to backend/.env
# redis-server should be running in the background to chat.

cd backend
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver 0.0.0.0:8000
### Websocket setting
# redis-server should be running in the background.

cd backend
daphne -b 0.0.0.0 -p 8001 FITogether.asgi:application

## Testing
### Test frontend
cd frontend
yarn test --coverage --watchAll=false
### Test backend
cd backend
coverage run --source='.' manage.py test
coverage report
------------------
## Docker
### Nginx (front + back)
docker-compose up
# If you want to rebuild, please type docker-compose up --build
- After docker-compose, type just ```http://localhost/``` in any browser
- You can access an account that already has chat dummy data created. Username is "testuser" and password is "password".
- Happy with _FITogether_!
## Create Dummy Data
cd backend
python manage.py seed_users -n 10
...
You can find commands to add dummy data at [here](https://github.com/swsnu/swppfall2022-team4/wiki).
2 changes: 1 addition & 1 deletion backend/.pylintrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[MASTER]
disable=C0114, C0115, C0116, C0301, C0411, W0105, W0221, W0201, W0611, W0703, R0903, R0911, R0914, R0915, R1705, R1710, E5110, E1101, R0801, R0912
disable=C0103, C0114, C0115, C0116, C0301, C0411, C0412, W0105, W0221, W0201, W0611, W0703, R0903, R0911, R0914, R0915, R1705, R1710, E5110, E1101, R0801, R0912
ignore-paths=.*/migrations/*, manage.py, .*/management/commands/*
28 changes: 0 additions & 28 deletions backend/Dockerfile

This file was deleted.

12 changes: 12 additions & 0 deletions backend/Dockerfile.deployment
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM python:3.9.5

VOLUME /app
WORKDIR /app

COPY . .

# ENV is not uploaded on Github.

RUN pip install -r requirements.txt
RUN pip install uwsgi
RUN pip install mysql-connector-python==8.0.26
32 changes: 6 additions & 26 deletions backend/FITogether/asgi.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,9 @@
"""
ASGI config for FITogether project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.1/howto/deployment/asgi/
"""

import os
import chats.routing
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
import django
from channels.routing import get_default_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'FITogether.settings')

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
# Initialize Django ASGI application early to ensure the AppRegistry
# is populated before importing code that may import ORM models.
django_asgi_app = get_asgi_application()
django.setup()

application = ProtocolTypeRouter(
{
"http": django_asgi_app,
"websocket": AllowedHostsOriginValidator(
AuthMiddlewareStack(URLRouter(chats.routing.websocket_urlpatterns))
),
}
)
application = get_default_application()
11 changes: 11 additions & 0 deletions backend/FITogether/routing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter, URLRouter
import chats.routing

application = ProtocolTypeRouter({
'websocket': AuthMiddlewareStack(
URLRouter(
chats.routing.websocket_urlpatterns
)
),
})
60 changes: 47 additions & 13 deletions backend/FITogether/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get("SECRET_KEY")
secret_key_default = 'secret_key_for_development_secret_key_for_development_secret_key_for_development_secret_key_for_development_secret_key_for_development'
SECRET_KEY = os.environ.get('SECRET_KEY', secret_key_default)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = os.environ.get('DEBUG', 'True') == 'True'

ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'backend']
ALLOWED_HOSTS = ['localhost', '127.0.0.1', 'ec2-3-37-226-67.ap-northeast-2.compute.amazonaws.com', '3.37.226.67', 'fitogether.site']

SECURE_HSTS_SECONDS = int(os.environ.get('SECURE_HSTS_SECONDS', 31536000))
SECURE_SSL_REDIRECT = os.environ.get('SECURE_SSL_REDIRECT', 'False') == 'True'
SESSION_COOKIE_SECURE = os.environ.get('SESSION_COOKIE_SECURE', 'False') == 'True'
CSRF_COOKIE_SECURE = os.environ.get('CSRF_COOKIE_SECURE', 'False') == 'True'
SECURE_HSTS_INCLUDE_SUBDOMAINS = os.environ.get('SECURE_HSTS_INCLUDE_SUBDOMAINS', 'False') == 'True'
SECURE_HSTS_PRELOAD = os.environ.get('SECURE_HSTS_PRELOAD', 'False') == 'True'


# Application definition

INSTALLED_APPS = [
'daphne',
'channels',
'chats',
'chatrooms',
'notifications',
Expand All @@ -53,16 +61,15 @@
'django.contrib.staticfiles',
]

REDIS_HOST = os.environ.get("REDIS_HOST")
ASGI_APPLICATION = 'FITogether.asgi.application'
ASGI_APPLICATION = 'FITogether.routing.application'

CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels_redis.core.RedisChannelLayer',
'CONFIG': {
"hosts": [(REDIS_HOST, 6379)],
"capacity": 1500,
"expiry": 300,
'hosts': [('127.0.0.1', 6379)],
'capacity': 1500,
'expiry': 300,
},
},
}
Expand Down Expand Up @@ -106,7 +113,19 @@
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3'
}
} if os.environ.get('APP_MODE', 'development') == 'development' else {
'default': {
'ENGINE': 'mysql.connector.django',
'NAME': 'fitogether_db',
'USER': 'fitogether_user',
'PASSWORD': os.environ.get('DB_PASSWORD'),
'HOST': 'mysql',
'PORT': '3306',
'OPTIONS': {
'auth_plugin': 'mysql_native_password'
}
}
}

Expand Down Expand Up @@ -152,11 +171,26 @@

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
CSRF_TRUSTED_ORIGINS = ["http://localhost:8000/", "http://localhost", "http://127.0.0.1:8000/"]
CORS_ALLOWED_ORIGINS = ["http://localhost:3000", "http://127.0.0.1:3000", "http://localhost"]
CSRF_TRUSTED_ORIGINS = [
'http://localhost:3000',
'http://127.0.0.1:3000',
'http://localhost',
'http://ec2-3-37-226-67.ap-northeast-2.compute.amazonaws.com:3000',
'http://3.37.226.67:3000',
'https://fitogether.site'
]
CORS_ALLOWED_ORIGINS = [
'http://localhost:3000',
'http://127.0.0.1:3000',
'http://localhost',
'http://ec2-3-37-226-67.ap-northeast-2.compute.amazonaws.com:3000',
'http://3.37.226.67:3000',
'https://fitogether.site'
]

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = 'true'
os.environ['DJANGO_ALLOW_ASYNC_UNSAFE'] = 'true'
5 changes: 4 additions & 1 deletion backend/FITogether/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.views.static import serve
from django.urls import re_path

urlpatterns = [
path('admin/', admin.site.urls),
Expand All @@ -30,4 +32,5 @@
path('api/fitelement/', include('workouts.urls')),
path('api/group/', include('groups.urls')),
path('api/notification/', include('notifications.urls')),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
re_path(r'^media/(?P<path>.*)$', serve, {'document_root':settings.MEDIA_ROOT}),
]
4 changes: 2 additions & 2 deletions backend/chatrooms/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.3 on 2022-11-24 12:00
# Generated by Django 4.1.3 on 2022-12-06 21:20

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -9,8 +9,8 @@ class Migration(migrations.Migration):
initial = True

dependencies = [
('users', '0001_initial'),
('groups', '0001_initial'),
('users', '0001_initial'),
]

operations = [
Expand Down
4 changes: 4 additions & 0 deletions backend/chats/consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ async def receive(self, text_data):
# info : 대상 username
target.append(data["info"])

elif data["category"] == "group":
# info : 대상 username
target.append(data["info"])

else:
pass

Expand Down
3 changes: 1 addition & 2 deletions backend/comments/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.1.3 on 2022-11-24 12:00
# Generated by Django 4.1.3 on 2022-12-06 21:20

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -26,7 +26,6 @@ class Migration(migrations.Migration):
('liker', models.ManyToManyField(blank=True, related_name='liked_comments', to='users.user')),
('parent_comment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='comments.comment')),
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='posts.post')),
('scraper', models.ManyToManyField(blank=True, related_name='scraped_comments', to='users.user')),
],
options={
'abstract': False,
Expand Down
9 changes: 2 additions & 7 deletions backend/comments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,11 @@ class Comment(AbstractTimeStampedModel):
content = models.TextField()

liker = models.ManyToManyField(User, related_name="liked_comments", blank=True)
disliker = models.ManyToManyField(
User, related_name="disliked_comments", blank=True
)
scraper = models.ManyToManyField(User, related_name="scraped_comments", blank=True)
disliker = models.ManyToManyField(User, related_name="disliked_comments", blank=True)

# Related_name : comments <- comments.Comment

parent_comment = models.ForeignKey(
"self", on_delete=models.CASCADE, blank=True, null=True
)
parent_comment = models.ForeignKey("self", on_delete=models.CASCADE, blank=True, null=True)

def get_like_num(self):
"""Get number of like"""
Expand Down
3 changes: 2 additions & 1 deletion backend/comments/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def prepare_comment_response(comment, is_detail=False, username=''):
if is_detail:
response["liked"] = comment.liker.all().filter(username=username).exists()
response["disliked"] = comment.disliker.all().filter(username=username).exists()
response["post_title"] = comment.post.title
return response


Expand Down Expand Up @@ -74,7 +75,7 @@ def comment_home(request):
author=author, post=post, content=content, parent_comment=parent_comment
)

add_exp(request.user.username, 15)
add_exp(request.user.username, 5)

return JsonResponse({"message": "Success!"}, status=201)
except (
Expand Down
Binary file removed backend/env.tar.enc
Binary file not shown.
5 changes: 0 additions & 5 deletions backend/example.env

This file was deleted.

9 changes: 7 additions & 2 deletions backend/groups/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from django.contrib import admin
from .models import Group
from groups.models import Group

admin.site.register(Group)

@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
"""Group admin definition"""

list_display = ("pk", "group_name", "group_leader", "address")
Empty file.
Empty file.
Loading

0 comments on commit 388ec47

Please sign in to comment.