Skip to content

Commit

Permalink
Merge pull request #22 from m-strzelec/strzelec
Browse files Browse the repository at this point in the history
Deployment
  • Loading branch information
m-strzelec authored Jun 19, 2024
2 parents 0c8c892 + b3c8065 commit 4d327d6
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 22 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Build and Deploy to Azure Container Apps

on:
push:
branches:
- main

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: 21

- name: Build with Maven
run: mvn clean package

- name: Log in to Azure CLI
uses: azure/login@v1
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Azure Container Registry
run: |
echo ${{ secrets.ACR_NAME }} | az acr login --name ${{ secrets.ACR_NAME }}
- name: Build and push Docker image
run: |
docker build -t ${{ secrets.ACR_NAME }}.azurecr.io/tabi-backend:latest .
docker push ${{ secrets.ACR_NAME }}.azurecr.io/tabi-backend:latest
- name: Create Azure Container App Environment
run: |
az containerapp env create --name tabienv --resource-group zzpjtabi --location polandcentral || echo "Environment already exists"
- name: Deploy to Azure Container Apps
run: |
az containerapp create --name tabiapp --resource-group zzpjtabi --environment tabienv --image ${{ secrets.ACR_NAME }}.azurecr.io/tabi-backend:latest --ingress 'external' --target-port 8080 --env-vars POSTGRES_DB=${{ secrets.POSTGRES_SERVER }} POSTGRES_USER=${{ secrets.POSTGRES_USER }} POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} DB_HOSTNAME=${{ secrets.DB_HOSTNAME }} DB_NAME=${{ secrets.POSTGRES_DATABASE }} APP_PROFILE=prod STRIPE_PUBLIC_KEY=${{ secrets.STRIPE_PUBLIC_KEY }} STRIPE_PRIVATE_KEY=${{ secrets.STRIPE_PRIVATE_KEY }} || az containerapp update --name tabiapp --resource-group zzpjtabi --set-env-vars POSTGRES_DB=${{ secrets.POSTGRES_SERVER }} POSTGRES_USER=${{ secrets.POSTGRES_USER }} POSTGRES_PASSWORD=${{ secrets.POSTGRES_PASSWORD }} DB_HOSTNAME=${{ secrets.DB_HOSTNAME }} DB_NAME=${{ secrets.POSTGRES_DATABASE }} APP_PROFILE=prod STRIPE_PUBLIC_KEY=${{ secrets.STRIPE_PUBLIC_KEY }} STRIPE_PRIVATE_KEY=${{ secrets.STRIPE_PRIVATE_KEY }}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ target/
*.swp
*.un~
*~
payments.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.zzpj.tabi.dto.reservation.ReservationCreateDTO;
import org.zzpj.tabi.dto.reservation.ReservationOutputDTO;
import org.zzpj.tabi.entities.Account;
Expand Down Expand Up @@ -136,7 +133,7 @@ public ResponseEntity<?> getOwnReservations() {
examples = @ExampleObject("500 Internal Server Error"))}
)
})
public ResponseEntity<?> createReservation(@Valid ReservationCreateDTO reservationCreateDTO) {
public ResponseEntity<?> createReservation(@RequestBody ReservationCreateDTO reservationCreateDTO) {
String login = SecurityContextHolder.getContext().getAuthentication().getName();
try {
Account account = accountService.getAccountByLogin(login);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import java.util.UUID;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Positive;
import lombok.Data;

@Data
Expand All @@ -14,7 +12,5 @@ public class ReservationCreateDTO {
private UUID travelId;

@Schema(example = "1")
@NotEmpty
@Positive
private int guestCount;
}
2 changes: 0 additions & 2 deletions src/main/java/org/zzpj/tabi/dto/review/ReviewUpdateDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -22,6 +21,5 @@ public class ReviewUpdateDTO {
private String comment;

@Schema(example = "00000000-0000-0000-0001-000000000001")
@NotEmpty
private UUID travelId;
}
3 changes: 0 additions & 3 deletions src/main/java/org/zzpj/tabi/dto/travel/TravelCreateDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class TravelCreateDTO {
private String place;

@Schema(example = "4999.99")
@Positive
private BigDecimal basePrice;

@Schema(example = "2025-12-15")
Expand All @@ -41,10 +40,8 @@ public class TravelCreateDTO {
private LocalDate endDate;

@Schema(example = "100")
@Positive
private int maxPlaces;

@Schema(example = "10")
@Positive
private int available;
}
4 changes: 0 additions & 4 deletions src/main/java/org/zzpj/tabi/dto/travel/TravelUpdateDTO.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package org.zzpj.tabi.dto.travel;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Positive;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;
Expand All @@ -26,7 +24,5 @@ public class TravelUpdateDTO {
private String description;

@Schema(example = "0")
@Positive
@NotEmpty
private Long version;
}
10 changes: 10 additions & 0 deletions src/main/java/org/zzpj/tabi/services/ReservationService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ public void createReservation(Client client, Travel travel, int guestCount) thro
throw new InvalidGuestCountException("Not enough available places");
}
BigDecimal amount = travel.getBasePrice().multiply(new BigDecimal(guestCount));
switch (client.getStatus()) {
case Client.Status.BRONZE:
break;
case Client.Status.SILVER:
amount = amount.multiply(new BigDecimal("0.9"));
break;
case Client.Status.GOLD:
amount = amount.multiply(new BigDecimal("0.8"));
break;
}
String title = "travel " + travel.getId();
travel.setAvailablePlaces(travel.getAvailablePlaces() - guestCount);
if (!travel.getVersion().equals(travelRepository.findById(travel.getId()).orElseThrow().getVersion())) {
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
spring.datasource.url=jdbc:postgresql://${DB_HOSTNAME}/${DB_NAME}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}
1 change: 1 addition & 0 deletions src/main/resources/application-prod.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spring.datasource.url=jdbc:postgresql://${DB_HOSTNAME}/${DB_NAME}?user=${POSTGRES_USER}&password=${POSTGRES_PASSWORD}&sslmode=require
4 changes: 1 addition & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ spring.config.import=optional:file:.env[.properties]

spring.application.name=tabi

spring.datasource.url=jdbc:postgresql://${DB_HOSTNAME}/${DB_NAME}
spring.datasource.username=${POSTGRES_USER}
spring.datasource.password=${POSTGRES_PASSWORD}
spring.profiles.active=${APP_PROFILE}

spring.sql.init.mode=always

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/payments.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
api.stripe.public-key=${STRIPE_PUBLIC_KEY}
api.stripe.private-key=${STRIPE_PRIVATE_KEY}

0 comments on commit 4d327d6

Please sign in to comment.