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

๐Ÿฉน Fix: ๋ถ€์Šค ์‘๋‹ต ๊ตฌ์กฐ ๋ณ€๊ฒฝ #17

Merged
merged 4 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 5 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
# 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"]
22 changes: 17 additions & 5 deletions booth/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion utils/exceptions.py
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋” ์ข‹์€ ์ฝ”๋“œ์ธ ๊ฒƒ ๊ฐ™์€๋ฐ ๊ดœํžˆ message๋ž‘ ์ฝ”๋“œ๋ž‘ ๊ฒน์น˜๋Š” ๊ฒƒ๋„ ๊ฐ™๊ธฐ๋„,, ๊ทผ๋ฐ์ „ ์กฐ์•„์š” ์ค‘์š”ํ•œ๊ฑด ๋‘๋ฒˆ์„ธ๋ฒˆ ํ™•์ธ ๊ตณ

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜คํ˜ธ .. ์ผ๋‹จ ์˜คํ‚ค์šฅ ใ…Žใ…Ž

Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 1 addition & 1 deletion utils/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading