docs: Added simple docs and dockerized backend
This commit is contained in:
20
backend/Dockerfile
Normal file
20
backend/Dockerfile
Normal file
@ -0,0 +1,20 @@
|
||||
# Use an official Maven image with Java 17 as the base image
|
||||
FROM maven:3.8.4-openjdk-17 AS build
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
# Copy the pom.xml and the project files to the container
|
||||
COPY pom.xml .
|
||||
COPY src ./src
|
||||
# Build the application using Maven
|
||||
RUN mvn clean package -DskipTests
|
||||
# Use an official OpenJDK image with Java 17 as the base image
|
||||
FROM openjdk:17-jdk-slim AS runtime
|
||||
# Set the working directory in the container
|
||||
WORKDIR /app
|
||||
# Copy the built JAR file from the previous stage to the container
|
||||
COPY --from=build /app/target/*.jar ./app.jar
|
||||
|
||||
EXPOSE 8080
|
||||
# Set the command to run the application
|
||||
CMD ["java", "-jar", "app.jar"]
|
||||
|
32
backend/docker-compose.yml
Normal file
32
backend/docker-compose.yml
Normal file
@ -0,0 +1,32 @@
|
||||
version: "3.8"
|
||||
|
||||
services:
|
||||
backend:
|
||||
build:
|
||||
context: .
|
||||
ports:
|
||||
- "8080:8080"
|
||||
environment:
|
||||
DB_USERNAME: root
|
||||
DB_PASSWORD: chronos
|
||||
DATASOURCE_URL: jdbc:mysql://database:3306/chronos
|
||||
depends_on:
|
||||
- database
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
database:
|
||||
image: mysql:8.0
|
||||
environment:
|
||||
MYSQL_ROOT_PASSWORD: chronos
|
||||
MYSQL_DATABASE: chronos
|
||||
volumes:
|
||||
- db_data:/var/lib/mysql
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
networks:
|
||||
app-network:
|
||||
|
||||
volumes:
|
||||
db_data:
|
@ -27,7 +27,7 @@
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>23</java.version>
|
||||
<java.version>17</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -11,7 +11,7 @@ import cz.jzitnik.chronos.payload.responses.UnifiedResponse;
|
||||
import cz.jzitnik.chronos.repository.CharacterRepository;
|
||||
import cz.jzitnik.chronos.repository.PlayerRepository;
|
||||
import cz.jzitnik.chronos.services.ItemService;
|
||||
import cz.jzitnik.chronos.utils.anotations.CheckUser;
|
||||
import cz.jzitnik.chronos.utils.annotations.CheckUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -5,7 +5,7 @@ import cz.jzitnik.chronos.payload.requests.MessageRequest;
|
||||
import cz.jzitnik.chronos.payload.responses.UnifiedResponse;
|
||||
import cz.jzitnik.chronos.repository.MessageRepository;
|
||||
import cz.jzitnik.chronos.repository.PlayerRepository;
|
||||
import cz.jzitnik.chronos.utils.anotations.CheckUser;
|
||||
import cz.jzitnik.chronos.utils.annotations.CheckUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
|
@ -9,7 +9,7 @@ import cz.jzitnik.chronos.repository.GameRepository;
|
||||
import cz.jzitnik.chronos.repository.ItemRepository;
|
||||
import cz.jzitnik.chronos.repository.PlayerRepository;
|
||||
import cz.jzitnik.chronos.services.GameService;
|
||||
import cz.jzitnik.chronos.utils.anotations.CheckUser;
|
||||
import cz.jzitnik.chronos.utils.annotations.CheckUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -17,7 +17,7 @@ import cz.jzitnik.chronos.repository.GameRepository;
|
||||
import cz.jzitnik.chronos.repository.ItemRepository;
|
||||
import cz.jzitnik.chronos.repository.PlayerRepository;
|
||||
import cz.jzitnik.chronos.services.GameService;
|
||||
import cz.jzitnik.chronos.utils.anotations.CheckUser;
|
||||
import cz.jzitnik.chronos.utils.annotations.CheckUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@ -154,7 +154,7 @@ public class PlayerController {
|
||||
if (item.getOwner() == null || !item.getOwner().getId().equals(player.getId())) {
|
||||
return ResponseEntity.status(HttpStatus.FORBIDDEN).body(UnifiedResponse.failure(new Error("You don't own this item!")));
|
||||
}
|
||||
if (player.getInventorySize() - player.getInventory().size() == 0) {
|
||||
if (player2.getInventorySize() - player2.getInventory().size() == 0) {
|
||||
// Inventory is full
|
||||
return ResponseEntity.status(HttpStatus.CONFLICT).body(UnifiedResponse.failure(new FullInventoryError("Player has full inventory!")));
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import cz.jzitnik.chronos.repository.PlayerRepository;
|
||||
import cz.jzitnik.chronos.repository.RoomRepository;
|
||||
import cz.jzitnik.chronos.services.GameService;
|
||||
import cz.jzitnik.chronos.services.ItemService;
|
||||
import cz.jzitnik.chronos.utils.anotations.CheckUser;
|
||||
import cz.jzitnik.chronos.utils.annotations.CheckUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -12,9 +12,7 @@ public enum ItemType {
|
||||
|
||||
public void useItem(Player player) throws ItemNotUsableException {
|
||||
switch (this) {
|
||||
case LUCK_POTION -> {
|
||||
player.setLuck(true);
|
||||
}
|
||||
case LUCK_POTION -> player.setLuck(true);
|
||||
default -> throw new ItemNotUsableException("Item " + this + " is not usable");
|
||||
}
|
||||
}
|
||||
|
@ -33,12 +33,12 @@ public class Baker implements InteractionPlayer {
|
||||
return new InteractionResponse(false, "Nemáš pro mě buď mouku nebo vodu. Dej mi obojí najednou!", new ArrayList<>());
|
||||
}
|
||||
|
||||
var flour = flours.getFirst();
|
||||
var flour = flours.get(0);
|
||||
flour.setOwner(null);
|
||||
itemRepository.save(flour);
|
||||
playerItems.remove(flour);
|
||||
|
||||
var onewater = water.getFirst();
|
||||
var onewater = water.get(0);
|
||||
onewater.setOwner(null);
|
||||
itemRepository.save(onewater);
|
||||
playerItems.remove(onewater);
|
||||
|
@ -32,7 +32,7 @@ public class Mayor implements InteractionPlayer {
|
||||
return new InteractionResponse(false, "Nemáš zlaté hodinky v inventáři!", new ArrayList<>());
|
||||
}
|
||||
|
||||
var goldenWatch = goldenWatches.getFirst();
|
||||
var goldenWatch = goldenWatches.get(0);
|
||||
goldenWatch.setOwner(null);
|
||||
itemRepository.save(goldenWatch);
|
||||
playerItems.remove(goldenWatch);
|
||||
|
@ -108,7 +108,7 @@ public class NumberGuessingGame implements InteractionPlayer {
|
||||
if (coals.isEmpty()) {
|
||||
return new InteractionResponse(false, "Nemáš uhlí pro mě!", new ArrayList<>());
|
||||
}
|
||||
var coal = coals.getFirst();
|
||||
var coal = coals.get(0);
|
||||
coal.setOwner(null);
|
||||
itemRepository.save(coal);
|
||||
player.getInventory().remove(coal);
|
||||
|
@ -1,4 +1,4 @@
|
||||
package cz.jzitnik.chronos.utils.anotations;
|
||||
package cz.jzitnik.chronos.utils.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
@ -1,4 +1,4 @@
|
||||
package cz.jzitnik.chronos.utils.anotations;
|
||||
package cz.jzitnik.chronos.utils.annotations;
|
||||
|
||||
import cz.jzitnik.chronos.payload.errors.PlayerNotFoundError;
|
||||
import cz.jzitnik.chronos.payload.responses.UnifiedResponse;
|
Reference in New Issue
Block a user