Compare commits

...

3 Commits

Author SHA1 Message Date
40f983980d API's met returns van objecten
Some checks failed
Docker Image CI / build-and-push (push) Failing after 20s
Docker Image CI / deploy (push) Has been skipped
2025-03-22 16:55:46 +01:00
2a50edc41d deploy to test 2025-03-22 16:54:25 +01:00
70f6b0c7b2 email fix 2025-03-22 16:54:12 +01:00
6 changed files with 159 additions and 17 deletions

View File

@@ -0,0 +1,139 @@
name: Docker Image CI
on:
push:
branches:
- develop
tags:
- "docker-build-*"
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
# Stap 1: Code ophalen
- uses: actions/checkout@v4
# Stap 2: Versienummer ophalen uit pom.xml en opslaan als artifact
- name: Extract Quarkus version from pom.xml
run: |
VERSION=$(xmlstarlet sel -t -v "/project/version" pom.xml)
echo $VERSION > version.txt
- name: Save version as artifact
uses: actions/upload-artifact@v3
with:
name: version
path: version.txt
# Stap 3: Notify Mattermost via Bot (Build gestart)
- name: Notify Mattermost via Bot
env:
VERSION: ${{ env.VERSION }}
REPO: ${{ gitea.repository }}
BRANCH: ${{ gitea.ref }}
MATTERMOST_BOT_TOKEN: ${{ secrets.MATTERMOST_BOT_TOKEN }}
run: |
curl --fail -X POST -H "Authorization: Bearer $MATTERMOST_BOT_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"channel_id": "9a8obynkd7rctk6qf8rfe6oppy",
"message": "@all 🚀 *Build gestart!* Een nieuwe build ['"$VERSION"'-SNAPSHOT] is begonnen voor de repository *'"$REPO"'* op branch *'"$BRANCH"'*."
}' \
https://mattermost.melvanveen.nl/api/v4/posts
# Stap 4: Inloggen bij Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Stap 5: Quarkus JAR bouwen (via Maven) en Docker-image bouwen
- name: Build the Quarkus JAR and Docker image
run: |
VERSION=$(cat version.txt)
mvn clean package -DskipTests
docker buildx build . --file Dockerfile --tag veenm/paypoint-backend-jvm:$VERSION-SNAPSHOT --platform linux/amd64
# Stap 6: Docker-image pushen naar Docker Hub (huidige versie tag)
- name: Push the Docker image (version-snapshot)
run: |
VERSION=$(cat version.txt)
docker push veenm/paypoint-backend-jvm:$VERSION-SNAPSHOT
deploy:
needs: build-and-push
runs-on: ubuntu-latest
steps:
# Stap 1: Artifact ophalen
- name: Download version artifact
uses: actions/download-artifact@v3
with:
name: version
# Stap 2: Lees versie uit het artifact
- name: Read version
id: read_version
run: echo "VERSION=$(cat version.txt)" >> $GITHUB_ENV
- name: Inject private key into resources
run: |
mkdir -p src/main/resources
echo "${{ secrets.PRIVATE_KEY }}" > src/main/resources/privateKey.pem
chmod 600 src/main/resources/privateKey.pem
- name: Inject public key into resources
run: |
mkdir -p src/main/resources
echo "${{ secrets.PUBLIC_KEY }}" > src/main/resources/publicKey.pem
chmod 600 src/main/resources/publicKey.pem
# Stap 3: Maak verbinding via SSH naar de Alpine server en update de container
- name: SSH into Alpine and update Docker container
uses: appleboy/ssh-action@v0.1.10
with:
host: ${{ secrets.ALPINE_HOST }}
username: ${{ secrets.ALPINE_USER }}
password: ${{ secrets.ALPINE_PASSWORD }}
script: |
VERSION=${{ env.VERSION }}
echo "Gekozen versie: $VERSION-SNAPSHOT"
# Stop en verwijder de huidige container
docker stop paypoint-backend || true
docker rm paypoint-backend || true
# Haal de nieuwste image binnen
docker pull veenm/paypoint-backend-jvm:$VERSION-SNAPSHOT
# Start een nieuwe container
docker run -d --name paypoint-backend --restart unless-stopped -p 15000:8080 \
-e DB_HOST=${{ secrets.ALPINE_HOST }} \
-e DB_PORT=${{ secrets.DB_PORT_TEST }} \
-e DB_USERNAME=${{ secrets.DB_USERNAME_TEST }} \
-e DB_PASSWORD=${{ secrets.DB_PASSWORD_TEST }} \
-e CORS_ORIGINS=${{ secrets.CORS_ORIGINS_TEST }} \
-e MAILER_FROM=${{ secrets.MAILER_FROM }} \
-e MAILER_HOST=${{ secrets.MAILER_HOST }} \
-e MAILER_PORT=${{ secrets.MAILER_PORT }} \
-e MAILER_USERNAME=${{ secrets.MAILER_USERNAME }} \
-e MAILER_PASSWORD=${{ secrets.MAILER_PASSWORD }} \
veenm/paypoint-backend-jvm:$VERSION-SNAPSHOT
# Opruimen oude images
docker image prune -f
# Stap 4: Notify Mattermost via Bot (Build is geslaagd)
- name: Notify Mattermost via Bot
env:
VERSION: ${{ env.VERSION }}
run: |
curl --fail -X POST -H "Authorization: Bearer $MATTERMOST_BOT_TOKEN" \
-H 'Content-Type: application/json' \
-d '{
"channel_id": "9a8obynkd7rctk6qf8rfe6oppy",
"message": "@all ✅ *Build is geslaagd!* Versie '"$VERSION"'-SNAPSHOT staat klaar op https://test-paypoint.melvanveen.nl"
}' \
https://mattermost.melvanveen.nl/api/v4/posts

View File

@@ -37,12 +37,15 @@ public class AppointmentResource {
return appointmentService.getAppointmentsByDate(start, companyId);
}
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/recent/{id}")
public Appointment getMostRecentAppointment(@PathParam("id") Long userId) {
return appointmentService.getMostRecentByUserId(userId);
}
//TODO: Deze werkend maken
// @GET
// @Produces(MediaType.APPLICATION_JSON)
// @Path("/recent/{id}")
// public Appointment getMostRecentAppointment(@PathParam("id") Long userId) {
// return appointmentService.getMostRecentByUserId(userId);
// }
@GET
@Produces(MediaType.APPLICATION_JSON)
@@ -56,8 +59,7 @@ public class AppointmentResource {
public Response addAppointment(Appointment appointment) {
JsonNumber companyIdJson = jwt.getClaim("company_id");
Long companyId = companyIdJson.longValue();
appointmentService.add(appointment, companyId);
return Response.ok().build();
return Response.ok(appointmentService.add(appointment, companyId)).build();
}
@DELETE
@@ -70,7 +72,6 @@ public class AppointmentResource {
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public Response updateAppointment(Appointment appointment) {
appointmentService.update(appointment);
return Response.ok().build();
return Response.ok(appointmentService.update(appointment)).build();
}
}

View File

@@ -28,7 +28,6 @@ public class CustomerResource {
@POST
@Produces(MediaType.APPLICATION_JSON)
public Response addCustomer(Customer customer) {
customerService.addCustomer(customer);
return Response.ok().build();
return Response.ok(customerService.addCustomer(customer)).build();
}
}

View File

@@ -34,11 +34,12 @@ public class AppointmentService {
}
@Transactional
public void add(Appointment appointment, Long companyId) {
public Appointment add(Appointment appointment, Long companyId) {
Company company = companyRepository.findById(companyId);
appointment.setCompany(company);
appointmentRepository.persist(appointment);
emailService.stuurBevestiging(appointment);
return appointment;
}
@Transactional
@@ -59,7 +60,7 @@ public class AppointmentService {
}
@Transactional
public void update(Appointment appointment) {
public Appointment update(Appointment appointment) {
Appointment appointmentToUpdate = appointmentRepository.findById(appointment.getId());
appointmentToUpdate.setTitle(appointment.getTitle());
appointmentToUpdate.setStartDate(appointment.getStartDate());
@@ -72,6 +73,7 @@ public class AppointmentService {
appointmentToUpdate.setDurationInMinutes(appointment.getDurationInMinutes());
appointmentRepository.persist(appointmentToUpdate);
emailService.stuurBewerking(appointmentToUpdate);
return appointmentToUpdate;
}
@Transactional

View File

@@ -28,7 +28,8 @@ public class CustomerService {
}
@Transactional
public void addCustomer(Customer customer) {
public Customer addCustomer(Customer customer) {
customerRepository.persist(customer);
return customer;
}
}

View File

@@ -197,7 +197,7 @@ public class EmailService {
String subject = String.format(" Afspraak geannuleerd: %s", formattedDate);
String recipient = appointment.getCustomer().getEmail();
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>"));
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>").setReplyTo(company.getEmail()));
}
public void stuurBewerking(Appointment appointment) {
@@ -285,7 +285,7 @@ public class EmailService {
String subject = String.format(" Afspraak gewijzigd: %s", formattedDate);
String recipient = appointment.getCustomer().getEmail();
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom(company.getEmail()));
mailer.send(Mail.withHtml(recipient, subject, emailBody).setFrom("Hairstyling By Daan <paypoint@melvanveen.nl>").setReplyTo(company.getEmail()));
}
public void stuurHerinnering(Appointment appointment) {