This repository has been archived on 2020-08-02. You can view files and clone it, but cannot push or open issues or pull requests.
e-commerce/prototype/src/main/java/org/hso/ecommerce/controller/intern/InternArticleController.java

130 lines
3.5 KiB
Java
Raw Normal View History

2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern;
2020-04-28 22:41:29 +02:00
2020-05-10 15:26:50 +02:00
import java.util.ArrayList;
import java.util.List;
import org.hso.ecommerce.entities.shop.Article;
import org.hso.ecommerce.repos.shop.ArticleRepository;
2020-05-10 15:26:50 +02:00
import org.hso.ecommerce.repos.warehouse.WarehouseBookingPositionSlotEntryRepository;
import org.springframework.beans.factory.annotation.Autowired;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
2020-05-10 15:26:50 +02:00
@Controller
@RequestMapping("intern/articles")
2020-05-11 11:58:26 +02:00
public class InternArticleController {
2020-05-10 15:26:50 +02:00
@Autowired
private final ArticleRepository articleRepository = null;
2020-05-10 15:26:50 +02:00
@Autowired
private final WarehouseBookingPositionSlotEntryRepository warehouseEntryRepository = null;
2020-05-10 15:26:50 +02:00
@GetMapping("/")
2020-05-11 11:58:26 +02:00
public String internListedArticles(Model model) {
2020-05-10 15:26:50 +02:00
List<ListedArticlesListTotals> totals = new ArrayList<ListedArticlesListTotals>();
for (Article article : articleRepository.findAll()) {
ListedArticlesListTotals tmp = new ListedArticlesListTotals();
2020-05-11 11:58:26 +02:00
tmp.addListedArticle(article, warehouseEntryRepository.getArticleStock(article.id).orElse(0));
2020-05-10 15:26:50 +02:00
totals.add(tmp);
}
model.addAttribute("ListedArticles", totals);
return "intern/listedArticles/index";
}
@GetMapping("/{id}")
2020-05-11 11:58:26 +02:00
public String internListedArticlesId(Model model, @PathVariable String id) {
int articleid = Integer.parseInt(id);
ListedArticlesListIdTotal total = new ListedArticlesListIdTotal();
total.addArticle(articleRepository.findArticleById(articleid),
warehouseEntryRepository.getArticleStock(articleid).orElse(0));
model.addAttribute("ArticleID", total);
2020-05-10 15:26:50 +02:00
return "intern/listedArticles/id";
}
@PostMapping("/{id}/saveChanges")
public RedirectView saveChanges() {
System.out.println("\n------ POST -----\n");
return new RedirectView("../");
}
2020-05-10 15:26:50 +02:00
2020-05-11 11:58:26 +02:00
public static class ListedArticlesListTotals {
2020-05-10 15:26:50 +02:00
public String imgPath;
public String title;
public String price;
public String price_netto;
public String categorie;
public int stock;
public long offer_id;
public long id;
2020-05-11 11:58:26 +02:00
void addListedArticle(Article article, int stock) {
this.imgPath = article.image.path;
this.title = article.title;
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
this.categorie = article.getCategories();
this.stock = stock;
this.offer_id = article.related.id;
this.id = article.id;
}
}
public static class ListedArticlesListIdTotal {
public String imgPath;
public String title;
public String price;
public String price_netto;
public int reorderMaxPrice;
public String categorie;
public int stock;
public long offer_id;
public long id;
public boolean shouldReorder;
public int warehouseUnitsPerSlot;
public String description;
void addArticle(Article article, int stock) {
2020-05-10 15:26:50 +02:00
this.imgPath = article.image.path;
this.title = article.title;
2020-05-11 11:58:26 +02:00
this.price_netto = String.format("%.2f", ((float) article.shopPricePerUnitNetCent / 100));
this.price = String.format("%.2f", ((float) article.getPriceGross() / 100));
2020-05-10 15:26:50 +02:00
this.categorie = article.getCategories();
this.stock = stock;
this.offer_id = article.related.id;
this.id = article.id;
2020-05-11 11:58:26 +02:00
this.reorderMaxPrice = article.reorderMaxPrice;
this.shouldReorder = article.shouldReorder;
this.warehouseUnitsPerSlot = article.warehouseUnitsPerSlot;
this.description = article.description;
2020-05-10 15:26:50 +02:00
}
}
2020-04-28 22:41:29 +02:00
}