diff --git a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java index 2b9ce3c1c..1f7d7cd13 100644 --- a/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java +++ b/src/main/java/org/springframework/cheapy/configuration/SecurityConfiguration.java @@ -38,7 +38,7 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter { .antMatchers(HttpMethod.GET, "/", "/oups").permitAll() .antMatchers("/users/new").permitAll() .antMatchers("/usuarios/new").permitAll() - .antMatchers("/offers").permitAll() + .antMatchers("/offers/**").permitAll() .antMatchers("/admin/**").hasAnyAuthority("admin") .antMatchers("/owners/**").hasAnyAuthority("owner", "admin") .antMatchers("/vets/**").authenticated().anyRequest().denyAll() diff --git a/src/main/java/org/springframework/cheapy/web/NuOfferController.java b/src/main/java/org/springframework/cheapy/web/NuOfferController.java new file mode 100644 index 000000000..bd6d34844 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/NuOfferController.java @@ -0,0 +1,104 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cheapy.web; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.TimeOffer; +import org.springframework.cheapy.service.FoodOfferService; +import org.springframework.cheapy.service.NuOfferService; +import org.springframework.cheapy.service.SpeedOfferService; +import org.springframework.cheapy.service.TimeOfferService; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + + +/** + * @author Juergen Hoeller + * @author Ken Krebs + * @author Arjen Poutsma + * @author Michael Isvy + */ +@Controller +public class NuOfferController { + + //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; + + + + public NuOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, + final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + this.foodOfferService = foodOfferService; + this.nuOfferService = nuOfferService; + this.speedOfferService = speedOfferService; + this.timeOfferService = timeOfferService; + + } + + + @GetMapping("/offers/nu/{nuOfferId}") + public String processShowForm(@PathVariable("nuOfferId") int nuOfferId, Map model) { + + NuOffer nuOffer=this.nuOfferService.findNuOfferById(nuOfferId); + + model.put("nuOffer", nuOffer); + + return "nuOffers/nuOffersShow"; + + } + +// @GetMapping("/owners/{ownerId}/edit") +// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { +// Owner owner = this.ownerService.findOwnerById(ownerId); +// model.addAttribute(owner); +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// +// @PostMapping("/owners/{ownerId}/edit") +// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, +// @PathVariable("ownerId") int ownerId) { +// if (result.hasErrors()) { +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// else { +// owner.setId(ownerId); +// this.ownerService.saveOwner(owner); +// return "redirect:/owners/{ownerId}"; +// } +// } +// @GetMapping("/owners/{ownerId}") +// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { +// ModelAndView mav = new ModelAndView("owners/ownerDetails"); +// Owner owner = this.ownerService.findOwnerById(ownerId); +// +// mav.addObject(owner); +// return mav; +// } + + +} diff --git a/src/main/java/org/springframework/cheapy/web/OfertaController.java b/src/main/java/org/springframework/cheapy/web/OfertaController.java index 517b1f5d9..dcd92f583 100644 --- a/src/main/java/org/springframework/cheapy/web/OfertaController.java +++ b/src/main/java/org/springframework/cheapy/web/OfertaController.java @@ -44,7 +44,7 @@ public class OfertaController { //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; private final FoodOfferService foodOfferService; - private final NuOfferService nuOfferService; + private final NuOfferService nuOfferService; private final SpeedOfferService speedOfferService; private final TimeOfferService timeOfferService; diff --git a/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java new file mode 100644 index 000000000..68a377a68 --- /dev/null +++ b/src/main/java/org/springframework/cheapy/web/SpeedOfferController.java @@ -0,0 +1,104 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cheapy.web; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.springframework.cheapy.model.FoodOffer; +import org.springframework.cheapy.model.NuOffer; +import org.springframework.cheapy.model.SpeedOffer; +import org.springframework.cheapy.model.TimeOffer; +import org.springframework.cheapy.service.FoodOfferService; +import org.springframework.cheapy.service.NuOfferService; +import org.springframework.cheapy.service.SpeedOfferService; +import org.springframework.cheapy.service.TimeOfferService; +import org.springframework.stereotype.Controller; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + + +/** + * @author Juergen Hoeller + * @author Ken Krebs + * @author Arjen Poutsma + * @author Michael Isvy + */ +@Controller +public class SpeedOfferController { + + //private static final String VIEWS_OWNER_CREATE_OR_UPDATE_FORM = "owners/createOrUpdateOwnerForm"; + + private final FoodOfferService foodOfferService; + private final NuOfferService nuOfferService; + private final SpeedOfferService speedOfferService; + private final TimeOfferService timeOfferService; + + + + public SpeedOfferController(final FoodOfferService foodOfferService, final NuOfferService nuOfferService, + final SpeedOfferService speedOfferService, final TimeOfferService timeOfferService) { + this.foodOfferService = foodOfferService; + this.nuOfferService = nuOfferService; + this.speedOfferService = speedOfferService; + this.timeOfferService = timeOfferService; + + } + + + @GetMapping("/offers/speed/{speedOfferId}") + public String processShowForm(@PathVariable("speedOfferId") int speedOfferId, Map model) { + + SpeedOffer speedOffer=this.speedOfferService.findSpeedOfferById(speedOfferId); + + model.put("speedOffer", speedOffer); + + return "speedOffers/speedOffersShow"; + + } + +// @GetMapping("/owners/{ownerId}/edit") +// public String initUpdateOwnerForm(@PathVariable("ownerId") int ownerId, Model model) { +// Owner owner = this.ownerService.findOwnerById(ownerId); +// model.addAttribute(owner); +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// +// @PostMapping("/owners/{ownerId}/edit") +// public String processUpdateOwnerForm(@Valid Owner owner, BindingResult result, +// @PathVariable("ownerId") int ownerId) { +// if (result.hasErrors()) { +// return VIEWS_OWNER_CREATE_OR_UPDATE_FORM; +// } +// else { +// owner.setId(ownerId); +// this.ownerService.saveOwner(owner); +// return "redirect:/owners/{ownerId}"; +// } +// } +// @GetMapping("/owners/{ownerId}") +// public ModelAndView showOwner(@PathVariable("ownerId") int ownerId) { +// ModelAndView mav = new ModelAndView("owners/ownerDetails"); +// Owner owner = this.ownerService.findOwnerById(ownerId); +// +// mav.addObject(owner); +// return mav; +// } + + +} diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 3dd3b74c7..b1bab7a65 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -13,6 +13,8 @@ INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Wa INSERT INTO food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, 'macarrones', '15%', 10); INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discount) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null, '12:00:00', '13:00:00', '10%'); +INSERT INTO speed_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,5,'25%',10,'15%',15,'10%' ); +INSERT INTO nu_offers(start, end, code, type, client_id, gold, discount_gold, silver, discount_silver, bronze, discount_bronze) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'jkhlljk', 'active', null,15,'25%',10,'15%',5,'10%' ); --insert into usuarios(username, password, enabled) values ('admin3', 'admin', true); --insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin'); diff --git a/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp new file mode 100644 index 000000000..9c4eca9f3 --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/nuOffers/nuOffersShow.jsp @@ -0,0 +1,56 @@ +<%@ page session="false" trimDirectiveWhitespaces="true" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> + + + +

Oferta por número de comensales

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Inicio de la oferta
Fin de la oferta
Meta oro
Descuento oro
Meta plata
Descuento plata
Meta bronce
Descuento bronce
Codigo de la oferta
+ + <%-- + + + Edit Owner --%> + +
diff --git a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp index 0bdf44add..b7df4694d 100644 --- a/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp +++ b/src/main/webapp/WEB-INF/jsp/offers/offersList.jsp @@ -50,30 +50,31 @@ Fecha inicio Fecha fin + - <%-- - - - - - --%> + - + + + + + Enlace + -

Ofertas por plato específico

+

Ofertas rapidez comiendo

@@ -81,30 +82,32 @@ + - <%-- --%> + +
Fecha inicio Fecha fin
- - - - - + + + + Enlace +
-

Ofertas por plato específico

+

Ofertas por franja horaria

@@ -118,19 +121,19 @@ - <%-- --%> + - + <%-- --%> diff --git a/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp new file mode 100644 index 000000000..4a85df28b --- /dev/null +++ b/src/main/webapp/WEB-INF/jsp/speedOffers/speedOffersShow.jsp @@ -0,0 +1,56 @@ +<%@ page session="false" trimDirectiveWhitespaces="true" %> +<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> +<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> +<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> +<%@ taglib prefix="cheapy" tagdir="/WEB-INF/tags" %> + + + +

Oferta por comer veloz

+ + +
- - - - - + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Inicio de la oferta
Fin de la oferta
Meta oro
Descuento oro
Meta plata
Descuento plata
Meta bronce
Descuento bronce
Codigo de la oferta
+ + <%-- + + + Edit Owner --%> + +