Skip to content

Commit

Permalink
Merge pull request #285 from smu-nity/feature/284
Browse files Browse the repository at this point in the history
Feature/284
  • Loading branch information
hyunmin0317 authored Jan 16, 2024
2 parents b925881 + d5b5696 commit c3a175f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 9 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# SMUNITY ![Python versions](https://img.shields.io/badge/Python-3.9-blue) ![License](https://img.shields.io/badge/license-MIT-green) ![Release](https://img.shields.io/badge/release-1.5.1-red)
# SMUNITY ![Python versions](https://img.shields.io/badge/Python-3.9-blue) ![License](https://img.shields.io/badge/license-MIT-green) ![Release](https://img.shields.io/badge/release-1.5.2-red)

#### 상명대학교 졸업요건 검사 사이트

![SMUNITY](https://github.com/smu-nity/SMUNITY/assets/63601183/f1e9be66-3894-42f7-a3a7-b730e8066a58)
Expand All @@ -12,7 +13,7 @@
* #### Backend
<img src="https://img.shields.io/badge/Python-3.9-3776AB?style=round-square&logo=Python&logoColor=white"/>
<img src="https://img.shields.io/badge/Django-4.1.5-092E20?style=round-square&logo=Django&logoColor=white"/>

* #### Frontend
<img src="https://img.shields.io/badge/HTML-E34F26?style=round-square&logo=HTML5&logoColor=white"/>
<img src="https://img.shields.io/badge/JavaScript-F7DF1E?style=round-square&logo=JavaScript&logoColor=white"/>
Expand Down
6 changes: 6 additions & 0 deletions api/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from rest_framework import serializers


class UserSerializer(serializers.Serializer):
username = serializers.CharField(max_length=100)
password = serializers.CharField(max_length=100)
3 changes: 3 additions & 0 deletions api/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from django.urls import path

from api import views

app_name = 'api'

urlpatterns = [
path('auth', views.authenticate, name='authenticate'),
path('userinfo', views.userinfo, name='userinfo'),
path('courses', views.courses, name='courses'),
]
50 changes: 43 additions & 7 deletions api/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
from rest_framework import status
from rest_framework.response import Response
from rest_framework.decorators import api_view
from sangmyung_univ_auth import auth
from rest_framework.response import Response
from sangmyung_univ_auth import auth, completed_courses

from api.serializers import UserSerializer


@api_view(['POST'])
def authenticate(request):
if 'username' and 'password' in request.data:
username, password = request.data['username'], request.data['password']
return authenticate_user(request)


@api_view(['POST'])
def userinfo(request):
return authenticate_user(request, response_body=False)


@api_view(['POST'])
def courses(request):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
username, password = serializer.validated_data['username'], serializer.validated_data['password']
result = completed_courses(username, password)
status_code = status.HTTP_200_OK if result.is_auth else status.HTTP_401_UNAUTHORIZED
return Response(filter_data(result.body), status=status_code)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


def authenticate_user(request, response_body=True):
serializer = UserSerializer(data=request.data)
if serializer.is_valid():
username, password = serializer.validated_data['username'], serializer.validated_data['password']
result = auth(username, password)
res = status.HTTP_200_OK if result.is_auth else status.HTTP_401_UNAUTHORIZED
return Response(result._asdict(), status=res)
return Response(status=status.HTTP_400_BAD_REQUEST)
status_code = status.HTTP_200_OK if result.is_auth else status.HTTP_401_UNAUTHORIZED
return Response(result._asdict() if response_body else result.body, status=status_code)
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)


def filter_data(original_data):
return list(map(lambda item: {
'number': item['SBJ_NO'],
'name': item['SBJ_NM'],
'credit': item['CDT'],
'type': item['CMP_DIV_NM'],
'grade': item['GRD_NM'],
'year': item['SCH_YEAR'],
'semester': item['SMT_NM'],
'domain': item['CULT_ARA_NM'] if item['CULT_ARA_NM'] != '*' else None
}, original_data))

0 comments on commit c3a175f

Please sign in to comment.