Changeset bfc49f4 for sources/app/src
- Timestamp:
- 02/12/22 17:21:18 (3 years ago)
- Branches:
- master
- Children:
- b2e6513
- Parents:
- 7bb19d4
- Location:
- sources/app/src/main/java/parkup
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
sources/app/src/main/java/parkup/configs/webConfigs/WebSecurityConfig.java
r7bb19d4 rbfc49f4 14 14 import parkup.configs.CustomAuthorizationFilter; 15 15 import parkup.services.AdministratorService; 16 import parkup.services.GuestService; 16 17 import parkup.services.RegisteredUserService; 17 18 import parkup.services.WorkerService; … … 26 27 private final RegisteredUserService registeredUserService; 27 28 private final AdministratorService administratorService; 29 private final GuestService guestService; 28 30 29 public WebSecurityConfig(WorkerService workerService, BCryptPasswordEncoder bCryptPasswordEncoder, RegisteredUserService registeredUserService, AdministratorService administratorService ) {31 public WebSecurityConfig(WorkerService workerService, BCryptPasswordEncoder bCryptPasswordEncoder, RegisteredUserService registeredUserService, AdministratorService administratorService, GuestService guestService) { 30 32 this.workerService = workerService; 31 33 this.bCryptPasswordEncoder = bCryptPasswordEncoder; 32 34 this.registeredUserService = registeredUserService; 33 35 this.administratorService = administratorService; 36 this.guestService = guestService; 34 37 } 35 38 … … 39 42 auth.userDetailsService(workerService).passwordEncoder(bCryptPasswordEncoder); 40 43 auth.userDetailsService(administratorService).passwordEncoder(bCryptPasswordEncoder); 41 44 auth.userDetailsService(guestService).passwordEncoder(bCryptPasswordEncoder); 42 45 } 43 46 -
sources/app/src/main/java/parkup/controllers/ParkingSessionController.java
r7bb19d4 rbfc49f4 40 40 return this.parkingSessionService.verifyParkingSession(parkingSessionId,parkingSpaceName); 41 41 } 42 @GetMapping("/parkingSession/calculate /{parkingSessionId}")43 public int calculateParkingSession( @PathVariable int parkingSessionId){44 return this.parkingSessionService.calculatePayment( parkingSessionId);42 @GetMapping("/parkingSession/calculate") 43 public int calculateParkingSession(){ 44 return this.parkingSessionService.calculatePayment(); 45 45 } 46 46 @PutMapping("/parkingSession/pay") 47 public boolean payParkingSession(@RequestParam String expireDate){47 public boolean payParkingSession(@RequestParam(required = false) String expireDate){ 48 48 return this.parkingSessionService.payParkingSession(expireDate); 49 49 } -
sources/app/src/main/java/parkup/services/GuestService.java
r7bb19d4 rbfc49f4 4 4 import java.util.Optional; 5 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.security.core.userdetails.UserDetails; 7 import org.springframework.security.core.userdetails.UserDetailsService; 8 import org.springframework.security.core.userdetails.UsernameNotFoundException; 6 9 import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; 7 10 import org.springframework.stereotype.Service; … … 10 13 11 14 @Service 12 public class GuestService {15 public class GuestService implements UserDetailsService { 13 16 private final GuestRepository guestRepository; 14 17 private final BCryptPasswordEncoder passwordEncoder; … … 34 37 throw new IllegalStateException("Email already taken, try adding a guest with a different valid email address"); 35 38 } else { 36 // guest.setPassword(passwordEncoder.encode(Math.random())); 39 double random = Math.random()*100; 40 guest.setPassword(passwordEncoder.encode(Double.toString(random))); 37 41 this.guestRepository.save(guest); 38 42 } … … 47 51 } 48 52 } 53 54 @Override 55 public UserDetails loadUserByUsername(String s) throws UsernameNotFoundException { 56 return guestRepository.findGuestByEmail(s) 57 .orElseThrow(() -> 58 new UsernameNotFoundException("Email not found")); 59 } 49 60 } -
sources/app/src/main/java/parkup/services/ParkingSessionService.java
r7bb19d4 rbfc49f4 93 93 94 94 } 95 96 // public void executePayment(int id){ 97 // ParkingSession session = parkingSessionRepository.findByPssId(id); 98 // if(session==null){ 99 // throw new IllegalStateException("No such session exists"); 100 // } 101 // else if(session.getStatus()== SessionStatus.ENDED_UNPAID){ 102 // throw new IllegalStateException("Cannot execute payment on an ended session"); 103 // } 104 // session.setStatus(SessionStatus.ENDED_PAID); 105 // } 106 107 public int calculatePayment(int id){ 108 ParkingSession session = parkingSessionRepository.findByPssId(id); 95 public int calculatePayment(){ 96 ParkingSession session = getParkingSession(); 109 97 if(session==null){ 110 98 throw new IllegalStateException("No such session exists"); … … 182 170 parkingSession.getParkingSpace().setTaken(false); 183 171 registeredUserRepository.findAll().stream().filter(rp->rp.getSession().getStatus().equals(SessionStatus.ENDED_PAID)).forEach(rp->rp.setSession(null)); 172 guestRepository.findAll().stream().filter(g->g.getSession().getStatus().equals(SessionStatus.ENDED_PAID)).forEach(g->g.setSession(null)); 173 guestRepository.deleteAll(guestRepository.findAll().stream().filter(g-> g.getSession() == null).collect(Collectors.toList())); 184 174 parkingSessionRepository.deleteByPssId(parkingSession.getPssId()); 185 175 return true;
Note:
See TracChangeset
for help on using the changeset viewer.