diff --git a/.gitignore b/.gitignore index cd70ec8..c011414 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +.env .gradle build/ !gradle/wrapper/gradle-wrapper.jar diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6196572 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,38 @@ +services: +# spring-boot-kotlin-app: +# image: 'spring-boot-kotlin-app:latest' # Specifies the Docker image for the Spring Boot application +# build: +# context: . # Specifies the build context, which is the current directory +# container_name: spring-boot-kotlin-app # Names the container 'spring-boot-kotlin-app' +# depends_on: +# - db # Ensures that the 'db' service starts before the 'spring-boot-kotlin-app' service +# environment: +# - SPRING_DATASOURCE_URL=${SPRING_DATASOURCE_URL} +# - SPRING_DATASOURCE_USERNAME=${POSTGRES_USER} +# - SPRING_DATASOURCE_PASSWORD=${POSTGRES_PASSWORD} +# - SPRING_JPA_HIBERNATE_DDL_AUTO=update # Configures Hibernate to update the database schema +# ports: +# - "8456:8456" +# networks: +# - app-network + + db: + image: postgres:latest + container_name: db + environment: + - POSTGRES_USER=${POSTGRES_USER} + - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} + - POSTGRES_DB=${POSTGRES_DB} + volumes: + - postgres_data:/var/lib/postgresql/data # Mounts a volume to persist PostgreSQL data + ports: + - "5432:5432" + networks: + - app-network + +volumes: + postgres_data: # Defines a named volume for PostgreSQL data persistence + +networks: + app-network: + driver: bridge \ No newline at end of file diff --git a/src/main/kotlin/de/tobjend/strategy/model/Game.kt b/src/main/kotlin/de/tobjend/strategy/model/Game.kt new file mode 100644 index 0000000..8b7321f --- /dev/null +++ b/src/main/kotlin/de/tobjend/strategy/model/Game.kt @@ -0,0 +1,17 @@ +package de.tobjend.strategy.model + +import jakarta.persistence.* + +@Entity +@Table(name = "games") +data class Game( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, + + @Column(name = "name", nullable = false) + val name: String, + + @OneToMany(mappedBy = "game", cascade = [CascadeType.ALL], fetch = FetchType.LAZY, orphanRemoval = true) + val players: MutableList = mutableListOf() +) \ No newline at end of file diff --git a/src/main/kotlin/de/tobjend/strategy/model/Player.kt b/src/main/kotlin/de/tobjend/strategy/model/Player.kt new file mode 100644 index 0000000..092b0c2 --- /dev/null +++ b/src/main/kotlin/de/tobjend/strategy/model/Player.kt @@ -0,0 +1,5 @@ +package de.tobjend.strategy.model + +data class Players( + val players: List +) \ No newline at end of file diff --git a/src/main/kotlin/de/tobjend/strategy/model/Players.kt b/src/main/kotlin/de/tobjend/strategy/model/Players.kt new file mode 100644 index 0000000..479fd5d --- /dev/null +++ b/src/main/kotlin/de/tobjend/strategy/model/Players.kt @@ -0,0 +1,21 @@ +package de.tobjend.strategy.model + +import jakarta.persistence.* + +@Entity +@Table(name = "players") +data class Player( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, + + @Column(name = "name", nullable = false) + val name: String, + + @Column(name = "position", nullable = false) + val position: String, + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "game_id") + var game: Game? = null +) \ No newline at end of file diff --git a/src/main/kotlin/de/tobjend/strategy/model/Strategy.kt b/src/main/kotlin/de/tobjend/strategy/model/Strategy.kt new file mode 100644 index 0000000..a51bd49 --- /dev/null +++ b/src/main/kotlin/de/tobjend/strategy/model/Strategy.kt @@ -0,0 +1,19 @@ +package de.tobjend.strategy.model + +import jakarta.persistence.* + +@Entity(name = "strategies") + data class Strategy( + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + val id: Long = 0, + + @Column(name = "name", nullable = false) + val name: String, + + @Column(name = "description", nullable = true) + val description: String?, + + @Column(name = "effectiveness") + val effectiveness: Double +) \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 3c783b1..af70d4d 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1 +1,6 @@ spring.application.name=strategy +spring.datasource.url=jdbc:postgresql://localhost:5432/strategy +spring.datasource.username=tobi +spring.datasource.password=risICE3 +spring.jpa.hibernate.ddl-auto=update +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect