Skip to content

Commit

Permalink
#318 add tokens in ticket category, fix @JsonIgnore use to hide embed…
Browse files Browse the repository at this point in the history
…ded events/stats
  • Loading branch information
syjer committed Aug 11, 2017
1 parent e14ee7c commit cc35c8d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
37 changes: 34 additions & 3 deletions src/main/java/alfio/controller/api/admin/EventApiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public class EventApiController {
private final FileUploadManager fileUploadManager;
private final EventDescriptionRepository eventDescriptionRepository;
private final TicketCategoryRepository ticketCategoryRepository;
private final SpecialPriceRepository specialPriceRepository;


@ExceptionHandler(DataAccessException.class)
Expand Down Expand Up @@ -181,10 +182,27 @@ public static class TicketCategoryWithAdditionalInfo implements StatisticsContai

private final Map<String, String> description;

private final List<SpecialPrice> tokenStatus;

//TODO: to remove it
@Deprecated
private final List<TicketWithStatistic> tickets = Collections.emptyList();

@JsonIgnore
public Event getEvent() {
return event;
}

@JsonIgnore
public TicketCategory getTicketCategory() {
return ticketCategory;
}

@JsonIgnore
public TicketCategoryStatisticView getTicketCategoryStatisticView() {
return ticketCategoryStatisticView;
}


public String getFormattedInception() {
return getInception(event.getZoneId()).format(EventStatistic.JSON_DATE_FORMATTER);
Expand Down Expand Up @@ -289,6 +307,16 @@ public static class EventWithAdditionalInfo implements StatisticsContainer, Pric

private final BigDecimal grossIncome;

@JsonIgnore
public Event getEvent() {
return event;
}

@JsonIgnore
public EventStatistic getEventStatistic() {
return eventStatistic;
}

@Override
@JsonIgnore
public int getSrcPriceCts() {
Expand Down Expand Up @@ -337,11 +365,14 @@ public ResponseEntity<EventAndOrganization> getSingleEvent(@PathVariable("name")


List<TicketCategory> ticketCategories = eventManager.loadTicketCategories(event);
Map<Integer, Map<String, String>> descriptions = ticketCategoryDescriptionRepository.descriptionsByTicketCategory(ticketCategories.stream().map(TicketCategory::getId).collect(Collectors.toList()));

List<Integer> ticketCategoriesIds = ticketCategories.stream().map(TicketCategory::getId).collect(Collectors.toList());
Map<Integer, Map<String, String>> descriptions = ticketCategoryDescriptionRepository.descriptionsByTicketCategory(ticketCategoriesIds);
Map<Integer, TicketCategoryStatisticView> ticketCategoriesStatistics = ticketCategoryRepository.findStatisticsForEventIdByCategoryId(event.getId());
Map<Integer, List<SpecialPrice>> specialPrices = specialPriceRepository.findAllByCategoriesIdsMapped(ticketCategoriesIds);

List<TicketCategoryWithAdditionalInfo> tWithInfo = ticketCategories.stream().map(t -> new TicketCategoryWithAdditionalInfo(event, t, ticketCategoriesStatistics.get(t.getId()), descriptions.get(t.getId()))).collect(Collectors.toList());
List<TicketCategoryWithAdditionalInfo> tWithInfo = ticketCategories.stream()
.map(t -> new TicketCategoryWithAdditionalInfo(event, t, ticketCategoriesStatistics.get(t.getId()), descriptions.get(t.getId()), specialPrices.get(t.getId())))
.collect(Collectors.toList());

EventWithAdditionalInfo e = new EventWithAdditionalInfo(event, tWithInfo, eventStatistic, description, grossIncome);

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/alfio/repository/SpecialPriceRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,20 @@
import ch.digitalfondue.npjt.QueryType;

import java.time.ZonedDateTime;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@QueryRepository
public interface SpecialPriceRepository {

@Query("select * from special_price where ticket_category_id = :ticketCategoryId")
List<SpecialPrice> findAllByCategoryId(@Bind("ticketCategoryId") int ticketCategoryId);

@Query("select * from special_price where ticket_category_id in (:ticketCategoryIds)")
List<SpecialPrice> findAllByCategoriesIds(@Bind("ticketCategoryIds") Collection<Integer> ticketCategoryIds);

@Query("select * from special_price where ticket_category_id = :ticketCategoryId and status = 'FREE'")
List<SpecialPrice> findActiveByCategoryId(@Bind("ticketCategoryId") int ticketCategoryId);

Expand Down Expand Up @@ -83,4 +89,9 @@ public interface SpecialPriceRepository {

@Query("select * from special_price where status = 'WAITING' and ticket_category_id = :categoryId for update")
List<SpecialPrice> findWaitingElementsForCategory(@Bind("categoryId") int categoryId);


default Map<Integer,List<SpecialPrice>> findAllByCategoriesIdsMapped(Collection<Integer> ticketCategoriesIds) {
return findAllByCategoriesIds(ticketCategoriesIds).stream().collect(Collectors.groupingBy(SpecialPrice::getTicketCategoryId));
}
}

0 comments on commit cc35c8d

Please sign in to comment.