Skip to content

Commit

Permalink
Merge branch 'test'
Browse files Browse the repository at this point in the history
  • Loading branch information
k1g99 committed Feb 6, 2024
2 parents b040fff + 2aa6b26 commit 59a9c10
Show file tree
Hide file tree
Showing 69 changed files with 1,802 additions and 776 deletions.
58 changes: 29 additions & 29 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
name: Docker Image CI
# name: Docker Image CI

on:
push:
branches: [main]
pull_request:
branches: [main]
# on:
# push:
# branches: [main]
# pull_request:
# branches: [main]

jobs:
build-image:
runs-on: ubuntu-latest
# jobs:
# build-image:
# runs-on: ubuntu-latest

steps:
- name: Checkout to repository
uses: actions/checkout@v2
# steps:
# - name: Checkout to repository
# uses: actions/checkout@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v2

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: k1g99
password: ${{ secrets.CR_PAT }}
# - name: Login to GitHub Container Registry
# uses: docker/login-action@v2
# with:
# registry: ghcr.io
# username: k1g99
# password: ${{ secrets.CR_PAT }}

- name: Build and push container image
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: true
tags: ghcr.io/fgfnet/fnet:latest
cache-from: type=gha
cache-to: type=gha,mode=max
# - name: Build and push container image
# uses: docker/build-push-action@v4
# with:
# context: .
# file: ./Dockerfile
# push: true
# tags: ghcr.io/fgfnet/fnet:latest
# cache-from: type=gha
# cache-to: type=gha,mode=max
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,5 @@ media
*.py[cod]
*$py.class

.DS_Store
.DS_Store
.env
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ RUN apk add --update --no-cache build-base nginx curl supervisor mysql-client ma
pip install --no-cache-dir -r /app/deploy/requirements.txt && \
apk del build-base --purge

COPY --from=builder /build/ /app/dist
COPY --from=builder /build/build/ /app/dist

ENTRYPOINT ["sh", "/app/deploy/entrypoint.sh" ]
2 changes: 1 addition & 1 deletion backend/deploy/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ http {
access_log /data/log/nginx_access.log main;

server {
listen 8000 default_server;
listen 80 default_server;
server_name _;

location /public {
Expand Down
7 changes: 4 additions & 3 deletions backend/fg/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
# Create your models here.
class UserManager(BaseUserManager):
user_in_migrations = True
def create_user(self, name, student_id):
def create_user(self, name, student_id, campus):
try:
fg = self.model(
name = name, student_id = student_id
name = name, student_id = student_id, campus= campus
)
fg.set_password(student_id)
fg.save(using=self._db)
Expand All @@ -20,7 +20,8 @@ def create_superuser(self, name, password, student_id="root"):
try:
fg = self.create_user(
name=name,
student_id = password if password else student_id
student_id = password if password else student_id,
campus = "n"
)
fg.set_password(password)
fg.role = 'Admin'
Expand Down
7 changes: 5 additions & 2 deletions backend/fg/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class FGSerializer(serializers.ModelSerializer):
class Meta:
model = FG
fields = ['id', 'name', 'student_id', 'campus', 'role']
fields = ['id', 'name', 'role', 'student_id', 'campus']

class CreateFGSerializer(serializers.Serializer):
name = serializers.CharField()
Expand All @@ -15,4 +15,7 @@ class CreateFGSerializer(serializers.Serializer):

class LoginSerializer(serializers.Serializer):
name = serializers.CharField()
password = serializers.CharField()
password = serializers.CharField()

class FGFileUploadSerializer(serializers.Serializer):
file = serializers.FileField()
3 changes: 2 additions & 1 deletion backend/fg/urls/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.urls import path

from ..views.admin import FGAPI
from ..views.admin import FGAPI, FGUploadAPI

urlpatterns = [
path('fg/', FGAPI.as_view(), name="fg_admin_api"),
path('fg/upload/', FGUploadAPI.as_view(), name="fg_upload_api")
]
63 changes: 54 additions & 9 deletions backend/fg/views/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from ..models import FG
from ..serializers import (FGSerializer, CreateFGSerializer)
from ..serializers import (FGSerializer, CreateFGSerializer, FGFileUploadSerializer)
from lc.serializers import LCSerializer
from lc.models import LC

from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.decorators import api_view
from openpyxl import load_workbook
from django.db import transaction, IntegrityError
from rest_framework.exceptions import ParseError
from django.contrib.auth.hashers import make_password

class FGAPI(APIView):
def get(self, request):
if request.user.role != ADMIN:
if request.user.role != 'Admin':
return Response({"error": True, "data": "Admin role required"})
fg_id = request.GET.get("id")
error = False
Expand Down Expand Up @@ -43,17 +50,55 @@ def post(self, request):
student_id=data["student_id"]
)
else:
fg = FG.objects.create_user(name=data["name"],
fg = FG.objects.create(name=data["name"],
student_id=data["student_id"],
campus=data["campus"]
)

# try:
# with transaction.atomic():
# Freshman.objects.bulk_create()
# except IntegrityError as e:
# return self.Response({"data": str(e).split("\n")[1]})

data = FGSerializer(fg).data

return Response({"error": False, "data": data})

class FGUploadAPI(APIView):
def post(self, request):
if request.user.role != "Admin":
return Response({"error": True, "data": "Admin role required"})

serializer = FGFileUploadSerializer(data = request.data)
serializer.is_valid(raise_exception=True)
file = serializer.validated_data['file']

rows = load_workbook(file).active.rows
data_list = [[cell.value for cell in row] for row in rows]
# remove header
data_list.pop(0)

# lc (LCXX), 자과fg, 자과 fg 학번, 자과 fg role, 사과fg, 사과 fg 학번, 사과 fg role, 날짜
lc_list = []

# 기존 data 모두 삭제
LC.objects.all().delete()
FG.objects.exclude(id=1).delete()

for data in data_list:
if FG.objects.filter(student_id = data[2]).exists():
fg_n = FG.objects.get(student_id = data[2])
else:
fg_n = FG.objects.create(name=data[1],
student_id=data[2],
campus="n",
password=make_password(str(data[2])))

if FG.objects.filter(student_id = data[5]).exists():
fg_s = FG.objects.get(student_id = data[5])
else:
fg_s = FG.objects.create(name=data[4],
student_id=data[5],
campus="s",
password=make_password(str(data[5])))

lc_list.append(LC.objects.create(name=data[0], fg_n_id=fg_n,
fg_s_id=fg_s, total=0, schedule=data[7]))

lc_success_data = LCSerializer(lc_list, many=True).data
return Response({"error":False, "data": lc_success_data})
4 changes: 3 additions & 1 deletion backend/fnet/dev_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
'USER': 'fnet',
'PASSWORD': 'fnet',
'HOST': '127.0.0.1',
'PORT': 3306,
'PORT': 1398,
}
}

DEBUG = True

SECRET_KEY = 'django-insecure-8l87s(fcz$l*hni4bs-9)rpdhzrab3=sc(fgz=b5ecau&1k0j9'

ALLOWED_HOSTS = ["*"]

DATA_DIR = f"{BASE_DIR}/data/django"
2 changes: 2 additions & 0 deletions backend/fnet/production_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

DEBUG = False

SECRET_KEY = get_env("DJANGO_SECRET_KEY")

ALLOWED_HOSTS = ["*"]

DATA_DIR = "/data"
10 changes: 6 additions & 4 deletions backend/fnet/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-8l87s(fcz$l*hni4bs-9)rpdhzrab3=sc(fgz=b5ecau&1k0j9'
# SECRET_KEY = 'django-insecure-8l87s(fcz$l*hni4bs-9)rpdhzrab3=sc(fgz=b5ecau&1k0j9'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -38,8 +38,8 @@
CORS_ALLOW_CREDENTIALS = True
CSRF_TRUSTED_ORIGINS = ["127.0.0.1:8000", "localhost:8000"]
CORS_ORIGIN_WHITELIST = (
'http://localhost:3000',
'http://127.0.0.1:8000',
'https://localhost:8000',
'https://127.0.0.1:8000',
)
CORS_ALLOW_HEADERS = (
'access-control-allow-credentials',
Expand Down Expand Up @@ -119,6 +119,8 @@
),
'DEFAULT_PARSER_CLASSES': (
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser'
),
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
Expand Down Expand Up @@ -150,7 +152,7 @@

LANGUAGE_CODE = 'en-us'

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

USE_I18N = True

Expand Down
11 changes: 5 additions & 6 deletions backend/fnet/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@
path('admin/', admin.site.urls),
path('api/', include('fg.urls.user')),
path('api/admin/', include('fg.urls.admin')),
# path('api/', include('freshman.urls.user')),
# path('api/admin/', include('freshman.urls.admin')),
# path('api/', include('lc.urls.user')),
# path('api/admin/', include('lc.urls.admin')),
path('api/', include('lc.urls.user')),
path('api/admin/', include('lc.urls.admin')),
path('api/', include('freshman.urls.user')),
path('api/admin/', include('freshman.urls.admin')),
path('api/', include('notice.urls.user')),
path('api/admin/', include('notice.urls.admin')),
# path('api/', include('todo.urls.user')),
# path('api/admin/', include('todo.urls.admin')),
path('api/', include('todo.urls.user')),
]
3 changes: 2 additions & 1 deletion backend/freshman/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib import admin

from .models import Freshman
# Register your models here.
admin.site.register(Freshman)
27 changes: 27 additions & 0 deletions backend/freshman/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.10 on 2023-02-15 19:04

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


class Migration(migrations.Migration):

initial = True

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

operations = [
migrations.CreateModel(
name='Freshman',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=30)),
('phone_number', models.CharField(max_length=13, null=True)),
('register', models.BooleanField(default=False)),
('department', models.CharField(choices=[('NC', '자연과학계열'), ('EN', '공학계열'), ('SS', '사회과학계열'), ('HS', '인문과학계열')], max_length=10)),
('lc', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='lc.lc')),
],
),
]
25 changes: 25 additions & 0 deletions backend/freshman/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
from django.db import models
from django.db.models.deletion import CASCADE
from django.db.models.fields import CharField, BooleanField
from django.db.models.fields.related import ForeignKey
from lc.models import LC

# Create your models here.
class Freshman(models.Model):
NATURAL_SCIENCE = 'NC'
ENGINEERING = 'EN'
SOCIAL_SCIENCE = 'SS'
HUMANITIES_SCIENCE = 'HS'

DEPARTMENT_CHOICES = [
(NATURAL_SCIENCE, '자연과학계열'),
(ENGINEERING, '공학계열'),
(SOCIAL_SCIENCE, '사회과학계열'),
(HUMANITIES_SCIENCE, '인문과학계열'),
]

lc = ForeignKey(LC, on_delete=CASCADE, null=True)
name = CharField(max_length=30)
phone_number = CharField(max_length=13, null=True)
register = BooleanField(default=False)
department = CharField(max_length=10, choices=DEPARTMENT_CHOICES) # n(자연과학),e(공학),s(사회과학),h(인문과학)

def __str__(self):
return self.name
Loading

0 comments on commit 59a9c10

Please sign in to comment.