Connect FS user page
This commit is contained in:
@@ -37,6 +37,7 @@ public class ControllerPathConfig {
|
||||
//FarmImageController
|
||||
public static final String FARM_IMAGE_BASE = "/farm";
|
||||
public static final String FARM_IMAGE_DEFAULT = FARM_IMAGE_BASE + "/default";
|
||||
public static final String FARM_IMAGE_ARTICLES = FARM_IMAGE_BASE + "/articles";
|
||||
|
||||
//OrderController
|
||||
public static final String ORDER_BASE = "/order";
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package de.htwsaar.webshop.controller;
|
||||
|
||||
import de.htwsaar.webshop.model.ArticleWithFarmImageModel;
|
||||
import de.htwsaar.webshop.model.FarmImageModel;
|
||||
import de.htwsaar.webshop.repository.entities.FarmImage;
|
||||
import de.htwsaar.webshop.service.ArticleService;
|
||||
@@ -11,10 +12,10 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static de.htwsaar.webshop.config.ControllerPathConfig.FARM_IMAGE_BASE;
|
||||
import static de.htwsaar.webshop.config.ControllerPathConfig.FARM_IMAGE_DEFAULT;
|
||||
import static de.htwsaar.webshop.config.ControllerPathConfig.*;
|
||||
import static de.htwsaar.webshop.config.ParameterConfig.*;
|
||||
import static de.htwsaar.webshop.util.LoggerUtil.logRequest;
|
||||
|
||||
@@ -95,4 +96,11 @@ public class FarmImageController {
|
||||
farmImageService.deleteById(imageId);
|
||||
return ResponseEntity.ok().build();
|
||||
}
|
||||
|
||||
@RequestMapping(path = FARM_IMAGE_ARTICLES, method = RequestMethod.DELETE, produces = "application/json")
|
||||
public ResponseEntity<List<ArticleWithFarmImageModel>> getFSArticles(HttpServletRequest request) {
|
||||
logRequest(request);
|
||||
return ResponseEntity.ok(farmImageService.getArticles());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
package de.htwsaar.webshop.model;
|
||||
|
||||
import de.htwsaar.webshop.repository.entities.Article;
|
||||
import de.htwsaar.webshop.repository.entities.FarmImage;
|
||||
import de.htwsaar.webshop.repository.entities.Image;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* What the Frontend gets when requesting an Article, POJO
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Setter
|
||||
@Getter
|
||||
public class ArticleWithFarmImageModel {
|
||||
private long id;
|
||||
private UUID uuid;
|
||||
private String name;
|
||||
private String description;
|
||||
private int price100;
|
||||
private int discount100;
|
||||
private int stock;
|
||||
private int stockExpected;
|
||||
private String category;
|
||||
private double rating;
|
||||
private String image;
|
||||
private String farmImage;
|
||||
|
||||
public ArticleWithFarmImageModel(ArticleModel article, Image image, FarmImage farmImage) {
|
||||
this.id = article.getId();
|
||||
this.uuid = article.getUuid();
|
||||
this.name = article.getName();
|
||||
this.description = article.getDescription();
|
||||
this.price100 = article.getPrice100();
|
||||
this.discount100 = article.getDiscount100();
|
||||
this.stock = article.getStock();
|
||||
this.stockExpected = article.getStockExpected();
|
||||
this.category = article.getCategory();
|
||||
this.rating = article.getRating();
|
||||
this.image = image.getBase64();
|
||||
this.farmImage = farmImage.getBase64();
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package de.htwsaar.webshop.service;
|
||||
|
||||
import de.htwsaar.webshop.model.ArticleWithFarmImageModel;
|
||||
import de.htwsaar.webshop.model.FarmImageModel;
|
||||
import de.htwsaar.webshop.repository.entities.FarmImage;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public interface FarmImageService {
|
||||
@@ -20,4 +22,6 @@ public interface FarmImageService {
|
||||
FarmImage save(UUID uuid, String base64, boolean standard);
|
||||
|
||||
void deleteById(Long imageId);
|
||||
|
||||
List<ArticleWithFarmImageModel> getArticles();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package de.htwsaar.webshop.service.impl;
|
||||
|
||||
import de.htwsaar.webshop.model.ArticleWithFarmImageModel;
|
||||
import de.htwsaar.webshop.model.FarmImageModel;
|
||||
import de.htwsaar.webshop.repository.FarmImageRepository;
|
||||
import de.htwsaar.webshop.repository.entities.Article;
|
||||
import de.htwsaar.webshop.repository.entities.FarmImage;
|
||||
import de.htwsaar.webshop.service.ArticleService;
|
||||
import de.htwsaar.webshop.service.FarmImageService;
|
||||
import de.htwsaar.webshop.service.ImageService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -13,6 +15,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.Base64;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
@@ -21,11 +24,13 @@ import java.util.UUID;
|
||||
public class FarmImageServiceImpl implements FarmImageService {
|
||||
private final FarmImageRepository farmImageRepository;
|
||||
private final ArticleService articleService;
|
||||
private final ImageService imageService;
|
||||
|
||||
@Autowired
|
||||
public FarmImageServiceImpl(FarmImageRepository imageRepository, ArticleService articleService) {
|
||||
public FarmImageServiceImpl(FarmImageRepository imageRepository, ArticleService articleService, ImageService imageService) {
|
||||
this.farmImageRepository = imageRepository;
|
||||
this.articleService = articleService;
|
||||
this.imageService = imageService;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,4 +83,15 @@ public class FarmImageServiceImpl implements FarmImageService {
|
||||
public void deleteById(Long imageId) {
|
||||
farmImageRepository.deleteById(imageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ArticleWithFarmImageModel> getArticles() {
|
||||
return farmImageRepository.findAll().stream()
|
||||
.map(fi -> new ArticleWithFarmImageModel(
|
||||
articleService.from(fi.getArticle()),
|
||||
imageService.getImageByUUID(fi.getArticle().getUuid()),
|
||||
fi
|
||||
))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,4 +25,19 @@ type ItemWithImage = {
|
||||
image: string;
|
||||
};
|
||||
|
||||
export type ItemWithFSImage = {
|
||||
id: number;
|
||||
uuid: string;
|
||||
name: string;
|
||||
description: string;
|
||||
price100: number;
|
||||
stock: number;
|
||||
stockExpected: number;
|
||||
category: string;
|
||||
rating: number;
|
||||
discount100: number;
|
||||
image: string;
|
||||
farmImage: string;
|
||||
};
|
||||
|
||||
export default ItemWithImage;
|
||||
@@ -7,20 +7,11 @@ import ItemCard from "../helper/homepage/ItemCard";
|
||||
import AddShoppingCartIcon from '@mui/icons-material/AddShoppingCart';
|
||||
|
||||
import farmingStation from '../assets/fscomponents/fs_components_0.png';
|
||||
import environment from '../assets/fscomponents/fs_components_1.png';
|
||||
import hoses from '../assets/fscomponents/fs_components_2.png';
|
||||
import pipes from '../assets/fscomponents/fs_components_3.png';
|
||||
import pumps from '../assets/fscomponents/fs_components_4.png';
|
||||
import sensors from '../assets/fscomponents/fs_components_5.png';
|
||||
import shelf from '../assets/fscomponents/fs_components_6.png';
|
||||
import connectors from '../assets/fscomponents/fs_components_7.png';
|
||||
import clips from '../assets/fscomponents/fs_components_8.png';
|
||||
import arduino from '../assets/fscomponents/fs_components_9.png';
|
||||
import Item from "../components/Item";
|
||||
import { ItemWithFSImage } from "../components/Item"; "../components/Item";
|
||||
|
||||
// API-Funktion, Items laden (URL anpassen!)
|
||||
async function fetchItemList(): Promise<Item[]> {
|
||||
const response = await fetch('/api/items');
|
||||
async function fetchFarmingStationItemList(): Promise<ItemWithFSImage[]> {
|
||||
const response = await fetch('/farm/articles');
|
||||
if (!response.ok) throw new Error('Failed to fetch items');
|
||||
return response.json();
|
||||
}
|
||||
@@ -35,37 +26,20 @@ export default function FSComponents() {
|
||||
const wantedIds = ["60", "67", "68", "69", "70", "71", "72", "73", "74", "75"];
|
||||
|
||||
// Daten mit react-query laden
|
||||
const { data = [], isLoading, error } = useQuery<Item[]>({
|
||||
queryKey: ['fetchItemList'],
|
||||
queryFn: fetchItemList,
|
||||
const { data = [], isLoading, error } = useQuery<ItemWithFSImage[]>({
|
||||
queryKey: ['fetchFarmingStationItemList'],
|
||||
queryFn: fetchFarmingStationItemList,
|
||||
retry: 3,
|
||||
retryDelay: 1000,
|
||||
});
|
||||
|
||||
// Filter auf wantedIds
|
||||
const filteredItems = data.filter(item => wantedIds.includes(item.id));
|
||||
|
||||
// Button-Funktion: alle gefilterten Items in den Warenkorb packen
|
||||
const handleAddAllToCart = () => {
|
||||
filteredItems.forEach(item => {
|
||||
data.forEach(item => {
|
||||
addToBasket(item, 1);
|
||||
});
|
||||
};
|
||||
|
||||
// Zuordnung Bilder (Annahme: 9 Bilder für 9 Items)
|
||||
const componentImages = [
|
||||
arduino,
|
||||
farmingStation,
|
||||
environment,
|
||||
pipes,
|
||||
pumps,
|
||||
sensors,
|
||||
shelf,
|
||||
hoses,
|
||||
connectors,
|
||||
clips,
|
||||
];
|
||||
|
||||
if (isLoading) return <Typography>{t('loading')}</Typography>;
|
||||
if (error) return <Typography color="error">{t('errorLoadingItems')}</Typography>;
|
||||
|
||||
@@ -85,7 +59,7 @@ export default function FSComponents() {
|
||||
}}>
|
||||
<Box
|
||||
component="img"
|
||||
src={hoverIndex !== null ? componentImages[hoverIndex] : farmingStation}
|
||||
src={hoverIndex !== null ? data[hoverIndex].farmImage : farmingStation}
|
||||
alt={t('componentsFarmingStation')}
|
||||
sx={{
|
||||
width: '100%',
|
||||
@@ -120,7 +94,7 @@ export default function FSComponents() {
|
||||
</Typography>
|
||||
</Box>
|
||||
<Box className="cardgrid">
|
||||
{filteredItems.map((item, index) => (
|
||||
{data.map((item, index) => (
|
||||
<div
|
||||
key={item.id}
|
||||
onMouseEnter={() => setHoverIndex(index)}
|
||||
|
||||
Reference in New Issue
Block a user