diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 068d4e8..c5cee7b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -9,28 +9,8 @@ on: env: DOCKER_USER: ${{ secrets.DOCKER_USER }} DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} - + jobs: - - # test: - # name: Jest Tests - # runs-on: ubuntu-latest - - # steps: - # - name: Checkout code - # uses: actions/checkout@v3 - - # - name: Set up NodeJS - # uses: actions/setup-node@v1 - # with: - # node-version: 20 - - # - name: Install all dependencies - # run: npm install - - # - name: Run Tests - # run: npm test - build: runs-on: ubuntu-latest @@ -40,6 +20,14 @@ jobs: with: fetch-depth: 0 + - name: Git Semantic Version + uses: PaulHatch/semantic-version@v5.4.0 + with: + major_pattern: "major:" + minor_pattern: "feat:" + version_format: "${major}.${minor}.${patch}-prerelease${increment}" + id: version + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 @@ -49,6 +37,16 @@ jobs: username: ${{ env.DOCKER_USER }} password: ${{ env.DOCKER_PASSWORD }} + - name: Build and push Docker Image + uses: docker/build-push-action@v2 + env: + NEW_VERSION: ${{ steps.version.outputs.version }} + with: + context: ./ + push: true + dockerfile: ./Dockerfile + tags: jaderodev/aup-backend:${{ env.NEW_VERSION }} + - name: Build and push Docker Image uses: docker/build-push-action@v2 with: @@ -77,15 +75,15 @@ jobs: - name: Move to project folder run: | - ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.82.157.13 'cd backend/ && sudo docker compose down' + ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && sudo docker compose down' - name: Remove old image run: | - ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.82.157.13 'sudo docker image rm -f backend-aup-backend:latest' + ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'sudo docker image rm -f backend-aup-backend:latest' - name: Run new containers run: | - ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.82.157.13 'cd backend/ && git pull && sudo docker compose up -d' + ssh -o StrictHostKeyChecking=no -i key.pem ubuntu@3.228.164.55 'cd backend/ && git pull && sudo docker compose up -d' diff --git a/docker-compose.yml b/docker-compose.yml index bd45323..fcd1f01 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -73,6 +73,11 @@ services: RABBITMQ_USER: ${RABBITMQ_USER} RABBITMQ_PASS: ${RABBITMQ_PASS} RABBITMQ_URL: ${RABBITMQ_URL} + AWS_ACCESS_KEY_ID: ${AWS_ACCESS_KEY_ID} + AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY} + AWS_REGION: ${AWS_REGION} + AWS_BUCKET: ${AWS_BUCKET} + AWS_BUCKET_URL: ${AWS_BUCKET_URL} proxy: build: ./nginx diff --git a/prisma/migrations/20240215174349_numfavs_count_in_animal/migration.sql b/prisma/migrations/20240215174349_numfavs_count_in_animal/migration.sql new file mode 100644 index 0000000..05a49d5 --- /dev/null +++ b/prisma/migrations/20240215174349_numfavs_count_in_animal/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "Animal" ADD COLUMN "numFavs" INTEGER NOT NULL DEFAULT 0; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index b425c29..00547c9 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -105,6 +105,7 @@ model Animal { numFavs Int @default(0) images String[] easyTrain Boolean + numFavs Int @default(0) energyLevel energy moltingAmount molting status status_pet @default(awaiting_home) diff --git a/src/presentation/animals/routes.ts b/src/presentation/animals/routes.ts index 15e5e44..98c5c35 100644 --- a/src/presentation/animals/routes.ts +++ b/src/presentation/animals/routes.ts @@ -90,6 +90,12 @@ export class AnimalRoutes { animalController.delete ); + router.post( + '/:id/add-favorite', + authMiddleware.authenticateUser, + animalController.addToFavorites + ); + return router; } } diff --git a/src/presentation/services/animal.service.ts b/src/presentation/services/animal.service.ts index dd7bbc1..58c04ad 100644 --- a/src/presentation/services/animal.service.ts +++ b/src/presentation/services/animal.service.ts @@ -234,14 +234,12 @@ export class AnimalService { const updateQuery = this.buildQuery(updateAnimalDto); - console.log({ updateQuery }); - const updatedAnimal = await prisma.animal.update({ where: { id: animal.id }, data: updateQuery, }); - return 'Update Animal'; + return updatedAnimal; } public async delete(user: PayloadUser, term: string) { @@ -302,6 +300,7 @@ export class AnimalService { } public async addFavorite(userId: string, animalId: string) { + const animal = await prisma.animal.findUnique({ where: { id: animalId } }); if (!animal) throw new NotFoundError('Animal not found');