set various files including 'Settings Window' and light & dark themes in CSS, rename BrickLogClient : BrickLogClientApplication
This commit is contained in:
@@ -1,9 +1,14 @@
|
||||
package com.example.bricklog;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
|
||||
|
||||
import com.example.bricklog.model.LegoBuild;
|
||||
import com.example.bricklog.repository.LegoBuildRepository;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableJpaRepositories(basePackages = "com.example.bricklog.repository") // Adjust if needed
|
||||
public class BrickLogApplication {
|
||||
@@ -12,4 +17,14 @@ public class BrickLogApplication {
|
||||
SpringApplication.run(BrickLogApplication.class, args);
|
||||
System.out.println("BrickLog Server is running...");
|
||||
}
|
||||
|
||||
// Example CommandLineRunner to load initial data into the database
|
||||
@Bean
|
||||
public CommandLineRunner initDatabase(LegoBuildRepository repository) {
|
||||
return args -> {
|
||||
repository.save(new LegoBuild("Castle", "John Doe", true, "A magnificent medieval castle"));
|
||||
repository.save(new LegoBuild("Spaceship", "Jane Smith", false, "A futuristic spacecraft model"));
|
||||
System.out.println("Database initialized with sample data.");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,63 @@
|
||||
package com.example.bricklog.controller;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.example.bricklog.model.LegoBuild;
|
||||
import com.example.bricklog.repository.LegoBuildRepository;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/builds")
|
||||
public class LegoBuildController {
|
||||
|
||||
private static final String IMAGE_DIRECTORY = "uploads/images/";
|
||||
|
||||
@Autowired
|
||||
private LegoBuildRepository legoBuildRepository;
|
||||
|
||||
@PostMapping("/add")
|
||||
public ResponseEntity<?> addLegoBuild(
|
||||
@RequestParam("name") String name,
|
||||
@RequestParam("builder") String builder,
|
||||
@RequestParam("isKitset") boolean isKitset,
|
||||
@RequestParam("description") String description,
|
||||
@RequestParam("image") MultipartFile image) {
|
||||
|
||||
// Save the image file
|
||||
String filePath = saveImageFile(image);
|
||||
|
||||
// Save the LegoBuild with image path
|
||||
LegoBuild legoBuild = new LegoBuild(name, builder, isKitset, description);
|
||||
legoBuild.setImagePath(filePath);
|
||||
legoBuildRepository.save(legoBuild);
|
||||
|
||||
return new ResponseEntity<>("Build added successfully with image.", HttpStatus.OK);
|
||||
}
|
||||
|
||||
private String saveImageFile(MultipartFile image) {
|
||||
try {
|
||||
Path directoryPath = Paths.get(IMAGE_DIRECTORY);
|
||||
if (!Files.exists(directoryPath)) {
|
||||
Files.createDirectories(directoryPath); // Create directory if it doesn’t exist
|
||||
}
|
||||
String filePath = IMAGE_DIRECTORY + image.getOriginalFilename();
|
||||
File file = new File(filePath);
|
||||
image.transferTo(file); // Save the image
|
||||
return filePath;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Failed to store image file", e);
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,6 +16,7 @@ public class LegoBuild {
|
||||
private String builder;
|
||||
private boolean isKitset; // true for Kitset, false for MoC
|
||||
private String description;
|
||||
private String imagePath;
|
||||
|
||||
public LegoBuild() {}
|
||||
|
||||
@@ -67,4 +68,12 @@ public class LegoBuild {
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getImagePath() {
|
||||
return imagePath;
|
||||
}
|
||||
|
||||
public void setImagePath(String imagePath) {
|
||||
this.imagePath = imagePath;
|
||||
}
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,9 @@
|
||||
# MariaDB Configuration
|
||||
spring.datasource.url=jdbc:mariadb://localhost:3306/bricklog_db
|
||||
spring.datasource.username=your_db_username
|
||||
spring.datasource.password=your_db_password
|
||||
|
||||
# JPA settings
|
||||
spring.jpa.hibernate.ddl-auto=update # Creates tables automatically; set to 'none' in production if not needed
|
||||
spring.jpa.show-sql=true # Shows SQL queries in the console, useful for debugging
|
||||
spring.jpa.database-platform=org.hibernate.dialect.MariaDBDialect
|
Reference in New Issue
Block a user