Skip to content

Commit

Permalink
Merge pull request #97 from TTBMP/release/v1.0
Browse files Browse the repository at this point in the history
Release/v1.0
  • Loading branch information
buracchi authored Jun 27, 2021
2 parents 5ab354d + dec11f4 commit 89a7457
Show file tree
Hide file tree
Showing 82 changed files with 664 additions and 789 deletions.
12 changes: 12 additions & 0 deletions app/src/main/java/com/ttbmp/cinehub/app/CinehubException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.ttbmp.cinehub.app;

/**
* @author Fabio Buracchi
*/
public class CinehubException extends Exception {

public CinehubException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import com.ttbmp.cinehub.app.repository.user.JdbcUserRepository;
import com.ttbmp.cinehub.app.repository.user.UserRepository;
import com.ttbmp.cinehub.app.service.email.EmailService;
import com.ttbmp.cinehub.app.service.email.MockEmailService;
import com.ttbmp.cinehub.app.service.email.EmailServiceAdapter;
import com.ttbmp.cinehub.app.service.movieapi.MovieApiService;
import com.ttbmp.cinehub.app.service.movieapi.TheMovieDbApiServiceAdapter;
import com.ttbmp.cinehub.app.service.payment.PaymentService;
Expand All @@ -50,7 +50,7 @@ public ServiceLocator() {
}

protected void addServicesFactory() {
serviceFactoryMap.put(EmailService.class, MockEmailService::new);
serviceFactoryMap.put(EmailService.class, EmailServiceAdapter::new);
serviceFactoryMap.put(MovieApiService.class, TheMovieDbApiServiceAdapter::new);
serviceFactoryMap.put(PaymentService.class, StripeServiceAdapter::new);
serviceFactoryMap.put(SecurityService.class, () -> new FirebaseAuthSecurityServiceAdapter(this));
Expand Down
58 changes: 58 additions & 0 deletions app/src/main/java/com/ttbmp/cinehub/app/dto/EmployeeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.ttbmp.cinehub.app.dto;

import com.ttbmp.cinehub.domain.employee.Employee;
import com.ttbmp.cinehub.domain.employee.Projectionist;
import com.ttbmp.cinehub.domain.employee.Usher;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;
import lombok.experimental.FieldDefaults;

/**
* @author Massimo Mazzetti
*/
@Getter
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@ToString
@EqualsAndHashCode
public class EmployeeDto {

String id;
String name;
String surname;
CinemaDto cinema;
EmployeeRole role;

public EmployeeDto(Employee employee) {
this.id = employee.getId();
this.name = employee.getName();
this.surname = employee.getSurname();
this.cinema = new CinemaDto(employee.getCinema());
if (employee instanceof Projectionist) {
this.role = EmployeeRole.PROJECTIONIST;
} else if (employee instanceof Usher) {
this.role = EmployeeRole.USHER;
} else {
throw new IllegalStateException("Unexpected value: " + employee);
}
}

public enum EmployeeRole {
PROJECTIONIST("Projectionist"),
USHER("Usher");

private final String name;

EmployeeRole(final String name) {
this.name = name;
}

@Override
public String toString() {
return name;
}

}

}

This file was deleted.

This file was deleted.

This file was deleted.

19 changes: 0 additions & 19 deletions app/src/main/java/com/ttbmp/cinehub/app/dto/employee/UsherDto.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public void setCinema(Cinema cinema) {
super.setCinema(cinema);
}


@Override
public List<Shift> getShiftList() {
if (!isShiftListLoaded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*/
public interface EmailService {

void sendMail(EmailServiceRequest emailServiceRequest);
void sendMail(EmailServiceRequest emailServiceRequest) throws EmailServiceException;

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package com.ttbmp.cinehub.app.service.email;

import com.ttbmp.cinehub.service.email.emailservice.SendEmailService;
import com.ttbmp.cinehub.service.email.emailservice.SendEmailServiceException;

public class EmailServiceAdapter implements EmailService {

private final SendEmailService service = new SendEmailService();

@Override
public void sendMail(EmailServiceRequest emailServiceRequest) {
service.sendMail(emailServiceRequest.getEmail());
public void sendMail(EmailServiceRequest request) throws EmailServiceException {
try {
service.sendMail(request.getEmail(), request.getObject());
} catch (SendEmailServiceException e) {
throw new EmailServiceException(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ttbmp.cinehub.app.service.email;

public class EmailServiceException extends Exception {

public EmailServiceException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.ttbmp.cinehub.app.repository.seat.SeatRepository;
import com.ttbmp.cinehub.app.repository.ticket.TicketRepository;
import com.ttbmp.cinehub.app.service.email.EmailService;
import com.ttbmp.cinehub.app.service.email.EmailServiceException;
import com.ttbmp.cinehub.app.service.email.EmailServiceRequest;
import com.ttbmp.cinehub.app.service.payment.PayServiceRequest;
import com.ttbmp.cinehub.app.service.payment.PaymentService;
Expand Down Expand Up @@ -157,17 +158,7 @@ public void pay(PaymentRequest request) {
presenter.presentSeatAlreadyBookedError(new SeatErrorReply("The place has already been booked"));
} else {
var ticket = new Ticket(0, projection.getBasePrice(), customer, seat, projection);
//-DECORATOR-//
if (Boolean.TRUE.equals(request.getTicketOption().getOpenBarOption())) {
ticket = new TicketOpenBar(ticket);
}
if (Boolean.TRUE.equals(request.getTicketOption().getMagicBoxOption())) {
ticket = new TicketMagicBox(ticket);
}
if (Boolean.TRUE.equals(request.getTicketOption().getSkipLineOption())) {
ticket = new TicketSkipLine(ticket);
}
//---------//
ticket = addFunctionality(ticket, request);
paymentService.pay(new PayServiceRequest(
customer.getEmail(),
customer.getName(),
Expand All @@ -177,15 +168,39 @@ public void pay(PaymentRequest request) {
request.getCreditCard().getCreditCardExpirationDate()
));
ticketRepository.saveTicket(ticket);
emailService.sendMail(new EmailServiceRequest(request.getEmail(), "Payment receipt"));
var message = "You bought the ticket at the price of "
+ ticket.getPrice() +
"€ for the hours "
+ projection.getStartTime() +
" in the hall " +
projection.getHall().getName() +
"\nSee you soon!";
emailService.sendMail(new EmailServiceRequest(request.getEmail(), message));
presenter.presentTicket(new TicketReply(new TicketDto(ticket)));
}
} catch (PaymentServiceException e) {
presenter.presentPaymentServiceException(e);
} catch (EmailServiceException e) {
presenter.presentSendEmailServiceException(e);
}
});
}

private Ticket addFunctionality(Ticket ticket, PaymentRequest request) {
//-DECORATOR-//
if (Boolean.TRUE.equals(request.getTicketOption().getOpenBarOption())) {
ticket = new TicketOpenBar(ticket);
}
if (Boolean.TRUE.equals(request.getTicketOption().getMagicBoxOption())) {
ticket = new TicketMagicBox(ticket);
}
if (Boolean.TRUE.equals(request.getTicketOption().getSkipLineOption())) {
ticket = new TicketSkipLine(ticket);
}
return ticket;
}


private void semanticValidatePay(PaymentRequest request, Customer customer, Projection projection, Seat seat) throws Request.InvalidRequestException {
if (customer == null) {
request.addError(PaymentRequest.MISSING_CUSTOMER_ERROR);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ttbmp.cinehub.app.usecase.buyticket;

import com.ttbmp.cinehub.app.service.email.EmailServiceException;
import com.ttbmp.cinehub.app.service.payment.PaymentServiceException;
import com.ttbmp.cinehub.app.service.security.SecurePresenter;
import com.ttbmp.cinehub.app.usecase.buyticket.reply.*;
Expand All @@ -23,4 +24,5 @@ public interface BuyTicketPresenter extends SecurePresenter {

void presentPaymentServiceException(PaymentServiceException exception);

void presentSendEmailServiceException(EmailServiceException e);
}
Loading

0 comments on commit 89a7457

Please sign in to comment.