mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 07:45:49 +00:00
Corrercion de errores
This commit is contained in:
parent
346a049fe2
commit
f9452671bb
7 changed files with 27 additions and 20 deletions
|
@ -18,6 +18,7 @@ package org.springframework.cheapy.model;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "food_offers")
|
||||
|
@ -29,7 +30,7 @@ public class FoodOffer extends Offer {
|
|||
@NotBlank
|
||||
private String discount;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer units; // revisar
|
||||
|
||||
public String getFood() {
|
||||
|
|
|
@ -17,15 +17,13 @@ package org.springframework.cheapy.model;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.Future;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
|
@ -33,12 +31,12 @@ import org.springframework.format.annotation.DateTimeFormat;
|
|||
public class Offer extends BaseEntity {
|
||||
|
||||
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
|
||||
@NotBlank
|
||||
@NotNull
|
||||
@Future
|
||||
private LocalDateTime start;
|
||||
|
||||
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm")
|
||||
@NotBlank
|
||||
@NotNull
|
||||
@Future
|
||||
private LocalDateTime end;
|
||||
|
||||
|
@ -47,6 +45,7 @@ public class Offer extends BaseEntity {
|
|||
@Enumerated(value = EnumType.STRING)
|
||||
private StatusOffer type;
|
||||
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="client_id")
|
||||
private Client client;
|
||||
|
|
|
@ -19,26 +19,27 @@ import javax.persistence.Column;
|
|||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Entity
|
||||
@Table(name = "speed_offers")
|
||||
public class SpeedOffer extends Offer {
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer gold; // x minutos
|
||||
|
||||
@Column(name = "discount_gold")
|
||||
@NotBlank
|
||||
private String discountGold;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer silver;
|
||||
|
||||
@Column(name = "discount_silver")
|
||||
@NotBlank
|
||||
private String discountSilver;
|
||||
|
||||
@NotBlank
|
||||
@NotNull
|
||||
private Integer bronze;
|
||||
|
||||
@Column(name = "discount_bronze")
|
||||
|
|
|
@ -16,8 +16,10 @@
|
|||
package org.springframework.cheapy.service;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cheapy.model.Client;
|
||||
import org.springframework.cheapy.repository.ClientRepository;
|
||||
import org.springframework.cheapy.repository.SpeedOfferRepository;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
@ -36,6 +38,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
public class ClientService {
|
||||
|
||||
private ClientRepository clientRepository;
|
||||
|
||||
@Autowired
|
||||
public ClientService(final ClientRepository clientRepository) {
|
||||
this.clientRepository = clientRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Client getCurrentclient() throws DataAccessException {
|
||||
|
|
|
@ -73,17 +73,17 @@ public class FoodOfferController {
|
|||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/foodOffers/{foodOfferid}/activate")
|
||||
public String activateFoodOffer(@PathVariable("foodOffer") final int foodOfferId, final ModelMap modelMap) {
|
||||
@GetMapping(value = "/foodOffers/{foodOfferId}/activate")
|
||||
public String activateFoodOffer(@PathVariable("foodOfferId") final int foodOfferId, ModelMap modelMap) {
|
||||
FoodOffer foodOffer = this.foodOfferService.findFoodOfferById(foodOfferId);
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
if(foodOffer.getClient().equals(client)) {
|
||||
foodOffer.setType(StatusOffer.active);
|
||||
foodOffer.setCode("SE-"+foodOfferId);
|
||||
foodOffer.setCode("FE-"+foodOfferId);
|
||||
this.foodOfferService.saveFoodOffer(foodOffer);
|
||||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this food offer");
|
||||
}
|
||||
return "redirect:/foodOffers/" + foodOffer.getId();
|
||||
return "redirect:/foodOffers/";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,8 +73,8 @@ public class SpeedOfferController {
|
|||
}
|
||||
}
|
||||
|
||||
@GetMapping(value = "/speedOffers/{speedOfferid}/activate")
|
||||
public String activateSpeedOffer(@PathVariable("speedOffer") final int speedOfferId, final ModelMap modelMap) {
|
||||
@GetMapping(value = "/speedOffers/{speedOfferId}/activate")
|
||||
public String activateSpeedOffer(@PathVariable("speedOfferId") final int speedOfferId, ModelMap modelMap) {
|
||||
SpeedOffer speedOffer = this.speedOfferService.findSpeedOfferById(speedOfferId);
|
||||
Client client = this.clientService.getCurrentclient();
|
||||
if(speedOffer.getClient().equals(client)) {
|
||||
|
@ -84,6 +84,6 @@ public class SpeedOfferController {
|
|||
} else {
|
||||
modelMap.addAttribute("message", "You don't have access to this speed offer");
|
||||
}
|
||||
return "redirect:/speedOffers/" + speedOffer.getId();
|
||||
return "redirect:/speedOffers/";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,13 +10,12 @@ INSERT INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Mad
|
|||
INSERT INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487');
|
||||
|
||||
|
||||
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 food_offers(start, end, code, type, client_id, food, discount, units) VALUES ('2021-06-15 12:00:00', '2021-06-16 12:00:00', 'FE-1', 'active', null, 'macarrones', '15%', 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', 'SE-1', 'active', null, 5, '15%', 10, '10%', 15, '5%');
|
||||
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 usuarios(username, password, enabled) values ('admin3', 'admin', true);
|
||||
--insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin');
|
||||
|
||||
INSERT INTO users(username,password,enabled) VALUES ('admin1','4dm1n',TRUE);
|
||||
INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin');
|
||||
|
||||
INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin');
|
Loading…
Reference in a new issue