Skip to content

Commit

Permalink
Merge pull request #35 from Funtech-3/refactor/registration
Browse files Browse the repository at this point in the history
Refactor/registration
  • Loading branch information
Denis-Shtanskiy committed Apr 27, 2024
2 parents 47571b8 + 42980eb commit 9de42e6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 62 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/build_and_push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Main Funtech deploy
on:
repository_dispatch:
types: [run-backend-workflow]
push:
branches: [ 'main', 'dev']
paths-ignore:
- "**/README.md"

jobs:
build_backend_and_push_to_docker_hub:
name: Push backend Docker image to DockerHub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
with:
context: ./backend/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend:latest


build_gateway_and_push_to_docker_hub:
name: Push gateway Docker image to DockerHub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
with:
context: ./nginx/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}_gateway:latest


deploy_uses_other_file:
if:
contains('
refs/heads/develop
refs/heads/main
', github.ref)
uses: Funtech-3/backend/.github/workflows/deploy.yml@develop
needs:
- build_backend_and_push_to_docker_hub
- build_gateway_and_push_to_docker_hub
secrets: inherit
56 changes: 4 additions & 52 deletions .github/workflows/main.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,12 @@
name: Main Funtech deploy
on:
repository_dispatch:
types: [run-backend-workflow]
push:
branches: [ 'main', 'dev']
paths-ignore:
- "**/README.md"

jobs:
build_backend_and_push_to_docker_hub:
name: Push backend Docker image to DockerHub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
with:
context: ./backend/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}_backend:latest
name: Funtech deploy


build_gateway_and_push_to_docker_hub:
name: Push gateway Docker image to DockerHub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to Docker
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push to DockerHub
uses: docker/build-push-action@v4
with:
context: ./nginx/
push: true
tags: ${{ secrets.DOCKER_USERNAME }}/${{ secrets.PROJECT_NAME }}_gateway:latest
on:
workflow_call:


jobs:
deploy:
runs-on: ubuntu-latest
needs:
- build_backend_and_push_to_docker_hub
- build_gateway_and_push_to_docker_hub
steps:
- name: Checkout repo
uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

20 changes: 10 additions & 10 deletions backend/api/v1/views_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ def get_serializer_class(self):

@action(
detail=False,
methods=[
"POST",
],
methods=["POST", "DELETE"],
url_path=r"(?P<slug>[\w-]+)/registration",
permission_classes=[
IsAuthenticated,
],
)
def registration(self, request, **kwargs):
"""Зарегистрироваться на событие."""
event = self.get_object()
object, created = Registration.objects.get_or_create(
user=self.request.user, event=event
)
if object:
return Response(status=CREATED)
return Response(status=BAD_REQUEST)
if request.method == "POST":
event = self.get_object()
object, created = Registration.objects.get_or_create(
user=self.request.user, event=event
)
if object:
return Response(status=CREATED)
return Response(status=BAD_REQUEST)
return Response(status=NO_CONTENT)


@receiver([post_save, post_delete], sender=Event)
Expand Down

0 comments on commit 9de42e6

Please sign in to comment.