Skip to content

Commit

Permalink
#111 initial stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed May 17, 2017
1 parent 08eab4d commit df42fc9
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public ResponseEntity<EventModification.AdditionalService> insert(@PathVariable(
.map(event -> {
AffectedRowCountAndKey<Integer> result = additionalServiceRepository.insert(eventId, Optional.ofNullable(additionalService.getPrice()).map(MonetaryUtil::unitToCents).orElse(0), additionalService.isFixPrice(),
additionalService.getOrdinal(), additionalService.getAvailableQuantity(), additionalService.getMaxQtyPerOrder(), additionalService.getInception().toZonedDateTime(event.getZoneId()),
additionalService.getExpiration().toZonedDateTime(event.getZoneId()), additionalService.getVat(), additionalService.getVatType());
additionalService.getExpiration().toZonedDateTime(event.getZoneId()), additionalService.getVat(), additionalService.getVatType(), additionalService.getType());
Validate.isTrue(result.getAffectedRowCount() == 1, "too many records updated");
int id = result.getKey();
Stream.concat(additionalService.getTitle().stream(), additionalService.getDescription().stream()).
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/alfio/manager/AdminReservationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class AdminReservationManager {
private final NotificationManager notificationManager;
private final MessageSource messageSource;
private final TemplateManager templateManager;
private final AdditionalServiceItemRepository additionalServiceItemRepository;

@Autowired
public AdminReservationManager(EventManager eventManager,
Expand All @@ -101,7 +102,8 @@ public AdminReservationManager(EventManager eventManager,
PaymentManager paymentManager,
NotificationManager notificationManager,
MessageSource messageSource,
TemplateManager templateManager) {
TemplateManager templateManager,
AdditionalServiceItemRepository additionalServiceItemRepository) {
this.eventManager = eventManager;
this.ticketReservationManager = ticketReservationManager;
this.ticketCategoryRepository = ticketCategoryRepository;
Expand All @@ -117,6 +119,7 @@ public AdminReservationManager(EventManager eventManager,
this.notificationManager = notificationManager;
this.messageSource = messageSource;
this.templateManager = templateManager;
this.additionalServiceItemRepository = additionalServiceItemRepository;
}

public Result<Triple<TicketReservation, List<Ticket>, Event>> confirmReservation(String eventName, String reservationId, String username) {
Expand Down Expand Up @@ -470,6 +473,7 @@ public void removeTickets(String eventName, String reservationId, List<Integer>

if(tickets.size() - ticketIds.size() <= 0) {
markAsCancelled(reservation);
additionalServiceItemRepository.updateItemsStatusWithReservationUUID(reservation.getId(), AdditionalServiceItem.AdditionalServiceItemStatus.CANCELLED);
}
});
}
Expand All @@ -489,6 +493,8 @@ public void removeReservation(String eventName, String reservationId, boolean re

removeTicketsFromReservation(e, tickets.stream().map(Ticket::getId).collect(toList()), notify, username);

additionalServiceItemRepository.updateItemsStatusWithReservationUUID(reservation.getId(), AdditionalServiceItem.AdditionalServiceItemStatus.CANCELLED);

if(refund && reservation.getPaymentMethod() != null && reservation.getPaymentMethod().isSupportRefund()) {
//fully refund
paymentManager.refund(reservation, e, Optional.empty());
Expand Down Expand Up @@ -518,7 +524,6 @@ private void removeTicketsFromReservation(Event event, List<Integer> ticketIds,
if(StringUtils.isNotBlank(t.getEmail())) {
sendTicketHasBeenRemoved(event, o, t);
}

});
}

Expand All @@ -536,7 +541,6 @@ private void sendTicketHasBeenRemoved(Event event, Organization organization, Ti
}

private void markAsCancelled(TicketReservation ticketReservation) {
//TODO: eventually, send email
ticketReservationRepository.updateTicketStatus(ticketReservation.getId(), TicketReservationStatus.CANCELLED.toString());
}

Expand All @@ -548,11 +552,7 @@ private void handleTicketsRefund(List<Integer> toRefund, Event e, TicketReservat
for(Integer toRefundId : toRefund) {
int toBeRefunded = ticketsById.get(toRefundId).getFinalPriceCts();
if(toBeRefunded > 0) {
if(paymentManager.refund(reservation, e, Optional.of(toBeRefunded))) {
//TODO: save refunded amount in reservation
} else {
//
}
paymentManager.refund(reservation, e, Optional.of(toBeRefunded));
}
}
//
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/alfio/manager/EventManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public void toggleActiveFlag(int id, String username, boolean activate) {
private void createAllAdditionalServices(int eventId, List<EventModification.AdditionalService> additionalServices, ZoneId zoneId) {
Optional.ofNullable(additionalServices)
.ifPresent(list -> list.forEach(as -> {
AffectedRowCountAndKey<Integer> service = additionalServiceRepository.insert(eventId, Optional.ofNullable(as.getPrice()).map(MonetaryUtil::unitToCents).orElse(0), as.isFixPrice(), as.getOrdinal(), as.getAvailableQuantity(), as.getMaxQtyPerOrder(), as.getInception().toZonedDateTime(zoneId), as.getExpiration().toZonedDateTime(zoneId), as.getVat(), as.getVatType());
AffectedRowCountAndKey<Integer> service = additionalServiceRepository.insert(eventId, Optional.ofNullable(as.getPrice()).map(MonetaryUtil::unitToCents).orElse(0), as.isFixPrice(), as.getOrdinal(), as.getAvailableQuantity(), as.getMaxQtyPerOrder(), as.getInception().toZonedDateTime(zoneId), as.getExpiration().toZonedDateTime(zoneId), as.getVat(), as.getVatType(), as.getType());
as.getTitle().forEach(insertAdditionalServiceDescription(service.getKey()));
as.getDescription().forEach(insertAdditionalServiceDescription(service.getKey()));
}));
Expand Down Expand Up @@ -253,7 +253,13 @@ private Integer findAdditionalService(Event event, EventModification.AdditionalS
ZoneId utc = ZoneId.of("UTC");
int eventId = event.getId();
String checksum = new AdditionalService(0, eventId, as.isFixPrice(), as.getOrdinal(), as.getAvailableQuantity(),
as.getMaxQtyPerOrder(), as.getInception().toZonedDateTime(event.getZoneId()).withZoneSameInstant(utc), as.getExpiration().toZonedDateTime(event.getZoneId()).withZoneSameInstant(utc), as.getVat(), as.getVatType(), Optional.ofNullable(as.getPrice()).map(MonetaryUtil::unitToCents).orElse(0)).getChecksum();
as.getMaxQtyPerOrder(),
as.getInception().toZonedDateTime(event.getZoneId()).withZoneSameInstant(utc),
as.getExpiration().toZonedDateTime(event.getZoneId()).withZoneSameInstant(utc),
as.getVat(),
as.getVatType(),
Optional.ofNullable(as.getPrice()).map(MonetaryUtil::unitToCents).orElse(0),
as.getType()).getChecksum();
return additionalServiceRepository.loadAllForEvent(eventId).stream().filter(as1 -> as1.getChecksum().equals(checksum)).findFirst().map(AdditionalService::getId).orElse(null);
}

Expand Down
8 changes: 5 additions & 3 deletions src/main/java/alfio/model/AdditionalService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum VatType {
}

public enum AdditionalServiceType {
DONATION
DONATION, SUPPLEMENT
}

private final int id;
Expand All @@ -53,7 +53,7 @@ public enum AdditionalServiceType {
private final ZonedDateTime utcExpiration;
private final BigDecimal vat;
private final VatType vatType;
private final AdditionalServiceType type = AdditionalServiceType.DONATION;
private final AdditionalServiceType type;

private final Integer srcPriceCts;

Expand All @@ -67,7 +67,8 @@ public AdditionalService(@Column("id") int id,
@Column("expiration_ts") ZonedDateTime utcExpiration,
@Column("vat") BigDecimal vat,
@Column("vat_type") VatType vatType,
@Column("src_price_cts") Integer srcPriceCts) {
@Column("src_price_cts") Integer srcPriceCts,
@Column("service_type") AdditionalServiceType type) {
this.id = id;
this.eventId = eventId;
this.fixPrice = fixPrice;
Expand All @@ -79,6 +80,7 @@ public AdditionalService(@Column("id") int id,
this.vat = vat;
this.vatType = vatType;
this.srcPriceCts = srcPriceCts;
this.type = type;
}

public ZonedDateTime getInception(ZoneId zoneId) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/alfio/model/modification/EventModification.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package alfio.model.modification;

import alfio.model.AdditionalService;
import alfio.model.Event;
import alfio.model.PriceContainer;
import alfio.model.modification.support.LocationDescriptor;
Expand Down Expand Up @@ -219,6 +220,7 @@ public static class AdditionalService {
private final List<AdditionalServiceText> description;
private final BigDecimal finalPrice;
private final String currencyCode;
private final alfio.model.AdditionalService.AdditionalServiceType type = alfio.model.AdditionalService.AdditionalServiceType.DONATION;

@JsonCreator
public AdditionalService(@JsonProperty("id") Integer id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ public interface AdditionalServiceRepository {
@Query("delete from additional_service where id = :id and event_id_fk = :eventId")
int delete(@Bind("id") int id, @Bind("eventId") int eventId);

@Query("insert into additional_service (event_id_fk, fix_price, ordinal, available_qty, max_qty_per_order, inception_ts, expiration_ts, vat, vat_type, price_cts, src_price_cts) " +
"values(:eventId, :fixPrice, :ordinal, :availableQty, :maxQtyPerOrder, :inceptionTs, :expirationTs, :vat, :vatType, 0, :srcPriceCts)")
@Query("insert into additional_service (event_id_fk, fix_price, ordinal, available_qty, max_qty_per_order, inception_ts, expiration_ts, vat, vat_type, price_cts, src_price_cts, service_type) " +
"values(:eventId, :fixPrice, :ordinal, :availableQty, :maxQtyPerOrder, :inceptionTs, :expirationTs, :vat, :vatType, 0, :srcPriceCts, :type)")
@AutoGeneratedKey("id")
AffectedRowCountAndKey<Integer> insert(@Bind("eventId") int eventId, @Bind("srcPriceCts") int srcPriceCts, @Bind("fixPrice") boolean fixPrice,
@Bind("ordinal") int ordinal, @Bind("availableQty") int availableQuantity, @Bind("maxQtyPerOrder") int maxQtyPerOrder,
@Bind("inceptionTs") ZonedDateTime inception, @Bind("expirationTs") ZonedDateTime expiration, @Bind("vat") BigDecimal vat,
@Bind("vatType") AdditionalService.VatType vatType);
@Bind("vatType") AdditionalService.VatType vatType,
@Bind("type")AdditionalService.AdditionalServiceType type);

@Query("update additional_service set fix_price = :fixPrice, ordinal = :ordinal, available_qty = :availableQty, max_qty_per_order = :maxQtyPerOrder," +
" inception_ts = :inceptionTs, expiration_ts = :expirationTs, vat = :vat, vat_type = :vatType, src_price_cts = :srcPriceCts where id = :id")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--
-- This file is part of alf.io.
--
-- alf.io is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- alf.io is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with alf.io. If not, see <http://www.gnu.org/licenses/>.
--

alter table additional_service add column service_type varchar(255);
alter table additional_service add column supplement_policy varchar(255);
update additional_service set service_type = 'DONATION';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--
-- This file is part of alf.io.
--
-- alf.io is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- alf.io is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with alf.io. If not, see <http://www.gnu.org/licenses/>.
--

alter table additional_service add column service_type varchar(255);
alter table additional_service add column supplement_policy varchar(255);
update additional_service set service_type = 'DONATION';
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--
-- This file is part of alf.io.
--
-- alf.io is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- alf.io is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with alf.io. If not, see <http://www.gnu.org/licenses/>.
--

alter table additional_service add column service_type varchar(255);
alter table additional_service add column supplement_policy varchar(255);
update additional_service set service_type = 'DONATION';

0 comments on commit df42fc9

Please sign in to comment.