Añadidas y arregladas ofertas de franja horaria y de numero de

comensales
This commit is contained in:
abemorcardc 2021-03-25 21:25:27 +01:00
parent 83897d84d5
commit 226833aa4d
8 changed files with 34 additions and 15 deletions

View file

@ -37,8 +37,8 @@ public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
http.authorizeRequests().antMatchers("/resources/**", "/webjars/**", "/h2-console/**").permitAll()
.antMatchers(HttpMethod.GET, "/", "/oups").permitAll()
.antMatchers("/users/new").permitAll()
.antMatchers("/nuOffers/new").hasAnyAuthority("admin","client")
.antMatchers("/timeOffers/new").hasAnyAuthority("admin","client")
.antMatchers("/nuOffers/**").hasAnyAuthority("admin","client")
.antMatchers("/timeOffers/**").hasAnyAuthority("admin","client")
.antMatchers("/usuarios/new").permitAll()
.antMatchers("/admin/**").hasAnyAuthority("admin")
.antMatchers("/owners/**").hasAnyAuthority("owner", "admin")

View file

@ -6,6 +6,7 @@ import org.springframework.data.repository.CrudRepository;
public interface ClientRepository extends CrudRepository<Client, String> {
Client findByUsername(String currentPrincipalName);
Client findByUsername(String username);
}

View file

@ -1,11 +1,10 @@
package org.springframework.cheapy.repository;
import org.springframework.cheapy.model.NuOffer;
import org.springframework.cheapy.model.TimeOffer;
import org.springframework.data.repository.Repository;
public interface TimeOfferRepository extends Repository<NuOffer, Integer> {
public interface TimeOfferRepository extends Repository<TimeOffer, Integer> {

View file

@ -16,6 +16,7 @@
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.dao.DataAccessException;
@ -31,11 +32,16 @@ public class ClientService {
private ClientRepository clientRepository;
@Autowired
public ClientService(final ClientRepository clientRepository) {
this.clientRepository = clientRepository;
}
@Transactional
public Client getCurrentClient() throws DataAccessException {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
String currentPrincipalName = authentication.getName();
return this.clientRepository.findByUsername(currentPrincipalName);
String username = authentication.getName();
return this.clientRepository.findByUsername(username);
}
}

View file

@ -8,21 +8,21 @@ import org.springframework.stereotype.Service;
@Service
public class TimeOfferService {
private TimeOfferRepository TimeOfferRepository;
private TimeOfferRepository timeOfferRepository;
@Autowired
public TimeOfferService(final TimeOfferRepository TimeOfferRepository) {
this.TimeOfferRepository = TimeOfferRepository;
this.timeOfferRepository = TimeOfferRepository;
}
public TimeOffer findTimeOfferById(final int id) {
return this.TimeOfferRepository.findTimeOfferById(id);
return this.timeOfferRepository.findTimeOfferById(id);
}
public void saveTimeOffer(final TimeOffer TimeOffer) throws DataAccessException { //
this.TimeOfferRepository.save(TimeOffer);
this.timeOfferRepository.save(TimeOffer);
}
}

View file

@ -71,12 +71,13 @@ public class NuOfferController {
if(nuOffer.getClient().equals(client)) {
nuOffer.setType(StatusOffer.active);
nuOffer.setCode("NU-"+nuOfferId);
this.nuOfferService.saveNuOffer(nuOffer);
return "redirect:/nuOffers/" + nuOffer.getId();
} else {
modelMap.addAttribute("message", "You don't have access to this number offer");
}
return "redirect:/nuOffers/" + nuOffer.getId();
return "redirect:/nuOffers/";
}

View file

@ -71,12 +71,13 @@ public class TimeOfferController {
if(timeOffer.getClient().equals(client)) {
timeOffer.setType(StatusOffer.active);
timeOffer.setCode("TI-"+timeOfferId);
this.timeOfferService.saveTimeOffer(timeOffer);
return "redirect:/timeOffers/" + timeOffer.getId();
} else {
modelMap.addAttribute("message", "You don't have access to this number offer");
modelMap.addAttribute("message", "You don't have access to this time offer");
}
return "redirect:/timeOffers/" + timeOffer.getId();
return "redirect:/timeOffers/";
}

View file

@ -12,7 +12,7 @@ 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 usuarios(username, password, enabled) values ('admin3', 'admin', true);
--insert into authorities(id ,usuario, authority) values (42,'admin3', 'admin');
@ -20,3 +20,14 @@ INSERT INTO time_offers(start, end, code, type, client_id, init, finish, discoun
INSERT INTO users(username,password,enabled) VALUES ('admin1','4dm1n',TRUE);
INSERT INTO authorities(id,username,authority) VALUES (1,'admin1','admin');
INSERT INTO clients(username,password,enabled, email, address, timetable,telephone,description,code,food) VALUES ('cliente','cliente',TRUE,'cliente@hotmail.com','Calle Tahona nº5','12:00-23:00','954876351','Descripcion','codigo','variado');
INSERT INTO users(username,password,enabled) VALUES ('cliente','cliente',TRUE);
INSERT INTO authorities(id,username,authority) VALUES (2,'cliente','client');
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', 'cliente', '12:00:00', '13:00:00', '10%');
INSERT INTO clients(username,password,enabled, email, address, timetable,telephone,description,code,food) VALUES ('cliente2','cliente2',TRUE,'cliente@hotmail.com','Calle Tahona nº5','12:00-23:00','954876351','Descripcion','codigo','variado');
INSERT INTO users(username,password,enabled) VALUES ('cliente2','cliente2',TRUE);
INSERT INTO authorities(id,username,authority) VALUES (3,'cliente2','client');