diff --git a/openspec/changes/add-event-tickets/tasks.md b/openspec/changes/add-event-tickets/tasks.md index 84e817e..46ece97 100644 --- a/openspec/changes/add-event-tickets/tasks.md +++ b/openspec/changes/add-event-tickets/tasks.md @@ -95,7 +95,7 @@ Design: `design.md` (technical contracts) and `docs/superpowers/specs/2026-12-04 - Adds `com.google.zxing:core` to `solvway-mobile-api/pom.xml`. This hotspot runs alone. - Scope: `solvway-mobile-api/**`, `solvway-api-gateway/src/**` - Verify: `mvn -T 1C -q -pl solvway-mobile-api,solvway-api-gateway verify` -- [ ] 3.2 Admin ticket endpoints. +- [x] 3.2 Admin ticket endpoints. - Depends on: 3.1 - Tests first: - **`GET /api/admin/tickets/{code}`:** `BO_EVENTS` and company-scoped (another company's ticket is 404). diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/constant/api/RestApiCounterServiceConstants.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/constant/api/RestApiCounterServiceConstants.java index e419b45..f2c5a73 100644 --- a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/constant/api/RestApiCounterServiceConstants.java +++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/constant/api/RestApiCounterServiceConstants.java @@ -63,6 +63,9 @@ public class RestApiCounterServiceConstants { public static final String API_REST_COUNTER_TICKET_BY_CODE = "/counter/ticket/byCode/{code}"; public static final String API_REST_COUNTER_TICKET_ATTENDEE = "/counter/ticket/attendee"; public static final String API_REST_COUNTER_TICKET_CONSENT = "/counter/ticket/consent"; + public static final String API_REST_COUNTER_TICKET_STAFF = "/counter/ticket/staff"; + public static final String API_REST_COUNTER_TICKET_CHECKIN = "/counter/ticket/checkin"; + public static final String API_REST_COUNTER_TICKET_ORDER_RESEND_TICKET = "/counter/ticketOrder/resendTicket"; public static final String API_REST_COUNTER_EVENT_SALESPERSON_FIND_BY_EVENT_UUID="/counter/eventSalesperson/findByEventUuid/{eventUuid}"; public static final String API_REST_COUNTER_EVENT_SALESPERSON_REPLACE="/counter/eventSalesperson/replace"; public static final String API_REST_COUNTER_INTEREST_FIND_BY_COMPANY="/counter/interest/findByCompany/{companyId}"; diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketCodeController.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketCodeController.java new file mode 100644 index 0000000..f6d3fee --- /dev/null +++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketCodeController.java @@ -0,0 +1,41 @@ +package com.solvway.mobile.api.controller.admin; + +import com.solvway.core.annotation.AppAuth; +import com.solvway.mobile.api.service.AdminTicketService; +import com.solvway.mobile.api.useraccess.AdminModule; +import com.solvway.mobile.api.useraccess.Audited; +import lombok.RequiredArgsConstructor; +import org.springframework.http.ResponseEntity; +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.Map; + +/** add-event-tickets: the staff view of a scanned ticket and door check-in. Must stay under {@code controller..} for AppAccessAspect. */ +@RestController +@RequestMapping("/api/admin/tickets/{code}") +@RequiredArgsConstructor +public class AdminTicketCodeController { + private final AdminTicketService tickets; + + @AppAuth + @AdminModule("BO_EVENTS") + @GetMapping + public ResponseEntity> ticket(@PathVariable String code) { + return ResponseEntity.ok(tickets.ticket(code)); + } + + /** The ticket code is a bearer link, so it is not recorded as the audit target; the ticket keeps who checked it in. */ + @AppAuth + @AdminModule("BO_EVENTS") + @Audited(target = false) + @PostMapping("/checkin") + public ResponseEntity> checkIn(@PathVariable String code, + @RequestBody(required = false) AdminTicketService.CheckInBody body) { + return ResponseEntity.ok(tickets.checkIn(code, body)); + } +} diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketController.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketController.java index b9d71ea..d96a419 100644 --- a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketController.java +++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/controller/admin/AdminTicketController.java @@ -127,4 +127,13 @@ public class AdminTicketController { tickets.resend(uuid, orderId); return ResponseEntity.noContent().build(); } + + @AppAuth + @AdminModule(value = "BO_EVENT_TICKETS", also = "BO_EVENTS") + @Audited(targetVariable = "ticketId") + @PostMapping("/orders/{orderId}/tickets/{ticketId}/resend") + public ResponseEntity resendTicket(@PathVariable String uuid, @PathVariable String orderId, @PathVariable String ticketId) { + tickets.resendTicket(uuid, orderId, ticketId); + return ResponseEntity.noContent().build(); + } } diff --git a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminTicketService.java b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminTicketService.java index 1729ca8..c0ff88c 100644 --- a/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminTicketService.java +++ b/solvway-mobile-api/src/main/java/com/solvway/mobile/api/service/AdminTicketService.java @@ -2,6 +2,7 @@ package com.solvway.mobile.api.service; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; +import com.solvway.mobile.api.constant.api.RestApiSystemServiceConstants; import com.solvway.mobile.api.dto.admin.CompanyEvent; import com.solvway.mobile.api.util.RestTemplateCustomUtil; import lombok.RequiredArgsConstructor; @@ -31,10 +32,12 @@ public class AdminTicketService { private static final ObjectMapper JSON = new ObjectMapper(); private static final int PAGE_SIZE = 50; /** The form field a counter refusal belongs to, so the portal can show it beside that field. */ - private static final Map FIELDS = Map.of( - "PAYMENT_INSTRUCTIONS_REQUIRED", "paymentInstructions", "PAYMENT_INSTRUCTIONS_TOO_LONG", "paymentInstructions", - "HOLD_DAYS_INVALID", "holdDays", "NAME_INVALID", "name", "NAME_TAKEN", "name", "PRICE_INVALID", "priceSen", - "QUANTITY_INVALID", "quantity", "QUANTITY_BELOW_HELD", "quantity", "PAYMENT_REF_TOO_LONG", "paymentRef"); + private static final Map FIELDS = Map.ofEntries( + Map.entry("PAYMENT_INSTRUCTIONS_REQUIRED", "paymentInstructions"), Map.entry("PAYMENT_INSTRUCTIONS_TOO_LONG", "paymentInstructions"), + Map.entry("HOLD_DAYS_INVALID", "holdDays"), Map.entry("NAME_INVALID", "name"), Map.entry("NAME_TAKEN", "name"), + Map.entry("PRICE_INVALID", "priceSen"), Map.entry("QUANTITY_INVALID", "quantity"), Map.entry("QUANTITY_BELOW_HELD", "quantity"), + Map.entry("PAYMENT_REF_TOO_LONG", "paymentRef"), Map.entry("NAME_REQUIRED", "name"), Map.entry("NAME_TOO_LONG", "name"), + Map.entry("MOBILE_OR_EMAIL_REQUIRED", "mobile")); private final RestTemplateCustomUtil rest; private final AdminEventLeadService leads; @@ -45,6 +48,11 @@ public class AdminTicketService { public record PayBody(String paymentRef) {} + /** Door check-in: name, mobile and email only for an unnamed ticket; consent ticked by the attendee at the door. */ + public record CheckInBody(String name, String mobile, String email, Boolean consent) {} + + private record Staff(CompanyEvent event, Map body) {} + public Map settings(String uuid) { CompanyEvent e = leads.loadEvent(uuid, null); Map out = new LinkedHashMap<>(); @@ -127,6 +135,75 @@ public class AdminTicketService { post(API_REST_COUNTER_TICKET_ORDER_RESEND, MAP, orderBody(read(uuid), orderId)); } + public void resendTicket(String uuid, String orderId, String ticketId) { + Map body = orderBody(write(uuid), orderId); + body.put("ticketId", AdminEventLeadService.parseOr(ticketId, AdminTicketService::ticketNotFound)); + post(API_REST_COUNTER_TICKET_ORDER_RESEND_TICKET, MAP, body); + } + + /** add-event-tickets: the staff view of a scanned ticket; only for the event's company (super admins: any), else not found. */ + public Map ticket(String code) { + Staff s = staff(code); + return view(post(API_REST_COUNTER_TICKET_STAFF, MAP, s.body()), s.event()); + } + + /** Door check-in; the counter refuses a second check-in, an invalid ticket and a day outside the event. */ + public Map checkIn(String code, CheckInBody b) { + Staff s = staff(code); + Map body = s.body(); + if (b != null) { + body.put("name", AdminEventLeadService.trimmed(b.name())); + body.put("mobileE164", AdminEventLeadService.mobile(b.mobile())); + body.put("email", AdminEventLeadService.email(b.email())); + if (Boolean.TRUE.equals(b.consent())) body.put("noticeId", notice(s.event()).get("id")); + } + body.put("doneBy", leads.caller().getUsername()); + return view(post(API_REST_COUNTER_TICKET_CHECKIN, MAP, body), s.event()); + } + + private Staff staff(String code) { + if (code == null || !PublicRegistrationService.TOKEN_SHAPE.matcher(code).matches()) throw ticketNotFound(); + Map t = PublicRegistrationService.found(() -> rest.getForEntity(rest.getURLforApiService(API_REST_COUNTER_TICKET_BY_CODE), + MAP, code).getBody()); + if (t == null || !(t.get("eventUuid") instanceof Number uuid)) throw ticketNotFound(); + CompanyEvent e; + try { + e = leads.loadEvent(String.valueOf(uuid.longValue()), null); + } catch (com.solvway.mobile.api.errorhandler.CodedResponseStatusException x) { + if (x.getStatusCode().value() == 404) throw ticketNotFound(); // another company's ticket looks unknown + throw x; + } + Map body = new LinkedHashMap<>(); + body.put("companyId", e.getCompanyId()); + body.put("code", code); + return new Staff(e, body); + } + + private Map view(Map staffView, CompanyEvent e) { + Map out = new LinkedHashMap<>(staffView == null ? Map.of() : staffView); + out.put("eventName", e.getName()); + out.put("startDate", e.getDateStart() == null ? null : e.getDateStart().toLocalDate().toString()); + out.put("endDate", e.getDateEnd() == null ? null : e.getDateEnd().toLocalDate().toString()); + out.put("location", e.getLocation()); + if (!Boolean.TRUE.equals(out.get("consented"))) { + Map n = notice(e); + if (n.get("id") != null) { + out.put("notice", Map.of("id", n.get("id"), "textEn", String.valueOf(n.get("textEn")), "textMs", String.valueOf(n.get("textMs")))); + } + } + return out; + } + + private Map notice(CompanyEvent e) { + Map n = PublicRegistrationService.found(() -> rest.getForEntity( + rest.getURLforApiService(RestApiSystemServiceConstants.API_REST_COMPANY_PRIVACY_NOTICE), MAP, e.getCompanyId()).getBody()); + return n == null ? Map.of() : n; + } + + private static com.solvway.mobile.api.errorhandler.CodedResponseStatusException ticketNotFound() { + return AdminEventLeadService.error(HttpStatus.NOT_FOUND, "Ticket not found", "TICKET_NOT_FOUND", null); + } + private Map read(String uuid) { CompanyEvent e = leads.loadEvent(uuid, null); Map body = new LinkedHashMap<>(); @@ -163,7 +240,11 @@ public class AdminTicketService { } catch (Exception ignored) { // not a ProblemDetail: keep the generic code } - throw AdminEventLeadService.error(HttpStatus.valueOf(e.getStatusCode().value()), code, code, FIELDS.get(code)); + // "CODE|value" (add-event-tickets: ALREADY_CHECKED_IN|