8 Commits

58 changed files with 2577 additions and 2429 deletions

31
.idea/dataSources.xml generated Normal file
View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="r710" uuid="e6a29f5c-71d9-45f0-931b-554bcf8a94ba">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://r710.dev.gofwd.group:5433/postgres</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
<property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
<data-source source="LOCAL" name="ss_builder@r710.gofwd.group" uuid="e0fa459b-2f6c-45f1-9c41-66423c870df9">
<driver-ref>postgresql</driver-ref>
<synchronize>true</synchronize>
<imported>true</imported>
<remarks>$PROJECT_DIR$/src/main/resources/application.properties</remarks>
<jdbc-driver>org.postgresql.Driver</jdbc-driver>
<jdbc-url>jdbc:postgresql://r710.gofwd.group:5433/ss_builder</jdbc-url>
<jdbc-additional-properties>
<property name="com.intellij.clouds.kubernetes.db.host.port" />
<property name="com.intellij.clouds.kubernetes.db.enabled" value="false" />
<property name="com.intellij.clouds.kubernetes.db.container.port" />
</jdbc-additional-properties>
<working-dir>$ProjectFileDir$</working-dir>
</data-source>
</component>
</project>

34
docker/backend/Dockerfile Normal file
View File

@@ -0,0 +1,34 @@
# Stage 1: Build the application (The Build Stage)
# Use a Java SDK image with Maven pre-installed
FROM maven:3.9-jdk-17-slim AS build
# Set the working directory inside the container
WORKDIR /app
# Copy the Maven project files (pom.xml) first to leverage Docker layer caching
COPY pom.xml .
# Copy the source code
COPY src ./src
# Build the Spring Boot application, skipping tests to speed up the Docker build
# This creates the executable JAR file in the 'target' directory
RUN mvn clean package -DskipTests
# Stage 2: Create the final lightweight image (The Runtime Stage)
# Use a smaller Java Runtime Environment (JRE) image for a smaller footprint
FROM openjdk:17-jre-slim
# Set the working directory in the final image
WORKDIR /app
# Copy the built JAR file from the 'build' stage into the final image
# The JAR file is typically named 'target/<your-app-name>-<version>.jar'
# You may need to adjust the name if you have a non-standard pom.xml
COPY --from=build /app/target/*.jar app.jar
# Expose the default Spring Boot port
EXPOSE 8080
# Define the command to run the application
ENTRYPOINT ["java", "-jar", "app.jar"]

View File

@@ -1,17 +0,0 @@
# Stage 1: Build the application
FROM openjdk:17-jdk-slim as build
WORKDIR /app
COPY gradlew .
COPY settings.gradle .
COPY build.gradle .
COPY src ./src
# Adjust the build command for Maven: ./mvnw package -DskipTests
RUN ./gradlew bootJar
# Stage 2: Create the final lightweight image
FROM openjdk:17-jre-slim
WORKDIR /app
# Get the built JAR from the build stage
COPY --from=build /app/build/libs/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]

View File

@@ -2,20 +2,18 @@ version: '3.8'
services: services:
# --- 1. Spring API Service (Backend) --- # --- 1. Spring API Service (Backend) ---
spring-api: ss_builder-api:
build: build:
context: ./backend # Path to your Spring project's root folder context: ./backend # Path to your Spring project's root folder
dockerfile: Dockerfile # Assumes you have a Dockerfile in ./backend dockerfile: Dockerfile # Assumes you have a Dockerfile in ./backend
container_name: spring-api container_name: ss_builder-api
ports: ports:
- "8080:8080" # Map host port 8080 to container port 8080 - "8080:8080" # Map host port 8080 to container port 8080
environment: environment:
# These environment variables link the API to the database service defined below # These environment variables link the API to the database service defined below
- SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/mydatabase - SPRING_DATASOURCE_URL=jdbc:postgresql://r710.dev.gofwd.group:5433/ss_builder
- SPRING_DATASOURCE_USERNAME=myuser - SPRING_DATASOURCE_USERNAME=dba
- SPRING_DATASOURCE_PASSWORD=mypassword - SPRING_DATASOURCE_PASSWORD=!@#Qwerty
depends_on:
- db
networks: networks:
- app-network - app-network
@@ -24,38 +22,20 @@ services:
build: build:
context: ./frontend # Path to your Next.js project's root folder context: ./frontend # Path to your Next.js project's root folder
dockerfile: Dockerfile # Assumes you have a Dockerfile in ./frontend dockerfile: Dockerfile # Assumes you have a Dockerfile in ./frontend
container_name: nextjs-app container_name: ss_builder-app
ports: ports:
- "3000:3000" # Map host port 3000 to container port 3000 - "3000:3000" # Map host port 3000 to container port 3000
environment: environment:
# This variable is crucial: Next.js needs the URL for the Spring API # This variable is crucial: Next.js needs the URL for the Spring API
# Use the Docker internal service name 'spring-api' and its port 8080 # Use the Docker internal service name 'spring-api' and its port 8080
- NEXT_PUBLIC_API_URL=http://spring-api:8080 - NEXT_PUBLIC_API_URL=http://ss_builder-api:8080
# For local testing, you might need the host IP for Next.js to call back # For local testing, you might need the host IP for Next.js to call back
# - NEXT_PUBLIC_API_URL_LOCAL=http://localhost:8080 # - NEXT_PUBLIC_API_URL_LOCAL=http://localhost:8080
depends_on: depends_on:
- spring-api - ss_builder-api
networks: networks:
- app-network - app-network
# --- 3. PostgreSQL Database Service (Example Dependency) ---
db:
image: postgres:15-alpine # Lightweight and stable PostgreSQL image
container_name: postgres-db
environment:
- POSTGRES_DB=mydatabase
- POSTGRES_USER=myuser
- POSTGRES_PASSWORD=mypassword
volumes:
- postgres_data:/var/lib/postgresql/data # Persist the database data
ports:
- "5432:5432" # Optional: Map DB port for external access (e.g., DBeaver)
networks:
- app-network
# --- Docker Volume for Persistent Data ---
volumes:
postgres_data:
# --- Docker Network for Inter-Container Communication --- # --- Docker Network for Inter-Container Communication ---
networks: networks:

View File

@@ -30,13 +30,8 @@ public class CorsConfig {
"https://localhost:8080", "https://localhost:8080",
"http://localhost:3000", "http://localhost:3000",
"https://localhost:3000", "https://localhost:3000",
"http://192.168.11.210:8070", "https://localhost:3000/gunbuilder",
"https://192.168.11.210:8070", "http://localhost:3000/gunbuilder"
"http://citysites.gofwd.group",
"https://citysites.gofwd.group",
"http://citysites.gofwd.group:8070",
"https://citysites.gofwd.group:8070"
)); ));
// Allow all headers // Allow all headers

View File

@@ -0,0 +1,51 @@
package group.goforward.ballistic.controllers;
import group.goforward.ballistic.model.Brand;
import group.goforward.ballistic.model.State;
import group.goforward.ballistic.repos.BrandRepository;
import group.goforward.ballistic.services.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/brands")
public class BrandController {
@Autowired
private BrandRepository repo;
@Autowired
private BrandService brandService;
//@Cacheable(value="getAllStates")
@GetMapping("/all")
public ResponseEntity<List<Brand>> getAllBrands() {
List<Brand> brand = repo.findAll();
return ResponseEntity.ok(brand);
}
@GetMapping("/{id}")
public ResponseEntity<Brand> getAllBrandsById(@PathVariable Integer id) {
return repo.findById(id)
.map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build());
}
@PostMapping("/add")
public ResponseEntity<Brand> createbrand(@RequestBody Brand item) {
Brand created = brandService.save(item);
return ResponseEntity.status(HttpStatus.CREATED).body(created);
}
@DeleteMapping("/delete/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
return brandService.findById(id)
.map(item -> {
brandService.deleteById(id);
return ResponseEntity.noContent().<Void>build();
})
.orElse(ResponseEntity.notFound().build());
}
}

View File

@@ -5,6 +5,7 @@ import group.goforward.ballistic.model.State;
import group.goforward.ballistic.repos.StateRepository; import group.goforward.ballistic.repos.StateRepository;
import group.goforward.ballistic.services.StatesService; import group.goforward.ballistic.services.StatesService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -13,44 +14,38 @@ import java.util.List;
@RestController @RestController
@RequestMapping() @RequestMapping("/api/states")
public class StateController { public class StateController {
@Autowired @Autowired
private StateRepository repo; private StateRepository repo;
@Autowired @Autowired
private StatesService statesService; private StatesService statesService;
//@Cacheable(value="getAllStates")
@GetMapping("/api/getAllStates") @GetMapping("/all")
public ResponseEntity<List<State>> getAllStates() { public ResponseEntity<List<State>> getAllStates() {
List<State> state = repo.findAll(); List<State> state = repo.findAll();
return ResponseEntity.ok(state); return ResponseEntity.ok(state);
} }
@GetMapping("/api/getAllStatesTest") @GetMapping("/{id}")
public ApiResponse<List<State>> getAllStatesTest() {
List<State> state = repo.findAll();
return ApiResponse.success(state);
}
@GetMapping("/api/getAllStatesById/{id}")
public ResponseEntity<State> getAllStatesById(@PathVariable Integer id) { public ResponseEntity<State> getAllStatesById(@PathVariable Integer id) {
return repo.findById(id) return repo.findById(id)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@GetMapping("/api/getAllStatesByAbbreviation/{abbreviation}") @GetMapping("/byAbbrev/{abbreviation}")
public ResponseEntity<State> getAllStatesByAbbreviation(@PathVariable String abbreviation) { public ResponseEntity<State> getAllStatesByAbbreviation(@PathVariable String abbreviation) {
return repo.findByAbbreviation(abbreviation) return repo.findByAbbreviation(abbreviation)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@PostMapping("/api/addState") @PostMapping("/addState")
public ResponseEntity<State> createState(@RequestBody State item) { public ResponseEntity<State> createState(@RequestBody State item) {
State created = statesService.save(item); State created = statesService.save(item);
return ResponseEntity.status(HttpStatus.CREATED).body(created); return ResponseEntity.status(HttpStatus.CREATED).body(created);
} }
@DeleteMapping("/api/deleteState/{id}") @DeleteMapping("/deleteState/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) { public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
return statesService.findById(id) return statesService.findById(id)
.map(item -> { .map(item -> {

View File

@@ -12,33 +12,36 @@ import java.util.List;
@RestController @RestController
@RequestMapping() @RequestMapping("/api/user")
public class UserController { public class UserController {
@Autowired private final UserRepository repo;
private UserRepository repo; private final UsersService usersService;
@Autowired
private UsersService usersService;
@GetMapping("/api/getAllUsers") public UserController(UserRepository repo, UsersService usersService) {
this.repo = repo;
this.usersService = usersService;
}
@GetMapping("/all")
public ResponseEntity<List<User>> getAllUsers() { public ResponseEntity<List<User>> getAllUsers() {
List<User> data = repo.findAll(); List<User> data = repo.findAll();
return ResponseEntity.ok(data); return ResponseEntity.ok(data);
} }
@GetMapping("/api/getAllUsersById/{id}") @GetMapping("/byId/{id}")
public ResponseEntity<User> getAllStatesById(@PathVariable Integer id) { public ResponseEntity<User> getAllStatesById(@PathVariable Integer id) {
return repo.findById(id) return repo.findById(id)
.map(ResponseEntity::ok) .map(ResponseEntity::ok)
.orElse(ResponseEntity.notFound().build()); .orElse(ResponseEntity.notFound().build());
} }
@PostMapping("/api/addUser") @PostMapping("/addUser")
public ResponseEntity<User> createUser(@RequestBody User item) { public ResponseEntity<User> createUser(@RequestBody User item) {
User created = usersService.save(item); User created = usersService.save(item);
return ResponseEntity.status(HttpStatus.CREATED).body(created); return ResponseEntity.status(HttpStatus.CREATED).body(created);
} }
@DeleteMapping("/api/deleteUser/{id}") @DeleteMapping("/deleteUser/{id}")
public ResponseEntity<Void> deleteItem(@PathVariable Integer id) { public ResponseEntity<Void> deleteItem(@PathVariable Integer id) {
return usersService.findById(id) return usersService.findById(id)
.map(item -> { .map(item -> {

View File

@@ -14,6 +14,25 @@ import group.goforward.ballistic.model.ProductConfiguration;
@Entity @Entity
@Table(name = "products") @Table(name = "products")
@NamedQuery(name="Products.findByPlatformWithBrand", query= "" +
"SELECT p FROM Product p" +
" JOIN FETCH p.brand b" +
" WHERE p.platform = :platform" +
" AND p.deletedAt IS NULL")
@NamedQuery(name="Product.findByPlatformAndPartRoleInWithBrand", query= "" +
"SELECT p FROM Product p JOIN FETCH p.brand b" +
" WHERE p.platform = :platform" +
" AND p.partRole IN :roles" +
" AND p.deletedAt IS NULL")
@NamedQuery(name="Product.findProductsbyBrandByOffers", query="" +
" SELECT DISTINCT p FROM Product p" +
" LEFT JOIN FETCH p.brand b" +
" LEFT JOIN FETCH p.offers o" +
" WHERE p.platform = :platform" +
" AND p.deletedAt IS NULL")
public class Product { public class Product {
@Id @Id

View File

@@ -33,6 +33,9 @@ public interface ProductRepository extends JpaRepository<Product, Integer> {
""") """)
List<Product> findByPlatformWithBrand(@Param("platform") String platform); List<Product> findByPlatformWithBrand(@Param("platform") String platform);
@Query(name="Products.findByPlatformWithBrand")
List<Product> findByPlatformWithBrandNQ(@Param("platform") String platform);
@Query(""" @Query("""
SELECT p SELECT p
FROM Product p FROM Product p

View File

@@ -0,0 +1,16 @@
package group.goforward.ballistic.services;
import group.goforward.ballistic.model.Brand;
import java.util.List;
import java.util.Optional;
public interface BrandService {
List<Brand> findAll();
Optional<Brand> findById(Integer id);
Brand save(Brand item);
void deleteById(Integer id);
}

View File

@@ -0,0 +1,38 @@
package group.goforward.ballistic.services.impl;
import group.goforward.ballistic.model.Brand;
import group.goforward.ballistic.repos.BrandRepository;
import group.goforward.ballistic.services.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;
@Service
public class BrandServiceImpl implements BrandService {
@Autowired
private BrandRepository repo;
@Override
public List<Brand> findAll() {
return repo.findAll();
}
@Override
public Optional<Brand> findById(Integer id) {
return repo.findById(id);
}
@Override
public Brand save(Brand item) {
return null;
}
@Override
public void deleteById(Integer id) {
deleteById(id);
}
}

0
wget-log Normal file
View File