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 ( ) ) {
2020-06-08 18:56:35 +02:00
UImodelOfferedArticle tmp = new UImodelOfferedArticle ( 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-06-05 18:05:10 +02:00
public long offerId ;
public String title ;
public String manufacturer ;
public String articleNumber ;
public String supplierName ;
public String price ;
public String ads ;
public int listedArticleId ;
public boolean offerIsListed ; // true --> offered article is listed
2020-05-16 22:48:20 +02:00
2020-06-08 18:56:35 +02:00
public UImodelOfferedArticle ( ArticleOffer article , Optional < Integer > listedArticleId ) {
2020-05-16 22:48:20 +02:00
2020-06-05 18:05:10 +02:00
this . offerId = article . id ;
2020-05-19 00:12:26 +02:00
this . title = article . title ;
this . manufacturer = article . manufacturer ;
2020-06-05 18:05:10 +02:00
this . articleNumber = article . articleNumber ;
2020-06-08 18:56:35 +02:00
if ( article . cheapestSupplier ! = null ) {
this . supplierName = article . cheapestSupplier . name ;
} else {
this . supplierName = " - " ;
}
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
}