feat: counter guest, invite registration and check-in endpoints

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-01 17:08:54 +08:00
1 parent d039cbc1e1
commit c700e12865
16 files changed
+1335 -6

No files matched your search

@@ -0,0 +1,18 @@
package com.solvway.services.counter.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.server.ResponseStatusException;
import java.util.Map;
/** Puts the reason of a ResponseStatusException into the body as `code`, which mobile-api reads. Limited to the invitation feature. */
@RestControllerAdvice(assignableTypes = {EventGuestController.class, EventCheckInController.class, EventController.class})
public class ApiErrorAdvice {
@ExceptionHandler(ResponseStatusException.class)
public ResponseEntity<Map<String, String>> handle(ResponseStatusException e) {
String reason = e.getReason() == null ? "" : e.getReason();
return ResponseEntity.status(e.getStatusCode()).body(Map.of("code", reason, "message", reason));
}
}
@@ -0,0 +1,37 @@
package com.solvway.services.counter.controller;
import com.solvway.services.counter.service.EventCheckInService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/counter/checkin")
@AllArgsConstructor
public class EventCheckInController {
private final EventCheckInService service;
@GetMapping("/findEvent/{token}")
public EventCheckInService.EventRef findEvent(@PathVariable("token") String token) {
return service.findEvent(token);
}
@PostMapping("/ensureToken")
public EventCheckInService.TokenView ensureToken(@RequestBody EventCheckInService.EnsureRequest req) {
return service.ensureToken(req);
}
@PostMapping("/lookup")
public EventCheckInService.LookupResult lookup(@RequestBody EventCheckInService.LookupRequest req) {
return service.lookup(req);
}
@PostMapping("/byGuest")
public EventCheckInService.NameView byGuest(@RequestBody EventCheckInService.ByGuestRequest req) {
return service.byGuest(req);
}
}
@@ -0,0 +1,50 @@
package com.solvway.services.counter.controller;
import com.solvway.services.counter.service.EventGuestService;
import com.solvway.services.counter.service.RegistrationService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping("/counter/eventGuest")
@AllArgsConstructor
public class EventGuestController {
private final EventGuestService service;
@PostMapping("/list")
public List<EventGuestService.GuestRow> list(@RequestBody EventGuestService.ListRequest req) {
return service.list(req);
}
@PostMapping("/add")
public EventGuestService.AddResult add(@RequestBody EventGuestService.AddRequest req) {
return service.add(req);
}
@PostMapping("/remove")
public void remove(@RequestBody EventGuestService.RemoveRequest req) {
service.remove(req);
}
@PostMapping("/markSent")
public void markSent(@RequestBody EventGuestService.MarkSentRequest req) {
service.markSent(req);
}
@GetMapping("/findByToken/{token}")
public EventGuestService.GuestLookup findByToken(@PathVariable("token") String token) {
return service.findByToken(token);
}
@PostMapping("/register")
public RegistrationService.RegisterResult register(@RequestBody EventGuestService.GuestRegisterRequest req) {
return service.register(req);
}
}
@@ -26,6 +26,8 @@ public class Event implements Serializable {
private Long companyId;
private Integer capacity;
private Integer invitationCap;
@Column(name = "checkin_token", updatable = false)
private String checkinToken;
private String uploadFloorPlan;
private String uploadStageActivities;
private String uploadLuckyDraw;
@@ -4,6 +4,8 @@ import com.solvway.services.counter.model.EventGuest;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
@Repository
@@ -17,4 +19,12 @@ public interface EventGuestRepository extends JpaRepository<EventGuest, Long> {
long countByEventUuid(long eventUuid);
long countByEventUuidAndEventLeadIdIsNotNull(long eventUuid);
List<EventGuest> findByEventUuidOrderByNameAsc(long eventUuid);
Optional<EventGuest> findByToken(String token);
Optional<EventGuest> findByIdAndEventUuidAndCompanyId(Long id, long eventUuid, long companyId);
List<EventGuest> findByEventUuidAndCompanyIdAndIdIn(long eventUuid, long companyId, Collection<Long> ids);
}
@@ -51,4 +51,14 @@ public interface EventLeadRepository extends JpaRepository<EventLead, Long> {
@Query("SELECT e, ev FROM EventLead e LEFT JOIN Event ev ON ev.uuid = e.eventUuid"
+ " WHERE e.companyId = :companyId AND e.leadUuid = :leadUuid ORDER BY e.capturedAt DESC, e.id DESC")
List<Object[]> history(@Param("companyId") long companyId, @Param("leadUuid") long leadUuid);
/** Rows are [EventLead, Lead] of this event whose lead has the mobile. */
@Query("SELECT e, l FROM EventLead e, Lead l WHERE l.uuid = e.leadUuid AND l.companyId = e.companyId"
+ " AND e.eventUuid = :eventUuid AND l.mobileE164 = :mobile")
List<Object[]> findByEventAndMobile(@Param("eventUuid") long eventUuid, @Param("mobile") String mobile);
/** Rows are [EventLead, Lead] of this event whose lead has the email. */
@Query("SELECT e, l FROM EventLead e, Lead l WHERE l.uuid = e.leadUuid AND l.companyId = e.companyId"
+ " AND e.eventUuid = :eventUuid AND l.emailNormalised = :email")
List<Object[]> findByEventAndEmail(@Param("eventUuid") long eventUuid, @Param("email") String email);
}
@@ -4,6 +4,10 @@ import com.solvway.core.enums.GeneralEnum;
import com.solvway.services.counter.configuration.JpaRepositoryCustom;
import com.solvway.services.counter.model.Event;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
@@ -12,6 +16,13 @@ import java.util.Optional;
@Repository
public interface EventRepository extends JpaRepository<Event,Long> , JpaRepositoryCustom<Event>{
Optional<Event> findByUuid(long uuid);
Optional<Event> findByCheckinToken(String checkinToken);
/** Sets the check-in token only while none exists; returns rows changed. Atomic, so concurrent callers agree on one token. */
@Modifying(clearAutomatically = true)
@Transactional
@Query("UPDATE Event e SET e.checkinToken = :token WHERE e.uuid = :uuid AND e.checkinToken IS NULL")
int setCheckinTokenIfAbsent(@Param("uuid") long uuid, @Param("token") String token);
java.util.List<Event> findByCompanyIdAndUuidIn(Long companyId, java.util.Collection<Long> uuids);
Optional<Event> findTop1ByDateStartLessThanEqualAndDateEndGreaterThanEqualAndEnabledOrderByDateStartDesc(LocalDateTime dateStart, LocalDateTime dateEnd, GeneralEnum.FlagYesNo enabled);
}
@@ -0,0 +1,111 @@
package com.solvway.services.counter.service;
import com.solvway.core.enums.GeneralEnum;
import com.solvway.services.counter.model.Event;
import com.solvway.services.counter.model.EventGuest;
import com.solvway.services.counter.model.EventLead;
import com.solvway.services.counter.model.Lead;
import com.solvway.services.counter.repo.EventGuestRepository;
import com.solvway.services.counter.repo.EventLeadRepository;
import com.solvway.services.counter.repo.EventRepository;
import com.solvway.services.counter.repo.LeadRepository;
import lombok.AllArgsConstructor;
import com.solvway.services.counter.util.EventDays;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;
import java.util.List;
/** Event-day check-in. Reveals a first name only, nothing else about a person. Never log contact data. */
@Service
@AllArgsConstructor
public class EventCheckInService {
public record EventRef(long companyId, long eventUuid) {}
public record EnsureRequest(Long companyId, long eventUuid) {}
public record TokenView(String token) {}
public record LookupRequest(Long companyId, long eventUuid, String mobileE164, String email) {}
public record LookupResult(String result, String firstName) {}
public record ByGuestRequest(Long companyId, String guestToken) {}
public record NameView(String firstName) {}
private final EventRepository eventRepository;
private final EventGuestRepository guestRepository;
private final EventLeadRepository eventLeadRepository;
private final LeadRepository leadRepository;
private static ResponseStatusException notFound(String code) {
return new ResponseStatusException(HttpStatus.NOT_FOUND, code);
}
private static long requireCompany(Long companyId) {
if (companyId == null) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "COMPANY_REQUIRED");
return companyId;
}
private Event event(Long companyId, long eventUuid) {
long company = requireCompany(companyId);
return eventRepository.findByUuid(eventUuid)
.filter(e -> company == e.getCompanyId())
.orElseThrow(() -> notFound("EVENT_NOT_FOUND"));
}
private static String firstName(String name) {
if (name == null) return null;
String t = name.trim();
int sp = t.indexOf(' ');
return sp < 0 ? t : t.substring(0, sp);
}
public EventRef findEvent(String token) {
Event e = eventRepository.findByCheckinToken(token).orElseThrow(() -> notFound("EVENT_NOT_FOUND"));
return new EventRef(e.getCompanyId(), e.getUuid());
}
public TokenView ensureToken(EnsureRequest req) {
Event e = event(req.companyId(), req.eventUuid());
if (e.getCheckinToken() == null) {
// atomic: only the first writer wins; re-read so every caller returns the stored token
eventRepository.setCheckinTokenIfAbsent(req.eventUuid(), RegistrationLinkService.newToken());
e = event(req.companyId(), req.eventUuid());
}
return new TokenView(e.getCheckinToken());
}
public LookupResult lookup(LookupRequest req) {
Event event = event(req.companyId(), req.eventUuid());
if (event.getEnabled() != GeneralEnum.FlagYesNo.Y) throw notFound("EVENT_NOT_FOUND");
if (!EventDays.isDuring(event, LocalDateTime.now())) throw new ResponseStatusException(HttpStatus.CONFLICT, "NOT_EVENT_DAY");
boolean hasMobile = req.mobileE164() != null && !req.mobileE164().isBlank();
boolean hasEmail = req.email() != null && !req.email().isBlank();
if (hasMobile == hasEmail) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "MOBILE_OR_EMAIL_REQUIRED");
List<Object[]> rows = hasMobile ? eventLeadRepository.findByEventAndMobile(req.eventUuid(), req.mobileE164())
: eventLeadRepository.findByEventAndEmail(req.eventUuid(), req.email());
if (rows.isEmpty()) return new LookupResult("FORM", null);
EventLead el = (EventLead) rows.get(0)[0];
Lead lead = (Lead) rows.get(0)[1];
markAttended(el);
return new LookupResult("CHECKED_IN", firstName(lead.getName()));
}
public NameView byGuest(ByGuestRequest req) {
long company = requireCompany(req.companyId());
EventGuest g = guestRepository.findByToken(req.guestToken())
.filter(x -> company == x.getCompanyId())
.orElseThrow(() -> notFound("GUEST_NOT_FOUND"));
if (g.getEventLeadId() == null) throw new ResponseStatusException(HttpStatus.CONFLICT, "NOT_REGISTERED");
if (!EventDays.isDuring(event(g.getCompanyId(), g.getEventUuid()), LocalDateTime.now())) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "NOT_EVENT_DAY");
}
EventLead el = eventLeadRepository.findById(g.getEventLeadId()).orElseThrow(() -> notFound("GUEST_NOT_FOUND"));
markAttended(el);
return new NameView(leadRepository.findByUuid(el.getLeadUuid()).map(l -> firstName(l.getName())).orElse(null));
}
private void markAttended(EventLead el) {
if (el.getAttendedAt() != null) return;
el.setAttendedAt(LocalDateTime.now());
eventLeadRepository.save(el);
}
}
@@ -0,0 +1,201 @@
package com.solvway.services.counter.service;
import com.solvway.services.counter.model.Event;
import com.solvway.services.counter.model.EventGuest;
import com.solvway.services.counter.model.EventLead;
import com.solvway.services.counter.model.EventSalesperson;
import com.solvway.services.counter.repo.EventGuestRepository;
import com.solvway.services.counter.repo.EventLeadRepository;
import com.solvway.services.counter.repo.EventRepository;
import com.solvway.services.counter.repo.EventSalespersonRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import com.solvway.services.counter.util.EventDays;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.server.ResponseStatusException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
/** Invitation list of an event and registration through a guest's personal link. Never log contact data. */
@Service
@AllArgsConstructor
public class EventGuestService {
public record ListRequest(Long companyId, long eventUuid) {}
public record GuestInput(String name, String mobileE164, String email, String companyName, Long salespersonUserId) {}
public record AddRequest(Long companyId, long eventUuid, List<GuestInput> guests, String doneBy) {}
public record RemoveRequest(Long companyId, long eventUuid, long guestId, String doneBy) {}
public record MarkSentRequest(Long companyId, long eventUuid, List<Long> guestIds, String doneBy) {}
public record GuestRow(long id, String name, String mobileE164, String email, String companyName, Long salespersonUserId,
String token, LocalDateTime invitedAt, int inviteSentCount, LocalDateTime registeredAt,
boolean attended, String eventLeadUuid) {}
public record Rejection(int index, String code, String field, String message) {}
public record AddResult(List<GuestRow> added, List<Rejection> rejected) {}
public record GuestLookup(long companyId, long eventUuid, long guestId, String name, String mobileE164, String email,
String companyName, Long salespersonUserId, boolean registered, boolean attended) {}
public record GuestRegisterRequest(Long companyId, String guestToken, String name, String mobileE164, String email,
String companyName, String jobTitle, List<Long> interestIds, Long consentNoticeId,
LocalDateTime consentAt) {}
private final EventRepository eventRepository;
private final EventGuestRepository guestRepository;
private final EventLeadRepository eventLeadRepository;
private final EventSalespersonRepository eventSalespersonRepository;
private final RegistrationService registrationService;
private static ResponseStatusException notFound(String code) {
return new ResponseStatusException(HttpStatus.NOT_FOUND, code);
}
private static long requireCompany(Long companyId) {
if (companyId == null) throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "COMPANY_REQUIRED");
return companyId;
}
private Event event(Long companyId, long eventUuid) {
long company = requireCompany(companyId);
return eventRepository.findByUuid(eventUuid)
.filter(e -> company == e.getCompanyId())
.orElseThrow(() -> notFound("EVENT_NOT_FOUND"));
}
private static boolean sameCompany(Long companyId, EventGuest g) {
return requireCompany(companyId) == g.getCompanyId();
}
public List<GuestRow> list(ListRequest req) {
event(req.companyId(), req.eventUuid());
List<EventGuest> guests = guestRepository.findByEventUuidOrderByNameAsc(req.eventUuid());
List<Long> leadIds = guests.stream().map(EventGuest::getEventLeadId).filter(Objects::nonNull).toList();
Map<Long, EventLead> leads = leadIds.isEmpty() ? Map.of()
: eventLeadRepository.findAllById(leadIds).stream().collect(Collectors.toMap(EventLead::getId, l -> l));
return guests.stream().map(g -> row(g, leads.get(g.getEventLeadId()))).toList();
}
private static GuestRow row(EventGuest g, EventLead lead) {
return new GuestRow(g.getId(), g.getName(), g.getMobileE164(), g.getEmail(), g.getCompanyName(),
g.getSalespersonUserId(), g.getToken(), g.getInvitedAt(), g.getInviteSentCount(), g.getRegisteredAt(),
lead != null && lead.getAttendedAt() != null, lead == null ? null : String.valueOf(lead.getUuid()));
}
// ponytail: deliberately not @Transactional. A unique-key race makes saveAndFlush throw; inside one transaction that
// would mark it rollback-only and lose the guests saved earlier in this request. Each save commits on its own.
// ponytail: the cap check below is unlocked; two concurrent adds can exceed the cap. Upgrade: lock the event row FOR UPDATE.
public AddResult add(AddRequest req) {
Event event = event(req.companyId(), req.eventUuid());
Set<Long> team = eventSalespersonRepository.findByEventUuid(req.eventUuid()).stream()
.map(EventSalesperson::getUserId).collect(Collectors.toSet());
Map<String, EventGuest> byMobile = new HashMap<>();
Map<String, EventGuest> byEmail = new HashMap<>();
List<EventGuest> existing = guestRepository.findByEventUuidOrderByNameAsc(req.eventUuid());
existing.forEach(g -> index(g, byMobile, byEmail));
int count = existing.size();
List<GuestRow> added = new ArrayList<>();
List<Rejection> rejected = new ArrayList<>();
for (int i = 0; i < req.guests().size(); i++) {
GuestInput in = req.guests().get(i);
if (in.salespersonUserId() != null && !team.contains(in.salespersonUserId())) {
rejected.add(new Rejection(i, "NOT_ON_TEAM", "salespersonUserId", "Salesperson is not on the event team"));
continue;
}
EventGuest dup = in.mobileE164() != null && byMobile.containsKey(in.mobileE164()) ? byMobile.get(in.mobileE164())
: in.email() != null ? byEmail.get(in.email()) : null;
if (dup != null) {
boolean mobile = in.mobileE164() != null && byMobile.get(in.mobileE164()) == dup;
rejected.add(new Rejection(i, "DUPLICATE", mobile ? "mobile" : "email",
"Already invited as " + dup.getName()));
continue;
}
if (event.getInvitationCap() != null && count >= event.getInvitationCap()) {
rejected.add(new Rejection(i, "CAP_REACHED", null, "Invitation cap reached (" + event.getInvitationCap() + ")"));
continue;
}
EventGuest g = new EventGuest();
g.setCompanyId(event.getCompanyId());
g.setEventUuid(req.eventUuid());
g.setName(in.name());
g.setMobileE164(in.mobileE164());
g.setEmail(in.email());
g.setCompanyName(in.companyName());
g.setSalespersonUserId(in.salespersonUserId());
g.setToken(RegistrationLinkService.newToken());
g.setCreatedBy(req.doneBy());
try {
g = guestRepository.saveAndFlush(g);
} catch (DataIntegrityViolationException e) {
String m = String.valueOf(e.getMostSpecificCause().getMessage());
if (!m.contains("uk_event_guest_mobile") && !m.contains("uk_event_guest_email")) throw e;
rejected.add(new Rejection(i, "DUPLICATE", null, "Already invited"));
continue;
}
index(g, byMobile, byEmail);
count++;
added.add(row(g, null));
}
return new AddResult(added, rejected);
}
private static void index(EventGuest g, Map<String, EventGuest> byMobile, Map<String, EventGuest> byEmail) {
if (g.getMobileE164() != null) byMobile.put(g.getMobileE164(), g);
if (g.getEmail() != null) byEmail.put(g.getEmail(), g);
}
public void remove(RemoveRequest req) {
Event event = event(req.companyId(), req.eventUuid());
EventGuest g = guestRepository.findByIdAndEventUuidAndCompanyId(req.guestId(), req.eventUuid(), event.getCompanyId())
.orElseThrow(() -> notFound("GUEST_NOT_FOUND"));
if (g.getEventLeadId() != null) throw new ResponseStatusException(HttpStatus.CONFLICT, "GUEST_REGISTERED");
guestRepository.delete(g);
}
@Transactional
public void markSent(MarkSentRequest req) {
Event event = event(req.companyId(), req.eventUuid());
LocalDateTime now = LocalDateTime.now();
for (EventGuest g : guestRepository.findByEventUuidAndCompanyIdAndIdIn(req.eventUuid(), event.getCompanyId(), req.guestIds())) {
if (g.getInvitedAt() == null) g.setInvitedAt(now);
g.setInviteSentCount(g.getInviteSentCount() + 1);
g.setUpdatedBy(req.doneBy());
g.setUpdatedAt(now);
guestRepository.save(g);
}
}
public GuestLookup findByToken(String token) {
EventGuest g = guestRepository.findByToken(token).orElseThrow(() -> notFound("GUEST_NOT_FOUND"));
EventLead lead = g.getEventLeadId() == null ? null : eventLeadRepository.findById(g.getEventLeadId()).orElse(null);
return new GuestLookup(g.getCompanyId(), g.getEventUuid(), g.getId(), g.getName(), g.getMobileE164(), g.getEmail(),
g.getCompanyName(), g.getSalespersonUserId(), g.getEventLeadId() != null,
lead != null && lead.getAttendedAt() != null);
}
public RegistrationService.RegisterResult register(GuestRegisterRequest req) {
requireCompany(req.companyId());
EventGuest g = guestRepository.findByToken(req.guestToken()).filter(x -> sameCompany(req.companyId(), x))
.orElseThrow(() -> notFound("GUEST_NOT_FOUND"));
// ponytail: ALREADY_REGISTERED/EVENT_FULL checks run before the registration transaction; a concurrent double
// submit is harmless but the second answer may differ.
if (g.getEventLeadId() != null) {
String uuid = eventLeadRepository.findById(g.getEventLeadId()).map(l -> String.valueOf(l.getUuid())).orElse(null);
return new RegistrationService.RegisterResult("ALREADY_REGISTERED", uuid);
}
Event event = event(g.getCompanyId(), g.getEventUuid());
if (event.getCapacity() != null && !EventDays.isDuring(event, LocalDateTime.now())
&& guestRepository.countByEventUuidAndEventLeadIdIsNotNull(g.getEventUuid())
+ eventLeadRepository.countWalkIns(g.getEventUuid()) >= event.getCapacity()) {
throw new ResponseStatusException(HttpStatus.CONFLICT, "EVENT_FULL");
}
return registrationService.register(new RegistrationService.RegisterRequest(g.getCompanyId(), g.getEventUuid(),
g.getSalespersonUserId(), req.name(), req.mobileE164(), req.email(), req.companyName(), req.jobTitle(),
req.interestIds(), req.consentNoticeId(), req.consentAt(), false, "INVITE", g.getId()));
}
}
@@ -30,4 +30,14 @@ public class GuestLinker {
guests.save(g);
});
}
/** Links the invited guest the registration came through; skipped when either side is already linked. */
public void linkGuest(long guestId, EventLead eventLead) {
guests.findById(guestId).ifPresent(g -> {
if (g.getEventLeadId() != null || guests.existsByEventLeadId(eventLead.getId())) return;
g.setEventLeadId(eventLead.getId());
if (g.getRegisteredAt() == null) g.setRegisteredAt(LocalDateTime.now());
guests.save(g);
});
}
}
@@ -114,14 +114,19 @@ public class RegistrationLinkService {
.orElseGet(() -> linkRepository.save(newLink(companyId, eventUuid, userId)));
}
private static RegistrationLink newLink(long companyId, long eventUuid, Long userId) {
/** 22-char unguessable base64url token. */
static String newToken() {
byte[] bytes = new byte[16];
RANDOM.nextBytes(bytes);
return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);
}
private static RegistrationLink newLink(long companyId, long eventUuid, Long userId) {
RegistrationLink l = new RegistrationLink();
l.setCompanyId(companyId);
l.setEventUuid(eventUuid);
l.setSalespersonUserId(userId);
l.setToken(Base64.getUrlEncoder().withoutPadding().encodeToString(bytes));
l.setToken(newToken());
l.setCreatedBy("system");
return l;
}
@@ -24,12 +24,20 @@ import java.util.Optional;
public class RegistrationService {
public record RegisterRequest(Long companyId, long eventUuid, Long salespersonUserId, String name, String mobileE164,
String email, String companyName, String jobTitle, List<Long> interestIds,
Long consentNoticeId, LocalDateTime consentAt, boolean attend) {
Long consentNoticeId, LocalDateTime consentAt, boolean attend,
String source, Long guestId) {
/** source null means QR; guestId, when set, is the invited guest this registration links to. */
public RegisterRequest(Long companyId, long eventUuid, Long salespersonUserId, String name, String mobileE164,
String email, String companyName, String jobTitle, List<Long> interestIds,
Long consentNoticeId, LocalDateTime consentAt, boolean attend) {
this(companyId, eventUuid, salespersonUserId, name, mobileE164, email, companyName, jobTitle, interestIds,
consentNoticeId, consentAt, attend, null, null);
}
public RegisterRequest(Long companyId, long eventUuid, Long salespersonUserId, String name, String mobileE164,
String email, String companyName, String jobTitle, List<Long> interestIds,
Long consentNoticeId, LocalDateTime consentAt) {
this(companyId, eventUuid, salespersonUserId, name, mobileE164, email, companyName, jobTitle, interestIds,
consentNoticeId, consentAt, false);
consentNoticeId, consentAt, false, null, null);
}
}
public record RegisterResult(String outcome, String eventLeadUuid) {}
@@ -100,7 +108,7 @@ public class RegistrationService {
e.setLeadType(leadType);
e.setStatus("OPEN");
e.setNotes(notes);
e.setSource("QR");
e.setSource(req.source() == null ? "QR" : req.source());
e.setCapturedBy(QR);
e.setConsentAt(req.consentAt());
e.setConsentNoticeId(req.consentNoticeId());
@@ -127,7 +135,9 @@ public class RegistrationService {
}
private void link(RegisterRequest req, EventLead e, Lead lead) {
if (guestLinker != null) guestLinker.link(req.eventUuid(), e, lead);
if (guestLinker == null) return;
if (req.guestId() != null) guestLinker.linkGuest(req.guestId(), e);
else guestLinker.link(req.eventUuid(), e, lead);
}
/** Submitted non-blank values that differ from the lead's, as an event-lead note; null when nothing differs. */