Changeset bfc49f4


Ignore:
Timestamp:
02/12/22 17:21:18 (2 years ago)
Author:
andrejTavchioski <andrej.tavchioski@…>
Branches:
master
Children:
b2e6513
Parents:
7bb19d4
Message:

paying session fix

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  
    1414import parkup.configs.CustomAuthorizationFilter;
    1515import parkup.services.AdministratorService;
     16import parkup.services.GuestService;
    1617import parkup.services.RegisteredUserService;
    1718import parkup.services.WorkerService;
     
    2627        private final RegisteredUserService registeredUserService;
    2728        private final AdministratorService administratorService;
     29        private final GuestService guestService;
    2830
    29         public WebSecurityConfig(WorkerService workerService, BCryptPasswordEncoder bCryptPasswordEncoder, RegisteredUserService registeredUserService, AdministratorService administratorService) {
     31        public WebSecurityConfig(WorkerService workerService, BCryptPasswordEncoder bCryptPasswordEncoder, RegisteredUserService registeredUserService, AdministratorService administratorService, GuestService guestService) {
    3032            this.workerService = workerService;
    3133            this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    3234            this.registeredUserService = registeredUserService;
    3335            this.administratorService = administratorService;
     36            this.guestService = guestService;
    3437        }
    3538
     
    3942            auth.userDetailsService(workerService).passwordEncoder(bCryptPasswordEncoder);
    4043            auth.userDetailsService(administratorService).passwordEncoder(bCryptPasswordEncoder);
    41 
     44            auth.userDetailsService(guestService).passwordEncoder(bCryptPasswordEncoder);
    4245        }
    4346
  • sources/app/src/main/java/parkup/controllers/ParkingSessionController.java

    r7bb19d4 rbfc49f4  
    4040        return this.parkingSessionService.verifyParkingSession(parkingSessionId,parkingSpaceName);
    4141    }
    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();
    4545    }
    4646    @PutMapping("/parkingSession/pay")
    47     public boolean payParkingSession(@RequestParam String expireDate){
     47    public boolean payParkingSession(@RequestParam(required = false) String expireDate){
    4848        return this.parkingSessionService.payParkingSession(expireDate);
    4949    }
  • sources/app/src/main/java/parkup/services/GuestService.java

    r7bb19d4 rbfc49f4  
    44import java.util.Optional;
    55import org.springframework.beans.factory.annotation.Autowired;
     6import org.springframework.security.core.userdetails.UserDetails;
     7import org.springframework.security.core.userdetails.UserDetailsService;
     8import org.springframework.security.core.userdetails.UsernameNotFoundException;
    69import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
    710import org.springframework.stereotype.Service;
     
    1013
    1114@Service
    12 public class GuestService {
     15public class GuestService implements UserDetailsService {
    1316    private final GuestRepository guestRepository;
    1417    private final BCryptPasswordEncoder passwordEncoder;
     
    3437            throw new IllegalStateException("Email already taken, try adding a guest with a different valid email address");
    3538        } else {
    36 //            guest.setPassword(passwordEncoder.encode(Math.random()));
     39            double random = Math.random()*100;
     40            guest.setPassword(passwordEncoder.encode(Double.toString(random)));
    3741            this.guestRepository.save(guest);
    3842        }
     
    4751        }
    4852    }
     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    }
    4960}
  • sources/app/src/main/java/parkup/services/ParkingSessionService.java

    r7bb19d4 rbfc49f4  
    9393
    9494    }
    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();
    10997        if(session==null){
    11098            throw new IllegalStateException("No such session exists");
     
    182170        parkingSession.getParkingSpace().setTaken(false);
    183171        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()));
    184174        parkingSessionRepository.deleteByPssId(parkingSession.getPssId());
    185175        return true;
Note: See TracChangeset for help on using the changeset viewer.