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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user