2020-04-29 22:44:16 +02:00
package org.hso.ecommerce.controller.intern.suppliers ;
2020-04-28 22:41:29 +02:00
2020-05-16 22:48:20 +02:00
import java.util.ArrayList ;
import java.util.List ;
2020-05-19 16:30:27 +02:00
import java.util.Optional ;
2020-05-16 22:48:20 +02:00
2020-05-19 00:12:26 +02:00
import org.hso.ecommerce.entities.supplier.ArticleOffer ;
2020-05-19 16:30:27 +02:00
import org.hso.ecommerce.repos.shop.ArticleRepository ;
2020-05-19 00:12:26 +02:00
import org.hso.ecommerce.repos.shop.OffersRepository ;
import org.springframework.beans.factory.annotation.Autowired ;
2020-04-28 22:41:29 +02:00
import org.springframework.stereotype.Controller ;
2020-05-15 11:57:20 +02:00
import org.springframework.ui.Model ;
import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.RequestMapping ;
2020-04-28 22:41:29 +02:00
@Controller
2020-05-15 14:14:29 +02:00
@RequestMapping ( " /intern/ " )
2020-05-01 10:48:12 +02:00
public class SupplierOfferController {
2020-05-15 14:14:29 +02:00
2020-05-19 00:12:26 +02:00
@Autowired
private final OffersRepository offersRepository = null ;
2020-05-19 16:30:27 +02:00
@Autowired
private final ArticleRepository articleRepository = null ;
2020-05-15 20:57:56 +02:00
@GetMapping ( " supplierOffers " )
public String internListedArticles ( Model model ) {
2020-05-15 14:14:29 +02:00
2020-06-01 17:10:04 +02:00
List < UImodelOfferedArticle > totals = new ArrayList < > ( ) ;
2020-05-16 22:48:20 +02:00
2020-05-19 00:12:26 +02:00
for ( ArticleOffer article : offersRepository . findAll ( ) ) {
UImodelOfferedArticle tmp = new UImodelOfferedArticle ( ) ;
2020-05-30 12:29:40 +02:00
tmp . addData ( article , articleRepository . findArticleIDByRelatedID ( article . id ) ) ;
2020-05-19 00:12:26 +02:00
totals . add ( tmp ) ;
}
2020-05-16 22:48:20 +02:00
model . addAttribute ( " OfferedArticles " , totals ) ;
2020-05-15 11:57:20 +02:00
return " intern/offeredArticles/index " ;
2020-05-16 22:48:20 +02:00
}
public class UImodelOfferedArticle {
2020-05-30 11:52:30 +02:00
long offer_id ;
2020-05-16 22:48:20 +02:00
String title ;
String manufacturer ;
String articlenumber ;
String supplierName ;
String price ;
String ads ;
int listedArticleId ;
2020-05-30 11:52:30 +02:00
boolean offerIsListed ; // true --> offered article is listed
2020-05-19 16:30:27 +02:00
public long getOffer_id ( ) {
return offer_id ;
}
public void setOffer_id ( long offer_id ) {
this . offer_id = offer_id ;
}
2020-05-30 11:52:30 +02:00
2020-05-19 16:30:27 +02:00
public boolean isOfferIsListed ( ) {
return offerIsListed ;
}
public void setOfferIsListed ( boolean offerIsListed ) {
this . offerIsListed = offerIsListed ;
}
2020-05-16 22:48:20 +02:00
public String getTitle ( ) {
return title ;
}
public void setTitle ( String title ) {
this . title = title ;
}
public String getManufacturer ( ) {
return manufacturer ;
}
public void setManufacturer ( String manufacturer ) {
this . manufacturer = manufacturer ;
}
public String getArticlenumber ( ) {
return articlenumber ;
}
public void setArticlenumber ( String articlenumber ) {
this . articlenumber = articlenumber ;
}
public String getSupplierName ( ) {
return supplierName ;
}
public void setSupplierName ( String supplierName ) {
this . supplierName = supplierName ;
}
public String getPrice ( ) {
return price ;
}
public void setPrice ( String price ) {
this . price = price ;
}
public String getAds ( ) {
return ads ;
}
public void setAds ( String ads ) {
this . ads = ads ;
}
public int getListedArticleId ( ) {
return listedArticleId ;
}
public void setListedArticleId ( int listedArticleId ) {
this . listedArticleId = listedArticleId ;
}
2020-05-30 11:52:30 +02:00
public void addData ( ArticleOffer article , Optional < Integer > listedArticleId ) {
2020-05-16 22:48:20 +02:00
2020-05-19 16:30:27 +02:00
this . offer_id = article . id ;
2020-05-19 00:12:26 +02:00
this . title = article . title ;
this . manufacturer = article . manufacturer ;
this . articlenumber = article . articleNumber ;
2020-05-30 11:52:30 +02:00
this . supplierName = article . cheapestSupplier . name ;
2020-05-19 00:12:26 +02:00
this . price = String . format ( " %.2f " , ( ( float ) article . pricePerUnitNet / 100 ) ) ;
2020-05-19 16:30:27 +02:00
this . ads = ( article . shouldBeAdvertised ) ? " Ja " : " Nein " ;
2020-05-15 14:14:29 +02:00
2020-05-19 16:30:27 +02:00
if ( listedArticleId . isPresent ( ) ) {
// this offer is listed --> show link
this . listedArticleId = listedArticleId . get ( ) ;
offerIsListed = true ;
} else {
// this offer is not listed
offerIsListed = false ;
}
}
2020-05-15 11:57:20 +02:00
}
2020-04-28 22:41:29 +02:00
}