Skip to content

Commit

Permalink
#29 expose repository
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Jan 8, 2015
1 parent 25f1733 commit bef158b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
19 changes: 19 additions & 0 deletions src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@
import alfio.manager.support.OrderSummary;
import alfio.manager.user.UserManager;
import alfio.model.*;
import alfio.model.PromoCode.DiscountType;
import alfio.model.modification.EventModification;
import alfio.model.modification.EventWithStatistics;
import alfio.model.modification.TicketCategoryModification;
import alfio.model.modification.TicketCategoryWithStatistic;
import alfio.model.transaction.PaymentProxy;
import alfio.model.user.Organization;
import alfio.repository.EventRepository;
import alfio.repository.PromoCodeRepository;
import alfio.repository.SpecialPriceRepository;
import alfio.repository.TicketCategoryRepository;
import alfio.repository.TicketRepository;
import alfio.util.MonetaryUtil;
import lombok.Data;
import lombok.extern.log4j.Log4j2;

import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.tuple.Pair;
Expand Down Expand Up @@ -68,6 +71,7 @@ public class EventManager {
private final TicketRepository ticketRepository;
private final TicketReservationManager ticketReservationManager;
private final SpecialPriceRepository specialPriceRepository;
private final PromoCodeRepository promoCodeRepository;
private final LocationManager locationManager;
private final NamedParameterJdbcTemplate jdbc;

Expand All @@ -78,6 +82,7 @@ public EventManager(UserManager userManager,
TicketRepository ticketRepository,
TicketReservationManager ticketReservationManager,
SpecialPriceRepository specialPriceRepository,
PromoCodeRepository promoCodeRepository,
LocationManager locationManager,
NamedParameterJdbcTemplate jdbc) {
this.userManager = userManager;
Expand All @@ -86,6 +91,7 @@ public EventManager(UserManager userManager,
this.ticketRepository = ticketRepository;
this.ticketReservationManager = ticketReservationManager;
this.specialPriceRepository = specialPriceRepository;
this.promoCodeRepository = promoCodeRepository;
this.locationManager = locationManager;
this.jdbc = jdbc;
}
Expand Down Expand Up @@ -518,6 +524,19 @@ public void confirmPayment(String eventName, String reservationId, BigDecimal pa
public void deletePendingOfflinePayment(String eventName, String reservationId, String username) {
ticketReservationManager.deleteOfflinePayment(getSingleEvent(eventName, username), reservationId);
}


public void addPromoCode(String promoCode, int eventId, ZonedDateTime start, ZonedDateTime end, int discountAmount, DiscountType discountType) {
promoCodeRepository.addPromoCode(promoCode, eventId, start, end, discountAmount, discountType.toString());
}

public void deletePromoCode(int promoCodeId) {
promoCodeRepository.deletePromoCode(promoCodeId);
}

public List<PromoCode> findPromoCodesInEvent(int eventId) {
return promoCodeRepository.findAllInEvent(eventId);
}

@Data
private static final class GeolocationResult {
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/alfio/repository/PromoCodeRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ int addPromoCode(@Bind("promoCode") String promoCode,
@Bind("end") ZonedDateTime end,
@Bind("discountAmount") int discountAmount,
@Bind("discountType") String discountType);

@Query("select * from promo_code where event_id_fk = :eventId and promo_code = :promoCode")
PromoCode findPromoCodeInEvent(@Bind("eventId") int eventId, @Bind("promoCode") String promoCode);
}
6 changes: 3 additions & 3 deletions src/test/java/alfio/manager/EventManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class EventManagerTest {{
TicketCategory updated = Mockito.mock(TicketCategory.class);
TicketRepository ticketRepository = it.usesMock(TicketRepository.class);
NamedParameterJdbcTemplate jdbc = it.usesMock(NamedParameterJdbcTemplate.class);
EventManager eventManager = new EventManager(null, null, null, ticketRepository, null, null, null, jdbc);
EventManager eventManager = new EventManager(null, null, null, ticketRepository, null, null, null, null, jdbc);
when(original.getId()).thenReturn(20);
when(updated.getId()).thenReturn(30);
when(original.getPriceInCents()).thenReturn(1000);
Expand Down Expand Up @@ -84,7 +84,7 @@ public class EventManagerTest {{

describe("handlePriceChange", it -> {
TicketRepository ticketRepository = it.usesMock(TicketRepository.class);
EventManager eventManager = new EventManager(null, null, null, ticketRepository, null, null, null, null);
EventManager eventManager = new EventManager(null, null, null, ticketRepository, null, null, null, null, null);
TicketCategory original = Mockito.mock(TicketCategory.class);
TicketCategory updated = Mockito.mock(TicketCategory.class);

Expand Down Expand Up @@ -120,7 +120,7 @@ public class EventManagerTest {{
describe("handleTokenModification", it -> {
SpecialPriceRepository specialPriceRepository = it.usesMock(SpecialPriceRepository.class);
NamedParameterJdbcTemplate jdbc = it.usesMock(NamedParameterJdbcTemplate.class);
EventManager eventManager = new EventManager(null, null, null, null, null, specialPriceRepository, null, jdbc);
EventManager eventManager = new EventManager(null, null, null, null, null, specialPriceRepository, null, null, jdbc);
TicketCategory original = Mockito.mock(TicketCategory.class);
TicketCategory updated = Mockito.mock(TicketCategory.class);

Expand Down

0 comments on commit bef158b

Please sign in to comment.