Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MailService #449

Merged
merged 1 commit into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class MailServiceImpl implements MailService {
*
* @param mailSender of type JavaMailSender
* @param templateEngine of type templateEngine
* @param ticketService of type TicketService
*/
@Autowired
public MailServiceImpl(JavaMailSender mailSender, SpringTemplateEngine templateEngine, TicketService ticketService) {
Expand Down Expand Up @@ -193,6 +194,7 @@ private void sendMailWithContent(String recipientEmail, String subject, String c
message.addAttachment("ch-" + uniqueCode + ".pkpass", new ByteArrayResource(walletPass), "application/vnd.apple.pkpass");
} catch (Exception e) {
// Do nothing
System.out.println("Unable to generate wallet pass: " + e.getMessage());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public interface TicketService {
* @param currentCustomer of type Customer
* @param newCustomer of type Customer
*/
void transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException;
Ticket transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException;

/**
* Generate a QR code for a Ticket.
Expand All @@ -125,6 +125,12 @@ public interface TicketService {
*/
BufferedImage generateQrCode(Ticket ticket) throws WriterException, IllegalArgumentException;

/**
* Get Apple Wallet pass for a Ticket.
* @param ticket of type Ticket
* @return byte[]
* @throws TicketPassFailedException when pass is not generated
*/
byte[] getApplePass(Ticket ticket) throws TicketPassFailedException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.*;

import ch.wisv.events.core.service.event.EventService;
import ch.wisv.events.core.service.mail.MailService;
import ch.wisv.events.core.util.QrCode;
import com.google.zxing.WriterException;
import org.springframework.beans.factory.annotation.Value;
Expand All @@ -42,11 +41,6 @@ public class TicketServiceImpl implements TicketService {
*/
private final EventService eventService;

/**
* MailService.
*/
private final MailService mailService;

@Value("${links.passes}")
@NotNull
private String passesLink;
Expand All @@ -55,11 +49,10 @@ public class TicketServiceImpl implements TicketService {
* TicketServiceImpl constructor.
*
* @param ticketRepository of type TicketRepository
* @param mailService of type MailService
* @param eventService of type EventService
*/
public TicketServiceImpl(TicketRepository ticketRepository, EventService eventService, MailService mailService) {
public TicketServiceImpl(TicketRepository ticketRepository, EventService eventService) {
this.ticketRepository = ticketRepository;
this.mailService = mailService;
this.eventService = eventService;
}

Expand Down Expand Up @@ -239,7 +232,7 @@ public BufferedImage generateQrCode(Ticket ticket) throws IllegalArgumentExcepti
* @param currentCustomer of type Customer
* @param newCustomer of type Customer
*/
public void transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException {
public Ticket transfer(Ticket ticket, Customer currentCustomer, Customer newCustomer) throws TicketNotTransferableException {
// Get event from ticket product
Event event = null;
try {
Expand All @@ -259,10 +252,16 @@ public void transfer(Ticket ticket, Customer currentCustomer, Customer newCustom

ticketRepository.saveAndFlush(ticket);

// Send email to new customer
mailService.sendTransferConfirmation(ticket, currentCustomer, newCustomer);
return ticket;
}

/**
* Get the Apple Pass of a Ticket.
*
* @param ticket of type Ticket
* @return byte[]
* @throws TicketPassFailedException when the Apple Pass is not generated
*/
public byte[] getApplePass(Ticket ticket) throws TicketPassFailedException {
try {
RestTemplate restTemplate = new RestTemplate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import ch.wisv.events.core.model.ticket.Ticket;
import ch.wisv.events.core.service.auth.AuthenticationService;
import ch.wisv.events.core.service.customer.CustomerService;
import ch.wisv.events.core.service.mail.MailService;
import ch.wisv.events.core.service.order.OrderService;
import ch.wisv.events.core.service.ticket.TicketService;
import ch.wisv.events.core.util.QrCode;
Expand Down Expand Up @@ -38,6 +39,9 @@ public class WebshopTicketController extends WebshopController {
/** CustomerService. */
private final CustomerService customerService;

/** MailService. */
private final MailService mailService;

/**
* @param authenticationService of type AuthenticationService
* @param orderService of type OrderService
Expand All @@ -47,11 +51,13 @@ public WebshopTicketController(
AuthenticationService authenticationService,
CustomerService customerService,
OrderService orderService,
TicketService ticketService
TicketService ticketService,
MailService mailService
) {
super(orderService, authenticationService);
this.customerService = customerService;
this.ticketService = ticketService;
this.mailService = mailService;
}

/** Get ticket transfer page.
Expand Down Expand Up @@ -104,7 +110,11 @@ public String transferTicket(Model model, RedirectAttributes redirect, @PathVari
Customer newCustomer = customerService.getByEmail(email);

// Transfer the ticket
ticketService.transfer(ticket, currentCustomer, newCustomer);
Ticket newTicket = ticketService.transfer(ticket, currentCustomer, newCustomer);

// Send email to new customer
mailService.sendTransferConfirmation(newTicket, currentCustomer, newCustomer);


redirect.addFlashAttribute(MODEL_ATTR_SUCCESS, "Ticket has been transferred to " + newCustomer.getEmail());

Expand Down
Loading