diff --git a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java index b031d789c..f8ebcfc52 100644 --- a/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java +++ b/src/main/java/org/springframework/cheapy/repository/TimeOfferRepository.java @@ -3,7 +3,6 @@ package org.springframework.cheapy.repository; import java.util.List; -import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; import org.springframework.data.domain.Pageable; @@ -12,15 +11,17 @@ import org.springframework.data.repository.PagingAndSortingRepository; import org.springframework.data.repository.query.Param; import org.springframework.transaction.annotation.Transactional; -public interface TimeOfferRepository extends PagingAndSortingRepository { - - TimeOffer findTimeOfferById(int timeOfferId); +public interface TimeOfferRepository extends PagingAndSortingRepository { + + @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.id =:id") + @Transactional(readOnly = true) + TimeOffer findTimeOfferById(int id); @Query("SELECT timeOffer FROM TimeOffer timeOffer") @Transactional(readOnly = true) List findAllTimeOffer(Pageable p); - void save(TimeOffer timeOffer); + //void save(TimeOffer timeOffer); @Query("SELECT timeOffer FROM TimeOffer timeOffer WHERE timeOffer.status =:status") @Transactional(readOnly = true) diff --git a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java index eb0a85b14..06c249351 100644 --- a/src/main/java/org/springframework/cheapy/service/FoodOfferService.java +++ b/src/main/java/org/springframework/cheapy/service/FoodOfferService.java @@ -25,7 +25,7 @@ public class FoodOfferService { public FoodOffer findFoodOfferById(final int id) { return this.foodOfferRepository.findByIdFO(id); } - + public List findAllFoodOffer(final Pageable p) { // return this.foodOfferRepository.findAllFoodOffer(); } diff --git a/src/main/java/org/springframework/cheapy/web/AdministratorController.java b/src/main/java/org/springframework/cheapy/web/AdministratorController.java index a880a6896..baa955e3d 100644 --- a/src/main/java/org/springframework/cheapy/web/AdministratorController.java +++ b/src/main/java/org/springframework/cheapy/web/AdministratorController.java @@ -1,13 +1,18 @@ package org.springframework.cheapy.web; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.TreeMap; import javax.servlet.http.HttpServletRequest; import org.springframework.cheapy.model.Client; import org.springframework.cheapy.model.FoodOffer; import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.Offer; import org.springframework.cheapy.model.SpeedOffer; import org.springframework.cheapy.model.StatusOffer; import org.springframework.cheapy.model.TimeOffer; @@ -18,6 +23,8 @@ import org.springframework.cheapy.service.NuOfferService; import org.springframework.cheapy.service.SpeedOfferService; import org.springframework.cheapy.service.TimeOfferService; import org.springframework.cheapy.service.UsuarioService; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; @@ -139,4 +146,98 @@ public class AdministratorController { this.clientService.saveClient(client); return "redirect:/administrators/clients"; } + + @GetMapping("/administrators/offersRecord") + public String processOffersRecordForm(final Map model) { + + Pageable p = PageRequest.of(0, 3); + + List datos = new ArrayList(); + + for(Offer of:this.foodOfferService.findAllFoodOffer(p)) { + Object[] fo = {of, "food"}; + datos.add(fo); + } + + for(Offer of:this.nuOfferService.findAllNuOffer(p)) { + Object[] nu = {of, "nu"}; + datos.add(nu); + } + + for(Offer of:this.speedOfferService.findAllSpeedOffer(p)) { + Object[] sp = {of, "speed"}; + datos.add(sp); + } + + for(Offer of:this.timeOfferService.findAllTimeOffer(p)) { + Object[] ti = {of, "time"}; + datos.add(ti); + } + + model.put("datos", datos); + + //Se añade formateador de fecha al modelo + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + + return "offers/offersRecordList"; + } + + @GetMapping("/administrators/offers/nu/{nuOfferId}") + public String processShowNuForm(@PathVariable("nuOfferId") final int nuOfferId, final Map model) { + + NuOffer nuOffer = this.nuOfferService.findNuOfferById(nuOfferId); + + if (nuOffer != null) { + model.put("nuOffer", nuOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/nu/nuOffersShow"; + } else { + return "welcome"; + } + + } + + @GetMapping("/administrators/offers/food/{foodOfferId}") + public String processShowFoodForm(@PathVariable("foodOfferId") final int foodOfferId, final Map model) { + + FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId); + + if (foodOffer != null) { + model.put("foodOffer", foodOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/food/foodOffersShow"; + + } else { + return "welcome"; + } + } + + @GetMapping("/administrators/offers/speed/{speedOfferId}") + public String processShowSpeedForm(@PathVariable("speedOfferId") final int speedOfferId, final Map model) { + + SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId); + + if (speedOffer != null) { + model.put("speedOffer", speedOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/speed/speedOffersShow"; + } else { + return "welcome"; + } + } + + @GetMapping("/administrators/offers/time/{timeOfferId}") + public String processShowTimeForm(@PathVariable("timeOfferId") final int timeOfferId, final Map model) { + + TimeOffer timeOffer = this.timeOfferService.findTimeOfferById(timeOfferId); + + if (timeOffer != null) { + model.put("timeOffer", timeOffer); + model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); + return "offers/time/timeOffersShow"; + + } else { + return "welcome"; + } + } } diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 2b82b91dc..39ec7c0d8 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -127,37 +127,6 @@ public class OfertaController { return "offers/offersCreate"; } - @GetMapping("/offersRecord") - public String processOffersRecordForm(final Map model) { - - Pageable p = PageRequest.of(0, 3); - - Map datos = new HashMap(); - - for(Offer of:this.foodOfferService.findAllFoodOffer(p)) { - datos.put(of, "food"); - } - - for(Offer of:this.nuOfferService.findAllNuOffer(p)) { - datos.put(of, "nu"); - } - - for(Offer of:this.speedOfferService.findAllSpeedOffer(p)) { - datos.put(of, "speed"); - } - - for(Offer of:this.timeOfferService.findAllTimeOffer(p)) { - datos.put(of, "time"); - } - - model.put("datos", datos); - - //Se añade formateador de fecha al modelo - model.put("localDateTimeFormat", DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm")); - - return "offers/offersRecordList"; - } - // @GetMapping("/owners/{ownerId}/edit") // public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { // Owner owner = this.ownerService.findOwnerById(ownerId); diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersRecordList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersRecordList.jsp index 7598a1ddc..4e0d4e251 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersRecordList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersRecordList.jsp @@ -17,6 +17,7 @@ Restaurante + ID Tipo de oferta @@ -28,43 +29,47 @@ - + - + + + + - + - + - + + - + - + - + - + - + - - + +