Skip to content

Commit

Permalink
chore: cleanup + dev environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Mar 10, 2024
1 parent eb00228 commit cd4efb8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 53 deletions.
5 changes: 0 additions & 5 deletions backend/notifications/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,9 @@ def get_message_dict(notification: Notification) -> Dict[str, str]:

# Call the function after 60 seconds and no more than once in that period
def schedule_send_mails():
print("Hiii")
if not cache.get("notifications_send_mails"):
print("Not in cache yet")
cache.set("notifications_send_mails", True)
_send_mails.apply_async(countdown=60)
else:
print("Already in cache")


# Try to send one email and set the result
Expand All @@ -42,7 +38,6 @@ def _send_mail(mail: mail.EmailMessage, result: List[bool]):
# Send all unsent emails
@shared_task
def _send_mails():
print("Sending")
cache.set("notifications_send_mails", False)

notifications = Notification.objects.filter(is_sent=False)
Expand Down
1 change: 0 additions & 1 deletion backend/notifications/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
notification_create = Signal()


# TODO: Remove send_mails call
@receiver(notification_create)
def notification_creation(
type: NotificationType,
Expand Down
4 changes: 1 addition & 3 deletions backend/notifications/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from django.urls import path
from notifications.views import NotificationView, TestingView
from notifications.views import NotificationView

# TODO: Remove test
urlpatterns = [
path("tmp/<str:user_id>/", NotificationView.as_view(), name="notification-detail"),
path("test/", TestingView.as_view(), name="notification-test"),
]
27 changes: 0 additions & 27 deletions backend/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from rest_framework.views import APIView


# TODO: Give admin access to everything
class NotificationPermission(BasePermission):
# The user can only access their own notifications
# An admin can access all notifications
Expand All @@ -36,29 +35,3 @@ def post(self, request: Request, user_id: str) -> Response:
notifications.update(is_read=True)

return Response(status=HTTP_200_OK)


# TODO: Remove this view
class TestingView(APIView):
permission_classes = [IsAuthenticated]

def get(self, request: Request):
from notifications.signals import NotificationType, notification_create

print("Hi")

notification_create.send(
sender="",
type=NotificationType.SCORE_ADDED,
user=request.user,
arguments={"score": "10"},
)

return Response(status=HTTP_200_OK)

def post(self, request: Request):
from notifications.logic import send_mails

send_mails()

return Response(status=HTTP_200_OK)
5 changes: 0 additions & 5 deletions backend/ypovoli/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,3 @@

# Load task modules from all registered Django apps.
app.autodiscover_tasks()


@app.task(bind=True, ignore_result=True)
def debug_task(self):
print(f"Request: {self.request!r}")
4 changes: 2 additions & 2 deletions data/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ http {
}

upstream frontend {
server frontend:3000;
server frontend:5173;
}

server {
Expand All @@ -28,7 +28,7 @@ http {
ssl_certificate_key ssl/private.key;

location / {
proxy_pass https://frontend;
proxy_pass http://frontend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
Expand Down
5 changes: 4 additions & 1 deletion development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ services:
build:
context: $FRONTEND_DIR
dockerfile: Dockerfile
command: bash -c "npm install && npm run host"
expose:
- 3000
- 5173
volumes:
- $FRONTEND_DIR:/app
depends_on:
- backend

Expand Down
28 changes: 19 additions & 9 deletions frontend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
FROM node:16 as build-stage
# FROM node:16 as build-stage
# WORKDIR /app
# COPY package*.json ./
# RUN npm install
# COPY ./ .
# RUN npm run build

# FROM nginx as development-stage
# EXPOSE 3000
# RUN mkdir /app
# COPY nginx.conf /etc/nginx/conf.d/default.conf
# COPY --from=build-stage /app/dist /app

FROM node:16

WORKDIR /app

COPY package*.json ./

RUN npm install
COPY ./ .
RUN npm run build

FROM nginx as development-stage
EXPOSE 3000
RUN mkdir /app
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY --from=build-stage /app/dist /app

COPY . /app/
1 change: 1 addition & 0 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"type": "module",
"scripts": {
"dev": "vite",
"host": "vite --host",
"build": "vue-tsc && vite build",
"preview": "vite preview"
},
Expand Down

0 comments on commit cd4efb8

Please sign in to comment.