diff --git a/Dockerfile b/Dockerfile index 258b8b6..619903d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,30 +9,16 @@ RUN apt-get update && apt-get install -y \ # 작업 디렉토리 설정 WORKDIR /app -# requirements.txt 복사 및 종속성 설치 +# requirements.txt 복사 및 패키지 설치 COPY ./requirements.txt /app/requirements.txt - RUN pip install --upgrade pip RUN pip install -r /app/requirements.txt -# .env 파일 복사 -COPY .env /app/.env - -# Docker 빌드 시 환경 변수 받기 -ARG SECRET_KEY -ARG DEBUG -ARG DJANGO_DEPLOY - -# 환경 변수를 컨테이너 내에서 사용할 수 있게 설정 -ENV SECRET_KEY=$SECRET_KEY -ENV DEBUG=$DEBUG -ENV DJANGO_DEPLOY=$DJANGO_DEPLOY - -# 프로젝트 파일 복사 +# 프로젝트 전체 복사 COPY . /app -# collectstatic 명령 실행 +# 정적 파일 수집 RUN python manage.py collectstatic --noinput -# Gunicorn으로 Django 애플리케이션 실행 -CMD ["gunicorn", "linenow.wsgi:application", "--bind", "0.0.0.0:8000"] \ No newline at end of file +# makemigrations, migrate 실행 후 Gunicorn 시작 +CMD ["sh", "-c", "python manage.py makemigrations --noinput && python manage.py migrate --noinput && gunicorn linenow.wsgi:application --bind 0.0.0.0:8000"] \ No newline at end of file diff --git a/booth/views.py b/booth/views.py index 81baf08..aec4dba 100644 --- a/booth/views.py +++ b/booth/views.py @@ -31,19 +31,31 @@ def get_queryset(self): # serializer.save() # return Response(serializer.data, status=status.HTTP_201_CREATED) # return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) - + @action(detail=False, methods=['get'], url_path='count') def get_booth_count(self, request): - booth_count = Booth.objects.count() - return custom_response({'booth_count': booth_count}, message='Booth count fetched successfully') + try: + booth_count = Booth.objects.count() + return custom_response({'booth_count': booth_count}, message='Booth count fetched successfully') + except Exception as e: + return custom_response(data=None, message=str(e), code=status.HTTP_500_INTERNAL_SERVER_ERROR, success=False) # 에러 띄우기 위한 함수 @action(detail=False, methods=['get'], url_path='error') def error(self, request): - raise ResourceNotFound() + raise ResourceNotFound('This booth does not exist.') # 에러 띄우기 위한 함수 mk2 @action(detail=False, methods=['get'], url_path='error2') def error2(self, request): - raise CustomException() return custom_response(data=None, message='This should not be reached', code=200, success=True) + + # 부스별 대기 팀 수 조회 API + @action(detail=False, methods=['get'], url_path='waiting-count') + def booth_waiting_count(self, request): + booths = Booth.objects.annotate(waiting_count=Count('waitings')) + data = [ + {"booth_name": booth.name, "waiting_count": booth.waiting_count} + for booth in booths + ] + return custom_response(data=data, message="Booth waiting counts fetched successfully", code=status.HTTP_200_OK) \ No newline at end of file diff --git a/utils/exceptions.py b/utils/exceptions.py index ca07422..d4c5ec0 100644 --- a/utils/exceptions.py +++ b/utils/exceptions.py @@ -36,6 +36,8 @@ def custom_exception_handler(exc, context): if response is not None: message = response.data.get('detail', 'An error occurred.') code = response.status_code - return custom_response(data=None, message=message, code=code, success=False) + error_type = exc.__class__.__name__ # 에러 타입 가져오기 .. + + return custom_response(data=None, message=f'{error_type}: {message}', code=code, success=False) return custom_response(data=None, message='Unhandled server error occurred.', code=500, success=False) \ No newline at end of file diff --git a/utils/responses.py b/utils/responses.py index 03ff053..066c78c 100644 --- a/utils/responses.py +++ b/utils/responses.py @@ -7,7 +7,7 @@ def custom_response(data=None, message='Success', code=status.HTTP_200_OK, succe - data: 실제 응답 데이터 - message: 응답 메시지 - code: HTTP 상태 코드 - - success: 성공 여부 (True면 'success', False면 'error') + - status: 성공 여부 (True면 'success', False면 'error') """ response = { 'status': 'success' if success else 'error',