Skip to content

Commit

Permalink
add public UUID to AttendeeSearchResults
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Jul 18, 2024
1 parent 5f14a83 commit 65be5cc
Show file tree
Hide file tree
Showing 7 changed files with 567 additions and 583 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import alfio.util.Json;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.servlet.http.HttpServletResponse;
import lombok.Data;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand All @@ -41,11 +42,11 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletResponse;
import java.security.Principal;
import java.util.*;
import java.util.stream.Collectors;

import static alfio.manager.AccessService.MEMBERSHIP_ROLES;
import static alfio.util.Wrappers.optionally;

@RestController
Expand Down Expand Up @@ -211,13 +212,13 @@ public ResponseEntity<AttendeeSearchResults> searchAttendees(@PathVariable Strin
@RequestParam(value = "query", required = false) String query,
@RequestParam(value = "page", required = false, defaultValue = "0") int page,
Principal principal) {
accessService.checkEventMembership(principal, publicIdentifier, AccessService.CHECKIN_ROLES);
accessService.checkEventMembership(principal, publicIdentifier, MEMBERSHIP_ROLES);
if (StringUtils.isBlank(query) || StringUtils.isBlank(publicIdentifier)) {
return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
}

return ResponseEntity.of(eventManager.getOptionalByName(publicIdentifier, principal.getName())
.map(event -> checkInManager.searchAttendees(event, query, page)));
.map(event -> checkInManager.searchAttendees(event, query, page, principal)));

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

public class EventListItem {

private static final int API_VERSION = 204;
private static final int API_VERSION = 205;
protected final Event event;
private final String requestContextPath;
private final List<EventDescription> eventDescriptions;
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/alfio/manager/CheckInManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import javax.crypto.spec.SecretKeySpec;
import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.security.Principal;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
Expand All @@ -60,6 +61,7 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

import static alfio.manager.AccessService.MEMBERSHIP_ROLES;
import static alfio.manager.support.CheckInStatus.*;
import static alfio.model.Audit.EventType.*;
import static alfio.model.system.ConfigurationKeys.*;
Expand Down Expand Up @@ -90,6 +92,7 @@ public class CheckInManager {
private final AdditionalServiceItemRepository additionalServiceItemRepository;
private final PollRepository pollRepository;
private final ClockProvider clockProvider;
private final AccessService accessService;


private void checkIn(String uuid, Event event) {
Expand All @@ -113,7 +116,8 @@ private void acquire(String uuid) {
ticketReservationManager.registerAlfioTransactionForOnsitePayment(eventRepository.findById(ticket.getEventId()), ticket.getTicketsReservationId());
}

public AttendeeSearchResults searchAttendees(Event event, String query, int page) {
public AttendeeSearchResults searchAttendees(Event event, String query, int page, Principal principal) {
accessService.checkEventMembership(principal, event.getShortName(), MEMBERSHIP_ROLES);
if (StringUtils.isBlank(query)) {
return new AttendeeSearchResults(0, 0, 0, 0, List.of());
}
Expand All @@ -129,10 +133,14 @@ public AttendeeSearchResults searchAttendees(Event event, String query, int page
var priceContainer = TicketPriceContainer.from(ticket, reservation.getVatStatus(), reservation.getVAT(), event.getVatStatus(), reservation.getDiscount().orElse(null));
amountToPay = event.getCurrency() + " " + MonetaryUtil.formatUnit(priceContainer.getFinalPrice(), event.getCurrency());
}
return new AttendeeSearchResults.Attendee(ticket.getUuid(), // we use internal UUID here, as mobile app needs to (potentially) perform check-in / revert
return new AttendeeSearchResults.AttendeeResult(ticket.getUuid(),
ticket.getPublicUuid(),
ticket.getFirstName(),
ticket.getLastName(), fi.getTicketCategory().getName(), fi.getTicketAdditionalInfo(),
ticket.getStatus(), amountToPay);
ticket.getLastName(),
fi.getTicketCategory().getName(),
fi.getTicketAdditionalInfo(),
ticket.getStatus(),
amountToPay);
}).collect(Collectors.toList());
int totalPages = (int) Math.ceil((statistics.getTotal() / (double) SEARCH_ATTENDEES_LIMIT));
return new AttendeeSearchResults(statistics.getTotal(), statistics.getCheckedIn(), totalPages, page, attendees);
Expand Down
106 changes: 22 additions & 84 deletions src/main/java/alfio/model/checkin/AttendeeSearchResults.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,96 +21,34 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;

public class AttendeeSearchResults {
private final int totalResults;
private final int checkedIn;
private final int totalPages;
private final int numPage;
private final List<Attendee> attendees;

public AttendeeSearchResults(int totalResults,
int checkedIn,
int totalPages,
int numPage,
List<Attendee> attendees) {
this.totalResults = totalResults;
this.checkedIn = checkedIn;
this.totalPages = totalPages;
this.numPage = numPage;
this.attendees = attendees;
}

public int getTotalResults() {
return totalResults;
}

public int getCheckedIn() {
return checkedIn;
}

public List<Attendee> getAttendees() {
return attendees;
}
public record AttendeeSearchResults(
int totalResults,
int checkedIn,
int totalPages,
int numPage,
List<AttendeeResult> attendees
) {

public boolean hasMorePages() {
return numPage < totalPages - 1;
}

public int getTotalPages() {
return totalPages;
}

public int getNumPage() {
return numPage;
}

public static class Attendee {
private final String uuid;
private final String firstName;
private final String lastName;
private final String categoryName;
private final Map<String, List<String>> additionalInfo;
private final Ticket.TicketStatus ticketStatus;
private final String amountToPay;

public Attendee(String uuid,
String firstName, String lastName, String categoryName, Map<String, List<String>> additionalInfo, Ticket.TicketStatus ticketStatus, String amountToPay) {
this.uuid = uuid;
this.firstName = firstName;
this.lastName = lastName;
this.categoryName = categoryName;
this.additionalInfo = additionalInfo;
this.ticketStatus = ticketStatus;
this.amountToPay = amountToPay;
}
public record AttendeeResult(
String uuid,
UUID publicUUID,
String firstName,
String lastName,
String categoryName,
Map<String, List<String>> additionalInfo,
Ticket.TicketStatus ticketStatus,
String amountToPay
) {

public String getFirstName() {
return firstName;
@Override
public Map<String, List<String>> additionalInfo() {
return Objects.requireNonNullElse(additionalInfo, Map.of());
}
}

public String getLastName() {
return lastName;
}

public String getCategoryName() {
return categoryName;
}

public Map<String, List<String>> getAdditionalInfo() {
return Objects.requireNonNullElse(additionalInfo, Map.of());
}

public Ticket.TicketStatus getTicketStatus() {
return ticketStatus;
}

public String getAmountToPay() {
return amountToPay;
}

public String getUuid() {
return uuid;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1124,20 +1124,20 @@ protected void testBasicFlow(Supplier<ReservationFlowContext> contextSupplier) t
assertTrue(results.getStatusCode().is2xxSuccessful());
assertNotNull(results.getBody());
var searchResults = results.getBody();
assertEquals(1, searchResults.getTotalPages());
var attendees = searchResults.getAttendees();
int count = searchResults.getTotalResults();
assertEquals(1, searchResults.totalPages());
var attendees = searchResults.attendees();
int count = searchResults.totalResults();
assertFalse(searchResults.hasMorePages());
assertFalse(attendees.isEmpty());
assertEquals(count, attendees.size());
assertTrue(attendees.stream().anyMatch(sr -> sr.getLastName().equals(fullTicketInfo.getLastName())));
assertTrue(attendees.stream().allMatch(sr -> sr.getAdditionalInfo() != null));
assertEquals(List.of("value"), attendees.get(0).getAdditionalInfo().get("field1"));
assertTrue(attendees.stream().anyMatch(sr -> sr.lastName().equals(fullTicketInfo.getLastName())));
assertTrue(attendees.stream().allMatch(sr -> sr.additionalInfo() != null));
assertEquals(List.of("value"), attendees.get(0).additionalInfo().get("field1"));
break;
case ONLINE:
assertTrue(results.getStatusCode().is2xxSuccessful());
assertNotNull(results.getBody());
assertEquals(0, results.getBody().getTotalResults());
assertEquals(0, results.getBody().totalResults());
break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/alfio/manager/CheckInManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void setUp() {
when(organization.getId()).thenReturn(ORG_ID);
when(eventRepository.retrieveCheckInStatisticsForEvent(EVENT_ID)).thenReturn(new CheckInStatistics(0, 0, new Date()));
checkInManager = new CheckInManager(null, eventRepository, null, null, null, null,
null, configurationManager, organizationRepository, null, null, null, null, null, TestUtil.clockProvider());
null, configurationManager, organizationRepository, null, null, null, null, null, TestUtil.clockProvider(), null);
}

@Test
Expand Down
Loading

0 comments on commit 65be5cc

Please sign in to comment.