Changeset bfc49f4 for sources/app/src/main/java/parkup/services
- Timestamp:
- 02/12/22 17:21:18 (3 years ago)
- Branches:
- master
- Children:
- b2e6513
- Parents:
- 7bb19d4
- Location:
- sources/app/src/main/java/parkup/services
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.