Remove outdated BillingController implementation, resolve conflicting bean definitions across modules, and retain the updated BillingController for consistency with frontend API logic.

This commit is contained in:
2026-04-12 21:51:33 +02:00
parent 9754f3e36b
commit 5eb2dd6904
28 changed files with 912 additions and 776 deletions
@@ -1,31 +1,26 @@
# syntax=docker/dockerfile:1.7
# ===================================================================
# Dockerfile for Billing Service
# Based on Spring Boot Service Template with Billing-specific configuration
# Multi-stage Dockerfile for Meldestelle Billing Service
# Features: Security hardening, monitoring support, optimal caching, BuildKit cache mounts
# Version: 2.6.0 - Reliable Monorepo Build
# ===================================================================
# === CENTRALIZED BUILD ARGUMENTS ===
ARG GRADLE_VERSION
ARG JAVA_VERSION
ARG GRADLE_VERSION=9.4.1
ARG JAVA_VERSION=25
ARG BUILD_DATE
ARG VERSION
# Service-specific arguments
ARG SERVICE_PATH=billing/billing-service
ARG SERVICE_NAME=billing-service
ARG VERSION=1.0.0-SNAPSHOT
# ===================================================================
# Build Stage
# ===================================================================
FROM gradle:${GRADLE_VERSION}-jdk${JAVA_VERSION}-alpine AS builder
FROM eclipse-temurin:${JAVA_VERSION}-jdk-alpine AS builder
# Re-declare build arguments for this stage
ARG SERVICE_PATH=billing/billing-service
ARG SERVICE_NAME=billing-service
ARG VERSION
ARG BUILD_DATE
LABEL stage=builder
LABEL maintainer="Meldestelle Development Team"
LABEL stage=builder \
service="billing-service" \
maintainer="Meldestelle Development Team"
WORKDIR /workspace
@@ -33,30 +28,24 @@ WORKDIR /workspace
ENV GRADLE_OPTS="-Dorg.gradle.caching=true \
-Dorg.gradle.daemon=false \
-Dorg.gradle.parallel=true \
-Dorg.gradle.configureondemand=true \
-Xmx2g"
-Dorg.gradle.workers.max=2 \
-Dorg.gradle.jvmargs=-Xmx2g \
-XX:+UseParallelGC \
-XX:MaxMetaspaceSize=512m"
ENV GRADLE_USER_HOME=/root/.gradle
# Copy build files in optimal order for caching
COPY gradlew gradlew.bat gradle.properties settings.gradle.kts ./
COPY gradle/ gradle/
# 1. Copy full project structure for a reliable monorepo build
# .dockerignore should be used to exclude unnecessary files (IDE, logs, etc.)
COPY . .
# Make gradlew executable
RUN chmod +x gradlew
COPY platform/ platform/
COPY core/ core/
COPY build.gradle.kts ./
# Copy billing service modules
COPY backend/services/billing/billing-domain/ backend/services/billing/billing-domain/
COPY backend/services/billing/billing-service/ backend/services/billing/billing-service/
# Build billing service
RUN echo "Building Billing Service..." && \
./gradlew :backend:services:billing:billing-service:dependencies --no-daemon --info && \
# 2. Build the service
RUN --mount=type=cache,target=/root/.gradle/caches \
--mount=type=cache,target=/root/.gradle/wrapper \
./gradlew :backend:services:billing:billing-service:bootJar --no-daemon --info
# Extract JAR layers
# 3. Extract layers
WORKDIR /builder
RUN cp /workspace/backend/services/billing/billing-service/build/libs/*.jar app.jar && \
java -Djarmode=layertools -jar app.jar extract
@@ -66,38 +55,32 @@ RUN cp /workspace/backend/services/billing/billing-service/build/libs/*.jar app.
# ===================================================================
FROM eclipse-temurin:${JAVA_VERSION}-jre-alpine AS runtime
# Metadata
LABEL service="billing-service" \
version="1.0.0" \
description="Billing and Financial Service for Austrian Equestrian Federation" \
maintainer="Meldestelle Development Team" \
java.version="${JAVA_VERSION}"
ARG BUILD_DATE
ARG VERSION
ARG JAVA_VERSION
# Build arguments
ARG APP_USER=billinguser
ARG APP_GROUP=billinggroup
ARG APP_UID=1008
ARG APP_GID=1008
LABEL service="billing-service" \
version="${VERSION}" \
description="Microservice for Billing and Payments" \
maintainer="Meldestelle Development Team" \
java.version="${JAVA_VERSION}" \
build.date="${BUILD_DATE}"
ARG APP_USER=appuser
ARG APP_GROUP=appgroup
ARG APP_UID=1001
ARG APP_GID=1001
WORKDIR /app
# System setup
RUN apk update && \
apk upgrade && \
apk add --no-cache curl jq tzdata && \
rm -rf /var/cache/apk/*
# Non-root user creation
RUN addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh
# Directory setup
RUN mkdir -p /app/logs /app/tmp && \
chown -R ${APP_USER}:${APP_GROUP} /app
# Re-declare build arguments for runtime stage
ARG SERVICE_PATH=billing/billing-service
ARG SERVICE_NAME=billing-service
apk add --no-cache curl tzdata tini && \
rm -rf /var/cache/apk/* && addgroup -g ${APP_GID} -S ${APP_GROUP} && \
adduser -u ${APP_UID} -S ${APP_USER} -G ${APP_GROUP} -h /app -s /bin/sh && \
mkdir -p /app/logs /app/tmp /app/config && \
chown -R ${APP_USER}:${APP_GROUP} /app && \
chmod -R 750 /app
# Copy Spring Boot layers
COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /builder/dependencies/ ./
@@ -107,35 +90,38 @@ COPY --from=builder --chown=${APP_USER}:${APP_GROUP} /builder/application/ ./
USER ${APP_USER}
# Expose application port and debug port
EXPOSE 8087 5012
EXPOSE 8087 5005
# Health check
HEALTHCHECK --interval=15s --timeout=3s --start-period=40s --retries=3 \
CMD curl -fsS --max-time 2 http://localhost:8087/actuator/health/readiness || exit 1
# JVM configuration
ENV JAVA_OPTS="-XX:MaxRAMPercentage=80.0 \
ENV JAVA_OPTS="-XX:MaxRAMPercentage=75.0 \
-XX:+UseG1GC \
-XX:+UseStringDeduplication \
-XX:+UseContainerSupport \
-XX:G1HeapRegionSize=16m \
-XX:G1ReservePercent=25 \
-XX:InitiatingHeapOccupancyPercent=30 \
-XX:+AlwaysPreTouch \
-XX:+DisableExplicitGC \
-Djava.security.egd=file:/dev/./urandom \
-Djava.awt.headless=true \
-Dfile.encoding=UTF-8 \
-Duser.timezone=Europe/Vienna"
-Duser.timezone=Europe/Vienna \
-Dspring.backgroundpreinitializer.ignore=true \
-Dmanagement.endpoints.web.exposure.include=health,info,metrics,prometheus \
-Dmanagement.endpoint.health.show-details=always \
-Dmanagement.prometheus.metrics.export.enabled=true"
# Spring Boot configuration
ENV SPRING_OUTPUT_ANSI_ENABLED=ALWAYS \
SERVER_PORT=8087 \
LOGGING_LEVEL_ROOT=INFO \
LOGGING_LEVEL_AT_MOCODE_BILLING=DEBUG
LOGGING_LEVEL_ROOT=INFO
# Startup command
ENTRYPOINT ["sh", "-c", "\
echo 'Starting Billing Service on port 8087...'; \
ENTRYPOINT ["tini", "--", "sh", "-c", "\
echo 'Starting Billing Service with Java ${JAVA_VERSION}...'; \
if [ \"${DEBUG:-false}\" = \"true\" ]; then \
echo 'Debug mode enabled on port 5012'; \
exec java $JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5012 org.springframework.boot.loader.launch.JarLauncher; \
echo 'DEBUG mode enabled'; \
exec java ${JAVA_OPTS} -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 org.springframework.boot.loader.launch.JarLauncher; \
else \
exec java $JAVA_OPTS org.springframework.boot.loader.launch.JarLauncher; \
exec java ${JAVA_OPTS} org.springframework.boot.loader.launch.JarLauncher; \
fi"]
@@ -1,65 +0,0 @@
@file:OptIn(ExperimentalUuidApi::class)
package at.mocode.billing.service.api
import at.mocode.billing.domain.model.Buchung
import at.mocode.billing.domain.model.BuchungsTyp
import at.mocode.billing.domain.model.TeilnehmerKonto
import at.mocode.billing.service.TeilnehmerKontoService
import org.springframework.web.bind.annotation.*
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid
@RestController
@RequestMapping("/api/v1/billing")
class BillingController(
private val kontoService: TeilnehmerKontoService
) {
@GetMapping("/konten/{kontoId}")
fun getKonto(@PathVariable kontoId: String): TeilnehmerKonto? {
return kontoService.getKontoById(Uuid.parse(kontoId))
}
@GetMapping("/veranstaltungen/{veranstaltungId}/personen/{personId}")
fun getOrCreateKonto(
@PathVariable veranstaltungId: String,
@PathVariable personId: String,
@RequestParam(required = false) personName: String?
): TeilnehmerKonto {
return kontoService.getOrCreateKonto(
Uuid.parse(veranstaltungId),
Uuid.parse(personId),
personName ?: "Unbekannter Teilnehmer"
)
}
@GetMapping("/konten/{kontoId}/historie")
fun getHistorie(@PathVariable kontoId: String): List<Buchung> {
return kontoService.getBuchungsHistorie(Uuid.parse(kontoId))
}
@GetMapping("/veranstaltungen/{veranstaltungId}/konten")
fun getKonten(@PathVariable veranstaltungId: String): List<TeilnehmerKonto> {
return kontoService.getKontenFuerVeranstaltung(Uuid.parse(veranstaltungId))
}
@PostMapping("/konten/{kontoId}/buche")
fun buche(
@PathVariable kontoId: String,
@RequestBody request: BuchungRequest
): TeilnehmerKonto {
return kontoService.buche(
Uuid.parse(kontoId),
request.betragCent,
request.typ,
request.verwendungszweck
)
}
}
data class BuchungRequest(
val betragCent: Long,
val typ: BuchungsTyp,
val verwendungszweck: String
)
@@ -38,12 +38,12 @@ class TeilnehmerKontoServiceTest {
zweck = "Nennung Bewerb 1"
)
assertEquals(1500L, updatedKonto.saldoCent)
assertEquals(-1500L, updatedKonto.saldoCent)
// 3. Buchungshistorie prüfen
val buchungen = service.getBuchungsHistorie(konto.kontoId)
assertEquals(1, buchungen.size)
assertEquals(1500L, buchungen[0].betragCent)
assertEquals(-1500L, buchungen[0].betragCent)
assertEquals("Nennung Bewerb 1", buchungen[0].verwendungszweck)
}
@@ -54,9 +54,9 @@ class TeilnehmerKontoServiceTest {
val konto = service.getOrCreateKonto(vId, pId, "Susi Sorglos")
service.buche(konto.kontoId, 2000L, BuchungsTyp.STARTGEBUEHR, "Startgeld")
val finalKonto = service.buche(konto.kontoId, -500L, BuchungsTyp.STORNIERUNG, "Storno")
val finalKonto = service.buche(konto.kontoId, 500L, BuchungsTyp.STORNIERUNG, "Storno")
assertEquals(1500L, finalKonto.saldoCent)
assertEquals(-1500L, finalKonto.saldoCent)
val historian = service.getBuchungsHistorie(konto.kontoId)
assertEquals(2, historian.size)