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

[17기_서혜준] HTTPS 과제 제출합니다 #56

Open
wants to merge 45 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
79b2c66
connect mysql and add models
shj718 Apr 1, 2023
7985c89
add other models
shj718 Apr 1, 2023
53f7c67
edit __str__() methods, edit related_names, migrate
shj718 Apr 1, 2023
c5b5bbc
edit model profile, add admin user
shj718 Apr 2, 2023
dbc2f4c
edit field of TakeLecture
shj718 Apr 2, 2023
aa01fb8
add 'through=' for manyToManyField
shj718 Apr 2, 2023
605dbf0
Update README.md
shj718 Apr 2, 2023
680165c
Add DRF settings and remove migration files
shj718 Apr 11, 2023
143033d
Refactor packages
shj718 Apr 11, 2023
3401ba7
Add new apps in INSTALLED_APPS
shj718 Apr 11, 2023
8b53001
Add serializers
shj718 Apr 12, 2023
9ecc9d8
Add CBV API in 'community'
shj718 Apr 13, 2023
f592f3b
Refactor to ViewSet
shj718 Apr 13, 2023
930e2fa
Add filter class for Post
shj718 Apr 13, 2023
7d4fba2
Update README.md
shj718 Apr 13, 2023
622a467
[Refact] Add soft-delete, edit custom filtering methods
shj718 May 4, 2023
a1d4eea
[Add] Add simple-jwt settings
shj718 May 5, 2023
e27395e
[Add] Add custom user model, manager
shj718 May 5, 2023
1219594
[Refact] Edit user model, manager
shj718 May 5, 2023
4727078
[Add] Create myUser serializer
shj718 May 5, 2023
ae17fb4
[Feat] Register, login, logout
shj718 May 5, 2023
e414a64
[Refact] Edit community models' user(fk)
shj718 May 6, 2023
af0d80b
[Feat] Refresh access token
shj718 May 6, 2023
eda8c12
[Feat] Set permission
shj718 May 6, 2023
bd7044d
Create README.md
shj718 May 6, 2023
7580799
Update README.md
shj718 May 6, 2023
ba5b1dc
Merge branch 'shj718' of https://github.com/shj718/django_rest_framew…
shj718 May 6, 2023
750c9a0
Update README.md
shj718 May 6, 2023
66b9fcf
[Feat] Deploy through github actions
shj718 May 13, 2023
d1035b0
[Add] Add dummy code for deploy test
shj718 May 13, 2023
73521a4
[Refact] Fix deploy.yml branches:
shj718 May 13, 2023
832c466
[Fix] Edit env_file in docker-compose.prod.yml
shj718 May 13, 2023
02489ef
Update README.md
shj718 May 13, 2023
4195682
[Test] Health check test
shj718 May 20, 2023
9f696d0
[Add] Add prod settings
shj718 May 20, 2023
f9e30c5
[Add] Add nginx redirection settings
shj718 May 20, 2023
1071196
[Fix] Edit nginx redirection settings
shj718 May 20, 2023
d4750d3
[Fix] Edit settings
shj718 May 20, 2023
946d767
[Fix] Edit env...
shj718 May 20, 2023
7e39d56
[Fix] 제발...
shj718 May 20, 2023
e92994c
에러 해결중..
shj718 May 20, 2023
1604374
진짜 미쳤다ㅠㅠ
shj718 May 20, 2023
3ba1f03
[Feat] Show school list
shj718 May 20, 2023
84f3dac
Update README.md
shj718 May 20, 2023
5c2c7af
Update README.md
shj718 May 20, 2023
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
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Deploy to EC2
on:
push:
branches:
- dev
- master

jobs:

Expand All @@ -16,8 +16,8 @@ jobs:

- name: create env file
run: |
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
touch .env.prod
echo "${{ secrets.ENV_VARS }}" >> .env.prod

- name: create remote directory
uses: appleboy/ssh-action@master
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,10 @@ celerybeat.pid
*.sage.py

# Environments
.env
venv/.env
.venv
.env
.env.prod
env/
venv/
ENV/
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt

# Now copy in our code, and run it
COPY . /app/
COPY . /app/
2 changes: 1 addition & 1 deletion Dockerfile.prod
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ WORKDIR $APP_HOME
RUN apk update && apk add libpq
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add --no-cache mariadb-dev
&& apk add --no-cache jpeg-dev zlib-dev mariadb-dev
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install mysqlclient
Expand Down
639 changes: 638 additions & 1 deletion README.md

Large diffs are not rendered by default.

File renamed without changes.
7 changes: 7 additions & 0 deletions account/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

from account.models import *

# admin.site.register(Profile)
admin.site.register(School)
admin.site.register(MyUser)
6 changes: 6 additions & 0 deletions account/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class UserConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'account'
46 changes: 46 additions & 0 deletions account/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 3.2.16 on 2023-04-11 14:56

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


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='School',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.CharField(default='A', max_length=10)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('name', models.CharField(max_length=60)),
('campus', models.CharField(blank=True, max_length=60)),
],
options={
'abstract': False,
},
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('status', models.CharField(default='A', max_length=10)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('profile_img_path', models.URLField(blank=True)),
('friends', models.ManyToManyField(blank=True, related_name='_account_profile_friends_+', to='account.Profile')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]
20 changes: 20 additions & 0 deletions account/migrations/0002_profile_school.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 3.2.16 on 2023-04-11 15:59

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


class Migration(migrations.Migration):

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

operations = [
migrations.AddField(
model_name='profile',
name='school',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='account.school'),
preserve_default=False,
),
]
18 changes: 18 additions & 0 deletions account/migrations/0003_alter_profile_friends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2023-04-13 09:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('account', '0002_profile_school'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='friends',
field=models.ManyToManyField(blank=True, null=True, related_name='_account_profile_friends_+', to='account.Profile'),
),
]
18 changes: 18 additions & 0 deletions account/migrations/0004_alter_profile_friends.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2023-04-13 09:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('account', '0003_alter_profile_friends'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='friends',
field=models.ManyToManyField(blank=True, related_name='_account_profile_friends_+', to='account.Profile'),
),
]
23 changes: 23 additions & 0 deletions account/migrations/0005_auto_20230504_1050.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.16 on 2023-05-04 10:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('account', '0004_alter_profile_friends'),
]

operations = [
migrations.AddField(
model_name='profile',
name='deleted_at',
field=models.DateTimeField(blank=True, null=True),
),
migrations.AddField(
model_name='school',
name='deleted_at',
field=models.DateTimeField(blank=True, null=True),
),
]
34 changes: 34 additions & 0 deletions account/migrations/0006_myuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.2.16 on 2023-05-05 20:42

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


class Migration(migrations.Migration):

dependencies = [
('account', '0005_auto_20230504_1050'),
]

operations = [
migrations.CreateModel(
name='MyUser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('email', models.EmailField(max_length=255, unique=True)),
('nickname', models.CharField(max_length=100, unique=True)),
('profile_img_path', models.URLField(blank=True, null=True)),
('is_admin', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('friends', models.ManyToManyField(blank=True, null=True, related_name='_account_myuser_friends_+', to='account.MyUser')),
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='account.school')),
],
options={
'abstract': False,
},
),
]
24 changes: 24 additions & 0 deletions account/migrations/0007_auto_20230505_2341.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.16 on 2023-05-05 23:41

from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('timetable', '0004_auto_20230505_2341'),
('community', '0004_auto_20230505_2341'),
('account', '0006_myuser'),
]

operations = [
migrations.AlterField(
model_name='myuser',
name='friends',
field=models.ManyToManyField(blank=True, related_name='_account_myuser_friends_+', to=settings.AUTH_USER_MODEL),
),
migrations.DeleteModel(
name='Profile',
),
]
File renamed without changes.
69 changes: 69 additions & 0 deletions account/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from django.db import models
from django.contrib.auth.models import User
from utils.models import BaseModel
from django.contrib.auth.models import BaseUserManager, AbstractBaseUser


class School(BaseModel):
name = models.CharField(max_length=60)
campus = models.CharField(max_length=60, blank=True)

def __str__(self):
return self.name


class MyUserManager(BaseUserManager):
def create_user(self, email, nickname, school=None, password=None, **extra_fields):
if not email:
raise ValueError("Users must have an email address")

user = self.model(
email=email,
nickname=nickname,
school=school,
)
user.set_password(password)
user.save(using=self._db)
return user

def create_superuser(self, email, nickname, school=None, password=None, **extra_fields):
superuser = self.create_user(
email=email,
nickname=nickname,
school=school,
password=password,
)
superuser.is_admin = True
superuser.save(using=self._db)
return superuser


class MyUser(AbstractBaseUser):
email = models.EmailField(max_length=255, unique=True)
nickname = models.CharField(max_length=100, unique=True)
# password, last_login 은 기본 제공
profile_img_path = models.URLField(blank=True, null=True)
friends = models.ManyToManyField('self', blank=True)
school = models.ForeignKey("School", on_delete=models.CASCADE)
is_admin = models.BooleanField(default=False)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

objects = MyUserManager()

USERNAME_FIELD = "email"
REQUIRED_FIELDS = ["nickname"]

def __str__(self):
return self.email


# class Profile(BaseModel):
# user = models.OneToOneField(User, on_delete=models.CASCADE)
# profile_img_path = models.URLField(blank=True)
# friends = models.ManyToManyField('self', blank=True)
# school = models.ForeignKey("School", on_delete=models.CASCADE)
#
# def __str__(self):
# return self.user.username
14 changes: 14 additions & 0 deletions account/permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import permissions


class IsOwnerOrReadonly(permissions.BasePermission):
def has_permission(self, request, view):
# 로그인한 사용자인 경우 API 사용 가능
return request.user and request.user.is_authenticated

def has_object_permission(self, request, view, obj):
# GET, OPTION, HEAD 요청일 때는 그냥 허용
if request.method in permissions.SAFE_METHODS:
return True
# DELETE, PATCH 일 때는 현재 사용자와 객체가 참조 중인 사용자가 일치할 때만 허용
return obj.myUser == request.user
38 changes: 38 additions & 0 deletions account/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from rest_framework import serializers
from account.models import *


class SchoolSerializer(serializers.ModelSerializer):
class Meta:
model = School
fields = '__all__'


class MyUserSerializer(serializers.ModelSerializer):
school = SchoolSerializer

class Meta:
model = MyUser
fields = '__all__'

def create(self, validated_data):
email = validated_data.get('email')
nickname = validated_data.get('nickname')
school = validated_data.get('school')
password = validated_data.get('password')
user = MyUser(
email=email,
nickname=nickname,
school=school
)
user.set_password(password)
user.save()
return user


# class ProfileSerializer(serializers.ModelSerializer):
# school = SchoolSerializer(read_only=True)
#
# class Meta:
# model = Profile
# fields = '__all__'
File renamed without changes.
12 changes: 12 additions & 0 deletions account/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.urls import path, include
from account import views


urlpatterns = [
path("register/", views.RegisterAPIView.as_view()),
path("login/", views.LoginAPIView.as_view()),
path("logout/", views.LogoutAPIView.as_view()),
path("token-refresh/", views.RefreshAccessToken.as_view()),
path("health-check/", views.HealthCheck.as_view()),
path("schools/", views.SchoolListAPIView.as_view()),
]
Loading