Skip to content

Commit

Permalink
Merge branch 'master' into add-docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr-Tymoshenko authored Nov 23, 2023
2 parents a5fb631 + c0636f2 commit ca5c889
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ public class PaymentController {
@ResponseBody
@PreAuthorize("hasRole('CUSTOMER')")
@GetMapping
@Operation(summary = "Get all payments",
description = "Get all rentals for user, Pageable default: page = 0, size = 10")
@Operation(summary = "Get all user's payments",
description = """
Get all user's payments.
Pageable default: page = 0, size = 10""")
public List<PaymentDto> getAll(@PageableDefault(page = 0, size = 10) Pageable pageable,
Authentication authentication) {
User user = (User) authentication.getPrincipal();
Expand All @@ -59,22 +61,27 @@ public List<PaymentDto> searchPayments(@RequestParam(name = "status")
@ResponseBody
@PostMapping("/pay")
@PreAuthorize("hasRole('CUSTOMER')")
@Operation(summary = "Create ")
@Operation(summary = "Create session",
description = "Session is created to enable user to use Stripe")
public PaymentDto createPaymentIntent(@RequestBody @Valid CreatePaymentRequestDto requestDto) {
return paymentService.createPaymentSession(requestDto);
}

@GetMapping("/success")
@Operation(summary = "",
description = "")
@Operation(summary = "Page redirection on successful payment",
description = """
On finishing payment in Stripe user is
redirected to page on successful payment""")
public String success(@RequestParam String sessionId) {
paymentService.getSuccessfulPayment(sessionId);
return "success";
}

@GetMapping("/cancel")
@Operation(summary = "",
description = "Customer is redirected to a page when ")
@Operation(summary = "Page redirection on canceled payment",
description = """
On canceling payment in Stripe user is
redirected to page on canceled payment""")
public String afterCancelPayment(@RequestParam String sessionId) {
paymentService.getCancelledPayment(sessionId);
return "cancel";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class NotificationServiceImpl implements NotificationService {
public void sendMessageAboutCreatedRental(Rental rental) {
String carInfo = formatCarInfo(rental.getCar());
String dateInfo = formatDate(rental.getRentalDateTime(), rental.getReturnDateTime());
String name = "Dear, %s".formatted(rental.getUser().getFirstName());
String name = "Dear, %s 🙌".formatted(rental.getUser().getFirstName());
String message = name + System.lineSeparator()
+ "You rent car: " + System.lineSeparator()
+ carInfo + System.lineSeparator()
Expand All @@ -39,7 +39,7 @@ public void sendMessageAboutOverdueRental(Rental rental) {
String message = """
You should have returned car:
%s,
on %s
on 🕛 %s
""".formatted(formatCarInfo(car),
formatDateForOverdueRental(rental.getReturnDateTime(),
rental.getActualReturnDateTime()));
Expand Down Expand Up @@ -100,12 +100,16 @@ private String formatDateForOverdueRental(LocalDateTime returnDateTime,
String formattedActualReturnDateTime = actualReturnDateTime.format(formatter);
return """
%s,
but you return it on %s
but you return it on 🕑 %s
""".formatted(formattedReturnDateTime, formattedActualReturnDateTime);
}

public String formatCarInfo(Car car) {
return " model ➡ %s, brand ➡ %s, type ➡ %s"
return """
🚗
model ➡ %s,
brand ➡ %s,
type ➡ %s"""
.formatted(car.getModel(), car.getBrand(), car.getType().name());

}
Expand All @@ -114,9 +118,9 @@ private String formatDate(LocalDateTime rentalDateTime, LocalDateTime returnDate
String formattedRentalDateTime = rentalDateTime.format(formatter);
String formattedReturnDateTime = returnDateTime.format(formatter);
return """
Your rent day and time is: %s,
you should return car on %s.
If you don't return the car on time, you will be fined.
Your rent day and time is: %s,
you should return car on %s.
If you don't return the car on time, you will be fined 💸
""".formatted(formattedRentalDateTime, formattedReturnDateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ public class CarSharingBot extends TelegramLongPollingBot {
@Value("${bot.token}")
private String token;

/*
1. You should create your bot in Telegram (I will send you a video)
2. Save token of the bot to env. file and after as variable in application.properties
3. Save name of your bot to env. file and after as variable in application.properties
4. Run the app and click /start in your bot
5. In the console you will see chat id which you should add to
env. file and after as variable in application.properties (just numbers)
6. After all members do that we will delete this instruction
and functionality to get chat id in method onUpdateReceive
*/

@Value("${bot.chat}")
private String chatId;

Expand Down

0 comments on commit ca5c889

Please sign in to comment.