-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OVERALL FIXING] Fixed some issues related to Payment and Rental (#33)
* adjusted payment service * added check data method * reset default data * fixed the problem with correct calculating of amount * added scheduler service class and made minor adjustments * reset default properties * resolved conflict * added cron param * implemented beta scheduling * updated from remote branch * adjusted payment and scheduler * fixed overall issues and adjusted payment process * fixed mistakes
- Loading branch information
1 parent
70cb59b
commit a2bf40a
Showing
22 changed files
with
287 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/project/carsharingapp/exception/NotValidPaymentProcessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.project.carsharingapp.exception; | ||
|
||
public class NotValidPaymentProcessException extends RuntimeException { | ||
public NotValidPaymentProcessException(String message) { | ||
super(message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/com/project/carsharingapp/repository/PaymentRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
package com.project.carsharingapp.repository; | ||
|
||
import com.project.carsharingapp.model.Payment; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
public interface PaymentRepository extends JpaRepository<Payment, Long> { | ||
@Query("FROM Payment p LEFT JOIN FETCH p.rental") | ||
Page<Payment> findAll(Pageable pageable); | ||
|
||
@Query("FROM Payment p LEFT JOIN FETCH p.rental") | ||
List<Payment> findAll(); | ||
|
||
Optional<Payment> findBySessionId(String sessionId); | ||
|
||
Optional<Payment> findByRentalId(Long rentalId); | ||
|
||
boolean existsByRentalIdAndStatus(Long rentalId, Payment.Status status); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/com/project/carsharingapp/service/SchedulerService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.project.carsharingapp.service; | ||
|
||
public interface SchedulerService { | ||
void checkOverdueRentals(); | ||
|
||
void checkExpiredPaymentSessions(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/main/java/com/project/carsharingapp/service/impl/SchedulerServiceImp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package com.project.carsharingapp.service.impl; | ||
|
||
import com.project.carsharingapp.model.Payment; | ||
import com.project.carsharingapp.model.User; | ||
import com.project.carsharingapp.repository.PaymentRepository; | ||
import com.project.carsharingapp.repository.UserRepository; | ||
import com.project.carsharingapp.service.NotificationService; | ||
import com.project.carsharingapp.service.RentalService; | ||
import com.project.carsharingapp.service.SchedulerService; | ||
import com.project.carsharingapp.service.payment.PaymentService; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class SchedulerServiceImp implements SchedulerService { | ||
private static final String OVERDUE_RENTAL_MESSAGE = "Your rental is expected to be " | ||
+ "overdue! Rental id: "; | ||
private final RentalService rentalService; | ||
private final PaymentService paymentService; | ||
private final UserRepository userRepository; | ||
private final PaymentRepository paymentRepository; | ||
private final NotificationService notificationService; | ||
|
||
@Override | ||
@Scheduled(cron = "0/1 0 * * * MON-FRI") | ||
public void checkOverdueRentals() { | ||
rentalService.getAllOverdueRentals() | ||
.forEach( | ||
(rentalDto) -> { | ||
User user = userRepository.findUserById(rentalDto.getUserId()).get(); | ||
notificationService.sendMessage(user.getTelegramChatId(), | ||
OVERDUE_RENTAL_MESSAGE + rentalDto.getId()); | ||
} | ||
); | ||
} | ||
|
||
@Override | ||
@Scheduled(cron = "0 * * * * *") | ||
public void checkExpiredPaymentSessions() { | ||
List<Payment> allExpiredPayments = paymentService.getAllExpiredPayments(); | ||
allExpiredPayments.forEach(payment -> payment.setStatus(Payment.Status.EXPIRED)); | ||
paymentRepository.saveAll(allExpiredPayments); | ||
} | ||
} |
Oops, something went wrong.