Changeset 9bcad23
- Timestamp:
- 01/25/25 23:12:23 (3 months ago)
- Branches:
- master
- Children:
- 2a2614e
- Parents:
- d9884b2
- Location:
- ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo
- Files:
-
- 2 added
- 9 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/model/exceptions/EmailNotFoundException.java
rd9884b2 r9bcad23 3 3 public class EmailNotFoundException extends RuntimeException { 4 4 public EmailNotFoundException(String username) { 5 super( String.format("User with email: %s was not found", username));5 super("User with email: " + username + " was not found"); 6 6 } 7 7 } -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/model/exceptions/ReservationNotFoundException.java
rd9884b2 r9bcad23 1 1 package mk.ukim.finki.it.reservengo.model.exceptions; 2 2 3 public class Reservation IdNotFoundException extends RuntimeException {4 public Reservation IdNotFoundException(Long id) {3 public class ReservationNotFoundException extends RuntimeException { 4 public ReservationNotFoundException(Long id) { 5 5 super("Reservation with ID " + id + " was not found"); 6 6 } -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/service/impl/AdminServiceImpl.java
rd9884b2 r9bcad23 2 2 3 3 import mk.ukim.finki.it.reservengo.model.Local; 4 import mk.ukim.finki.it.reservengo.model.exceptions.LocalNotFoundException; 4 5 import mk.ukim.finki.it.reservengo.repository.LocalRepository; 5 6 import mk.ukim.finki.it.reservengo.service.intf.AdminService; … … 23 24 @Override 24 25 public void deleteLocal(Long id) { 25 localRepository.deleteById(id); 26 Local local = localRepository.findById(id).orElseThrow(() -> new LocalNotFoundException(id)); 27 localRepository.delete(local); 26 28 } 27 29 } -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/service/impl/AuthServiceImpl.java
rd9884b2 r9bcad23 40 40 customerRepository.save(customer); 41 41 String jwt = jwtService.generateTokenNoClaims(customer); 42 43 System.out.println(jwt);44 System.out.println(customer);45 42 46 43 return new JWTAuthenticationResponse( -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/service/impl/CustomerServiceImpl.java
rd9884b2 r9bcad23 1 1 package mk.ukim.finki.it.reservengo.service.impl; 2 2 3 import jakarta.transaction.Transactional; 3 4 import mk.ukim.finki.it.reservengo.model.Customer; 5 import mk.ukim.finki.it.reservengo.model.Local; 6 import mk.ukim.finki.it.reservengo.model.exceptions.CustomerNotFoundException; 7 import mk.ukim.finki.it.reservengo.model.exceptions.LocalNotFoundException; 4 8 import mk.ukim.finki.it.reservengo.repository.CustomerRepository; 9 import mk.ukim.finki.it.reservengo.repository.LocalRepository; 5 10 import mk.ukim.finki.it.reservengo.service.intf.CustomerService; 6 11 import org.springframework.stereotype.Service; 12 13 import java.util.List; 7 14 8 15 @Service 9 16 public class CustomerServiceImpl implements CustomerService { 10 17 private final CustomerRepository customerRepository; 18 private final LocalRepository localRepository; 11 19 12 public CustomerServiceImpl(CustomerRepository customerRepository ) {20 public CustomerServiceImpl(CustomerRepository customerRepository, LocalRepository localRepository) { 13 21 this.customerRepository = customerRepository; 22 this.localRepository = localRepository; 14 23 } 15 24 16 25 @Override 17 26 public Customer getCustomerProfile(Long id) { 18 return customerRepository.findById(id).orElseThrow(RuntimeException::new); 27 return customerRepository.findById(id).orElseThrow(() -> new CustomerNotFoundException(id)); 28 } 29 30 @Override 31 public List<Local> listFavouriteLocals(Long id) { 32 Customer customer = customerRepository.findById(id).orElseThrow(() -> new CustomerNotFoundException(id)); 33 return customer.getFavouriteLocals(); 34 } 35 36 @Override 37 public void addFavouriteLocal(Long userId, Long localId) { 38 Customer customer = customerRepository.findById(userId).orElseThrow(() -> new CustomerNotFoundException(userId)); 39 Local local = localRepository.findById(localId).orElseThrow(() -> new LocalNotFoundException(localId)); 40 41 if (!customer.getFavouriteLocals().contains(local)) { 42 customer.getFavouriteLocals().add(local); 43 } 44 45 customerRepository.save(customer); 46 } 47 48 @Override 49 public void removeFavouriteLocal(Long userId, Long localId) { 50 Customer customer = customerRepository.findById(userId).orElseThrow(() -> new CustomerNotFoundException(userId)); 51 Local local = localRepository.findById(localId).orElseThrow(() -> new LocalNotFoundException(localId)); 52 53 customer.getFavouriteLocals().remove(local); 54 55 customerRepository.save(customer); 19 56 } 20 57 } -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/service/impl/ReservationServiceImpl.java
rd9884b2 r9bcad23 2 2 3 3 import mk.ukim.finki.it.reservengo.model.Reservation; 4 import mk.ukim.finki.it.reservengo.model.exceptions.Reservation IdNotFoundException;4 import mk.ukim.finki.it.reservengo.model.exceptions.ReservationNotFoundException; 5 5 import mk.ukim.finki.it.reservengo.repository.ReservationRepository; 6 6 import mk.ukim.finki.it.reservengo.service.intf.ReservationService; … … 21 21 @Override 22 22 public Reservation getReservationById(Long id) { 23 return this.reservationRepository.findById(id).orElseThrow(() -> new Reservation IdNotFoundException(id));23 return this.reservationRepository.findById(id).orElseThrow(() -> new ReservationNotFoundException(id)); 24 24 } 25 25 -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/service/intf/AdminService.java
rd9884b2 r9bcad23 2 2 3 3 public interface AdminService { 4 5 4 void addLocal(String name); 6 5 -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/service/intf/CustomerService.java
rd9884b2 r9bcad23 2 2 3 3 import mk.ukim.finki.it.reservengo.model.Customer; 4 import mk.ukim.finki.it.reservengo.model.Local; 5 6 import java.util.List; 4 7 5 8 public interface CustomerService { 6 9 Customer getCustomerProfile(Long id); 10 11 List<Local> listFavouriteLocals(Long id); 12 13 void addFavouriteLocal(Long userId, Long localId); 14 15 void removeFavouriteLocal(Long userId, Long localId); 7 16 } -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/web/CustomerController.java
rd9884b2 r9bcad23 2 2 3 3 import mk.ukim.finki.it.reservengo.model.Customer; 4 import mk.ukim.finki.it.reservengo.model.Local; 4 5 import mk.ukim.finki.it.reservengo.model.Reservation; 5 6 import mk.ukim.finki.it.reservengo.model.User; … … 25 26 } 26 27 27 @GetMapping28 public ResponseEntity<?> getCustomer() {29 return ResponseEntity.ok("ok");30 }31 32 28 @GetMapping("/profile") 33 29 public ResponseEntity<?> getUserProfile(@AuthenticationPrincipal User user) { 34 System.out.println(user.getId());35 30 Customer userProfile = customerService.getCustomerProfile(user.getId()); 36 31 return ResponseEntity.ok(userProfile); … … 42 37 return ResponseEntity.ok(customerReservations); 43 38 } 39 40 @GetMapping("/favourite-locals") 41 public ResponseEntity<?> listFavouriteLocals(@AuthenticationPrincipal User user) { 42 List<Local> favouriteLocals = customerService.listFavouriteLocals(user.getId()); 43 return ResponseEntity.ok(favouriteLocals); 44 } 45 46 @PostMapping("/favourite-locals/add/{id}") 47 public ResponseEntity<?> addFavouriteLocal(@AuthenticationPrincipal User user, @PathVariable Long id) { 48 customerService.addFavouriteLocal(user.getId(), id); 49 return ResponseEntity.ok().build(); 50 } 51 52 @PostMapping("/favourite-locals/remove/{id}") 53 public ResponseEntity<?> removeFavouriteLocal(@AuthenticationPrincipal User user, @PathVariable Long id) { 54 customerService.removeFavouriteLocal(user.getId(), id); 55 return ResponseEntity.ok().build(); 56 } 44 57 } -
ReserveNGo-backend/src/main/java/mk/ukim/finki/it/reservengo/web/ReservationController.java
rd9884b2 r9bcad23 26 26 27 27 @PostMapping("/reservations/{id}/status") 28 public ResponseEntity<?> updateReservationStatus(@PathVariable Long id, 29 @RequestParam ReservationStatus status) { 28 public ResponseEntity<?> updateReservationStatus(@PathVariable Long id, @RequestParam ReservationStatus status) { 30 29 Reservation reservation = reservationService.getReservationById(id); 31 30 reservation.setStatus(status);
Note:
See TracChangeset
for help on using the changeset viewer.