diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..05c4e4b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,16 @@ +# Stage 1: Build the application +FROM maven:3.9.6-eclipse-temurin-17 AS build +WORKDIR /app +# Copy only the pom.xml first to leverage Docker cache for dependencies +COPY pom.xml . +RUN mvn dependency:go-offline -B +# Copy source code and build +COPY src ./src +RUN mvn clean package -DskipTests + +# Stage 2: Run the application +FROM eclipse-temurin:17-jre-jammy +WORKDIR /app +COPY --from=build /app/target/*.jar app.jar +EXPOSE 8080 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/README.md b/README.md index fc4b445..241fed7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,40 @@ +# Ramsai Kitchen + +Digital restaurant management system built with Spring Boot and PostgreSQL. + +## Quick Start Tutorial + +### Prerequisites +- Docker and Docker Compose installed on your machine. + +### First-Time Running the Project +1. **Clone the repository**: + ```bash + git clone + cd RamsAI-Kitchen + ``` + +2. **Start the application**: + Use Docker Compose to build and start both the database and the application: + ```bash + docker compose up --build + ``` + The application will be available at [http://localhost:8080](http://localhost:8080). + +### Development with Docker Compose Watch +For a faster development loop, this project supports `docker compose watch`. This allows you to see your changes in real-time without manually rebuilding the containers. + +1. **Run in watch mode**: + ```bash + docker compose watch + ``` + +2. **What happens during watch?**: + - **Static Files**: Any changes in `src/main/resources/static` will be automatically synced to the running container. + - **Java Code & Dependencies**: Any changes in `src/` or `pom.xml` will trigger an automatic rebuild and restart of the application container, ensuring your backend changes are reflected immediately. + +--- + ## User Stories & Acceptance Criteria ### 1. Menu Access diff --git a/docker-compose.yml b/docker-compose.yml index 610d8f0..77a0a07 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,4 +11,35 @@ services: ports: - "5432:5432" volumes: - - ./src/main/resources/sql/schema.sql:/docker-entrypoint-initdb.d/schema.sql + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U ramsai -d ramsai_kitchen"] + interval: 5s + timeout: 5s + retries: 5 + + app: + build: . + container_name: ramsai-kitchen-app + ports: + - "8080:8080" + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/ramsai_kitchen + - SPRING_DATASOURCE_USERNAME=ramsai + - SPRING_DATASOURCE_PASSWORD=kitchen_password + - SPRING_JPA_HIBERNATE_DDL_AUTO=validate + depends_on: + db: + condition: service_healthy + develop: + watch: + - path: ./src/main/resources/static + action: sync + target: /app/resources/static + - path: ./pom.xml + action: rebuild + - path: ./src + action: rebuild + +volumes: + postgres_data: diff --git a/pom.xml b/pom.xml index a6a27e2..2b44527 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,7 @@ 17 1.5.5.Final 0.2.0 + 1.18.32 @@ -52,6 +53,7 @@ org.projectlombok lombok + ${lombok.version} true @@ -60,6 +62,12 @@ ${org.mapstruct.version} + + org.springframework.boot + spring-boot-devtools + runtime + true + org.springframework.boot spring-boot-starter-test @@ -77,10 +85,13 @@ org.apache.maven.plugins maven-compiler-plugin - 3.11.0 + 3.13.0 ${java.version} ${java.version} + + -parameters + org.projectlombok diff --git a/src/main/java/com/ramsai/kitchen/config/SecurityConfig.java b/src/main/java/com/ramsai/kitchen/config/SecurityConfig.java new file mode 100644 index 0000000..c5134ab --- /dev/null +++ b/src/main/java/com/ramsai/kitchen/config/SecurityConfig.java @@ -0,0 +1,30 @@ +package com.ramsai.kitchen.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +@EnableWebSecurity +public class SecurityConfig { + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .csrf(AbstractHttpConfigurer::disable) + .authorizeHttpRequests(auth -> auth + .requestMatchers("/", "/index.html", "/error", "/static/**", "/css/**", "/js/**", "/images/**").permitAll() + .anyRequest().permitAll() + ) + .formLogin(login -> login + .defaultSuccessUrl("/", true) + .permitAll() + ) + .logout(logout -> logout.permitAll()); + + return http.build(); + } +} diff --git a/src/main/java/com/ramsai/kitchen/enums/ItemStatus.java b/src/main/java/com/ramsai/kitchen/enums/ItemStatus.java index 087b07a..8d39760 100644 --- a/src/main/java/com/ramsai/kitchen/enums/ItemStatus.java +++ b/src/main/java/com/ramsai/kitchen/enums/ItemStatus.java @@ -1,5 +1,5 @@ package com.ramsai.kitchen.enums; public enum ItemStatus { - PENDING, PREPARING, READY, SERVED + PENDING, COOKING, READY, SERVED, CANCELLED } diff --git a/src/main/java/com/ramsai/kitchen/exceptions/InsufficientStockException.java b/src/main/java/com/ramsai/kitchen/exceptions/InsufficientStockException.java new file mode 100644 index 0000000..a765402 --- /dev/null +++ b/src/main/java/com/ramsai/kitchen/exceptions/InsufficientStockException.java @@ -0,0 +1,11 @@ +package com.ramsai.kitchen.exceptions; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class InsufficientStockException extends RuntimeException { + public InsufficientStockException(String message) { + super(message); + } +} diff --git a/src/main/java/com/ramsai/kitchen/models/dtos/OrderItemResponse.java b/src/main/java/com/ramsai/kitchen/models/dtos/OrderItemResponse.java new file mode 100644 index 0000000..453a02d --- /dev/null +++ b/src/main/java/com/ramsai/kitchen/models/dtos/OrderItemResponse.java @@ -0,0 +1,15 @@ +package com.ramsai.kitchen.models.dtos; + +import com.ramsai.kitchen.enums.ItemStatus; +import java.math.BigDecimal; + +public record OrderItemResponse( + Long id, + Long orderId, + Long productId, + String productName, + Integer quantity, + BigDecimal unitPrice, + String specialNotes, + ItemStatus itemStatus +) {} diff --git a/src/main/java/com/ramsai/kitchen/models/dtos/ProductPopularityResponse.java b/src/main/java/com/ramsai/kitchen/models/dtos/ProductPopularityResponse.java new file mode 100644 index 0000000..35bdc75 --- /dev/null +++ b/src/main/java/com/ramsai/kitchen/models/dtos/ProductPopularityResponse.java @@ -0,0 +1,8 @@ +package com.ramsai.kitchen.models.dtos; + +public record ProductPopularityResponse( + Long id, + String name, + Long totalQuantitySold, + String categoryName +) {} diff --git a/src/main/java/com/ramsai/kitchen/models/dtos/TableResponse.java b/src/main/java/com/ramsai/kitchen/models/dtos/TableResponse.java new file mode 100644 index 0000000..1751801 --- /dev/null +++ b/src/main/java/com/ramsai/kitchen/models/dtos/TableResponse.java @@ -0,0 +1,13 @@ +package com.ramsai.kitchen.models.dtos; + +import com.ramsai.kitchen.enums.TableStatus; +import java.time.LocalDateTime; + +public record TableResponse( + Long id, + Integer tableNumber, + TableStatus status, + Integer xPos, + Integer yPos, + LocalDateTime lastOrderTime +) {} diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html new file mode 100644 index 0000000..eb76c43 --- /dev/null +++ b/src/main/resources/static/index.html @@ -0,0 +1,40 @@ + + + + + + Ramsai Kitchen + + + +
+

Welcome to Ramsai Kitchen

+

Hello World! Your Spring Boot application is running in Docker. + MODIFICARE MODIFICARE

+
+ +