set various files including 'Settings Window' and light & dark themes in CSS, rename BrickLogClient : BrickLogClientApplication

This commit is contained in:
bryce
2024-10-28 11:53:08 +13:00
parent 83eb995d69
commit 5b618916b1
28 changed files with 328 additions and 9 deletions

View File

@@ -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.");
};
}
}

View File

@@ -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 doesnt 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);
}
}
}

View File

@@ -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;
}
}