mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 15:55:49 +00:00
commit
f4a43c06c8
6 changed files with 247 additions and 72 deletions
|
@ -1,47 +1,58 @@
|
||||||
package org.springframework.cheapy.model;
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
import javax.persistence.JoinColumn;
|
import javax.persistence.Id;
|
||||||
import javax.persistence.ManyToOne;
|
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Size;
|
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "authorities")
|
@Table(name = "authorities")
|
||||||
public class Authorities extends BaseEntity{
|
public class Authorities{
|
||||||
|
|
||||||
|
@Id
|
||||||
|
String username;
|
||||||
|
|
||||||
/**
|
String authority;
|
||||||
*
|
|
||||||
*/
|
public String getUsername() {
|
||||||
private static final long serialVersionUID = 1L;
|
return username;
|
||||||
|
|
||||||
@ManyToOne
|
|
||||||
@JoinColumn(name = "username")
|
|
||||||
private Usuario user;
|
|
||||||
|
|
||||||
@Size(min = 3, max = 50)
|
|
||||||
private String authority;
|
|
||||||
|
|
||||||
public Usuario getUser() {
|
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
public void setUsername(String username) {
|
||||||
public void setUser(Usuario usern) {
|
this.username = username;
|
||||||
this.user = usern;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthority() {
|
public String getAuthority() {
|
||||||
return authority;
|
return authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAuthority(String authority) {
|
public void setAuthority(String authority) {
|
||||||
this.authority = authority;
|
this.authority = authority;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static long getSerialversionuid() {
|
|
||||||
return serialVersionUID;
|
// @ManyToOne
|
||||||
}
|
// @JoinColumn(name = "username")
|
||||||
|
// private Usuario user;
|
||||||
|
//
|
||||||
|
// @Size(min = 3, max = 50)
|
||||||
|
// private String authority;
|
||||||
|
//
|
||||||
|
// public Usuario getUser() {
|
||||||
|
// return user;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setUser(Usuario usern) {
|
||||||
|
// this.user = usern;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public String getAuthority() {
|
||||||
|
// return authority;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setAuthority(String authority) {
|
||||||
|
// this.authority = authority;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public static long getSerialversionuid() {
|
||||||
|
// return serialVersionUID;
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,43 @@
|
||||||
package org.springframework.cheapy.model;
|
package org.springframework.cheapy.model;
|
||||||
|
|
||||||
|
import java.time.LocalTime;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
import javax.persistence.Entity;
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
import javax.validation.constraints.Digits;
|
import javax.validation.constraints.Digits;
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.NotEmpty;
|
import javax.validation.constraints.NotEmpty;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "clients")
|
@Table(name = "clients")
|
||||||
public class Client extends BaseEntity{
|
public class Client extends BaseEntity{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
// (id, email, address, init, finish, telephone, description, code, food, usuar)
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String address;
|
private String address;
|
||||||
|
|
||||||
@NotEmpty
|
//@DateTimeFormat(pattern = "HH:mm")
|
||||||
private String timetable;
|
@NotBlank
|
||||||
|
private String init;
|
||||||
|
|
||||||
|
//@DateTimeFormat(pattern = "HH:mm")
|
||||||
|
@NotBlank
|
||||||
|
private String finish;
|
||||||
|
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
@Digits(fraction = 0, integer = 10)
|
@Digits(fraction = 0, integer = 10)
|
||||||
|
@ -34,6 +52,10 @@ public class Client extends BaseEntity{
|
||||||
@NotEmpty
|
@NotEmpty
|
||||||
private String food;
|
private String food;
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "username", referencedColumnName = "username")
|
||||||
|
private User usuar;
|
||||||
|
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private Set<FoodOffer> foodOffers;
|
private Set<FoodOffer> foodOffers;
|
||||||
|
|
||||||
|
@ -46,6 +68,8 @@ public class Client extends BaseEntity{
|
||||||
@OneToMany
|
@OneToMany
|
||||||
private Set<TimeOffer> timeOffers;
|
private Set<TimeOffer> timeOffers;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String getEmail() {
|
public String getEmail() {
|
||||||
return email;
|
return email;
|
||||||
}
|
}
|
||||||
|
@ -62,12 +86,29 @@ public class Client extends BaseEntity{
|
||||||
this.address = address;
|
this.address = address;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTimetable() {
|
|
||||||
return timetable;
|
public String getInit() {
|
||||||
|
return init;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimetable(String timetable) {
|
public void setInit(String init) {
|
||||||
this.timetable = timetable;
|
this.init = init;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFinish() {
|
||||||
|
return finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFinish(String finish) {
|
||||||
|
this.finish = finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUsername() {
|
||||||
|
return usuar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(User username) {
|
||||||
|
this.usuar = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTelephone() {
|
public String getTelephone() {
|
||||||
|
@ -101,4 +142,37 @@ public class Client extends BaseEntity{
|
||||||
public void setFood(String food) {
|
public void setFood(String food) {
|
||||||
this.food = food;
|
this.food = food;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<FoodOffer> getFoodOffers() {
|
||||||
|
return foodOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFoodOffers(Set<FoodOffer> foodOffers) {
|
||||||
|
this.foodOffers = foodOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<NuOffer> getNuOffers() {
|
||||||
|
return nuOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNuOffers(Set<NuOffer> nuOffers) {
|
||||||
|
this.nuOffers = nuOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<SpeedOffer> getSpeedOffers() {
|
||||||
|
return speedOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpeedOffers(Set<SpeedOffer> speedOffers) {
|
||||||
|
this.speedOffers = speedOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<TimeOffer> getTimeOffers() {
|
||||||
|
return timeOffers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeOffers(Set<TimeOffer> timeOffers) {
|
||||||
|
this.timeOffers = timeOffers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -4,15 +4,40 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.MappedSuperclass;
|
import javax.persistence.MappedSuperclass;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
|
|
||||||
@MappedSuperclass
|
@Entity
|
||||||
public class User extends BaseEntity{
|
@Table(name = "users")
|
||||||
|
//@MappedSuperclass
|
||||||
|
public class User{
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
boolean enabled;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@OneToOne
|
|
||||||
@JoinColumn(name = "username")
|
public String getUsername() {
|
||||||
private Usuario usuario;
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,45 +9,97 @@ import javax.persistence.JoinColumn;
|
||||||
import javax.persistence.OneToMany;
|
import javax.persistence.OneToMany;
|
||||||
import javax.persistence.OneToOne;
|
import javax.persistence.OneToOne;
|
||||||
import javax.persistence.Table;
|
import javax.persistence.Table;
|
||||||
|
import javax.validation.constraints.Email;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "users")
|
@Table(name = "usuarios")
|
||||||
public class Usuario {
|
public class Usuario extends BaseEntity{
|
||||||
|
|
||||||
@Id
|
/** nombre, apellidos, dni, direccion, telefono, email, username
|
||||||
private String username;
|
* (id,nombre, apellidos, dni, direccion, telefono, email, usuar)
|
||||||
|
*/
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
private String password;
|
private String nombre;
|
||||||
|
|
||||||
boolean enabled;
|
@NotBlank
|
||||||
|
private String apellidos;
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
@NotBlank
|
||||||
|
private String dni;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
private String direccion;
|
||||||
|
|
||||||
|
@NotBlank
|
||||||
|
//@Pattern(regexp = "([+][^0][\\d]{0,2})?[ ]?([(][\\d]{0,4}[)])?[ ]?([\\d]{6,10})$")
|
||||||
|
private String telefono;
|
||||||
|
|
||||||
|
@Email
|
||||||
|
@NotBlank
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
|
@JoinColumn(name = "username", referencedColumnName = "username")
|
||||||
|
private User usuar;
|
||||||
|
|
||||||
|
public String getNombre() {
|
||||||
|
return nombre;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsername(String username) {
|
public void setNombre(String nombre) {
|
||||||
this.username = username;
|
this.nombre = nombre;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getPassword() {
|
public String getApellidos() {
|
||||||
return password;
|
return apellidos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPassword(String password) {
|
public void setApellidos(String apellidos) {
|
||||||
this.password = password;
|
this.apellidos = apellidos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDni() {
|
||||||
|
return dni;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDni(String dni) {
|
||||||
|
this.dni = dni;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDireccion() {
|
||||||
|
return direccion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDireccion(String direccion) {
|
||||||
|
this.direccion = direccion;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTelefono() {
|
||||||
|
return telefono;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTelefono(String telefono) {
|
||||||
|
this.telefono = telefono;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return usuar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User username) {
|
||||||
|
this.usuar = username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
|
|
||||||
private Set<Authorities> authorities;
|
|
||||||
|
|
||||||
public Set<Authorities> getAuthorities() {
|
|
||||||
return authorities;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAuthorities(Set<Authorities> authorities) {
|
|
||||||
this.authorities = authorities;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,6 @@ import org.springframework.cheapy.model.Usuario;
|
||||||
|
|
||||||
public interface UsuarioRepository extends CrudRepository<Usuario, String> {
|
public interface UsuarioRepository extends CrudRepository<Usuario, String> {
|
||||||
|
|
||||||
Usuario findByUsername(String currentPrincipalName);
|
//Usuario findByUsername(String currentPrincipalName);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,24 @@ INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discoun
|
||||||
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 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 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 users (dtype,username,password,enabled) VALUES ('user','admin','admin', TRUE );
|
||||||
--insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin');
|
INSERT INTO authorities VALUES ('admin','admin');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','manoli','manoli', TRUE );
|
||||||
|
INSERT INTO authorities VALUES ('manoli','cliente');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','david','david', TRUE );
|
||||||
|
INSERT INTO authorities VALUES ('david','cliente');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','paco','paco', TRUE );
|
||||||
|
INSERT INTO authorities VALUES ('paco','usuario');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','lolo','lolo', TRUE );
|
||||||
|
INSERT INTO authorities VALUES ('lolo','usuario');
|
||||||
|
INSERT INTO users (dtype,username,password,enabled) VALUES ('user','pepe','pepe', TRUE );
|
||||||
|
INSERT INTO authorities VALUES ('pepe','usuario');
|
||||||
|
|
||||||
INSERT INTO users(username,password,enabled) VALUES ('cliente','cliente',TRUE);
|
INSERT INTO usuarios VALUES (1, 'admin', 'admin', 'admin', 'C/admin', '000000000', 'admin@gmail.com','admin');
|
||||||
INSERT INTO authorities(id,username,authority) VALUES (1,'cliente','client');
|
|
||||||
|
|
||||||
INSERT INTO clients(email, address, timetable,telephone,description,code,food) VALUES ('cliente@hotmail.com','Calle Tahona nº5','12:00-23:00','954876351','Descripcion','codigo','variado');
|
INSERT INTO clients VALUES (1,'manoli@gmail.com','C/Betis','10:00','22:00','608726190', 'description 1', 'code1', 'ESPAÑOLA','manoli');
|
||||||
--INSERT INTO authorities(id,username,authority) VALUES (31,'cliente','client');
|
INSERT INTO clients VALUES (2,'david@gmail.com','C/Sevilla','09:30','22:00','608726190', 'description 2', 'code2', 'americana','david');
|
||||||
|
|
||||||
|
INSERT INTO usuarios VALUES (2, 'Paco', 'Naranjo', '21154416G', 'C/Esperanza', '666973647', 'Paco@gmail.com','paco');
|
||||||
|
INSERT INTO usuarios VALUES (3, 'Lolo', 'Lopez', '25486596L', 'C/Macarena', '690670547' ,'Lolo@gmail.com','lolo');
|
||||||
|
INSERT INTO usuarios VALUES (4, 'Pepe', 'Lopez', '12456776V', 'C/Macarena', '690670547', 'Pepe@gmail.com','pepe');
|
||||||
|
|
Loading…
Reference in a new issue