fix(pages): send a form block's event uuid as a string; page detail carries branding

A Snowflake event uuid is beyond JavaScript number precision, so the
editor would round it. The counter now writes it as a string and the
public page service reads either form. The admin page detail adds the
company's branding for the editor's preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
This commit is contained in:
ngqileandClaude Opus 5.5 committed 2026-12-02 16:30:54 +08:00
1 parent 98a77fa17d
commit ab9d3f4942
6 files changed
+49 -3

No files matched your search

@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.solvway.core.model.User;
import com.solvway.core.utils.HttpReqRespUtils;
import com.solvway.mobile.api.constant.api.RestApiCounterServiceConstants;
import com.solvway.mobile.api.constant.api.RestApiSystemServiceConstants;
import com.solvway.mobile.api.dto.admin.AdminPageRequest;
import com.solvway.mobile.api.errorhandler.CodedResponseStatusException;
import com.solvway.mobile.api.useraccess.AdminCompanyScope;
@@ -44,8 +45,17 @@ public class AdminPageService {
return rest.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_CMS_PAGE_SEARCH), MAP, body).getBody();
}
/** The page with its company's branding, which the editor's preview renders with. */
public Map<String, Object> get(long id) {
return load(caller(), id);
Map<String, Object> page = new LinkedHashMap<>(load(caller(), id));
Map<String, Object> company = PublicRegistrationService.found(() -> rest.getForEntity(
url(RestApiSystemServiceConstants.API_REST_COMPANY_FIND_BY_ID), MAP, ((Number) page.get("companyId")).longValue()).getBody());
if (company != null) {
Map<String, Object> branding = new LinkedHashMap<>();
for (String k : List.of("code", "name", "logoImageId", "accentColor")) branding.put(k, company.get(k));
page.put("company", branding);
}
return page;
}
public Map<String, Object> create(AdminPageRequest r) {
@@ -116,8 +116,10 @@ public class PublicPageService {
/** The form block's event when it can take sign-ups now, else null. companyId comes from the page's company, never the block. */
private PublicRegistrationService.Open open(long companyId, Map<String, Object> block) {
Object u = block.get("eventUuid"); // the counter sends it as a string (Snowflake precision)
Long uuid = u instanceof Number n ? Long.valueOf(n.longValue()) : u instanceof String s && s.matches("\\d{1,19}") ? Long.valueOf(s) : null;
Map<String, Object> link = new LinkedHashMap<>();
link.put("eventUuid", block.get("eventUuid"));
link.put("eventUuid", uuid);
link.put("companyId", companyId);
return registration.load(link, true);
}
@@ -147,6 +147,15 @@ class AdminPageServiceTest {
assertThat((Map<String, Object>) body.getValue()).containsEntry("companyId", 2L).containsEntry("data", "aGk=").containsEntry("user", "boss");
}
@Test
void detailCarriesTheCompanysBrandingForThePreview() {
caller(2L, false);
when(rest.getForEntity(eq("/company/findById/{id}"), any(ParameterizedTypeReference.class), eq(2L))).thenReturn(ResponseEntity.ok(
Map.of("id", 2, "code", "INS", "name", "INS Sdn Bhd", "logoImageId", 4, "accentColor", "#0B5FFF", "status", "A")));
Map<String, Object> out = service.get(5L);
assertThat((Map<String, Object>) out.get("company")).isEqualTo(Map.of("code", "INS", "name", "INS Sdn Bhd", "logoImageId", 4, "accentColor", "#0B5FFF"));
}
@Test
void superAdminMustPickACompanyToCreate() {
caller(null, true);
@@ -87,7 +87,7 @@ class PublicPageServiceTest {
}
private static Map<String, Object> page() {
Map<String, Object> form = new HashMap<>(Map.of("type", "FORM", "heading", "Talk to us", "eventUuid", EV));
Map<String, Object> form = new HashMap<>(Map.of("type", "FORM", "heading", "Talk to us", "eventUuid", String.valueOf(EV)));
return new HashMap<>(Map.of("id", 12L, "companyId", COMPANY, "slug", "hotel-technology", "title", "Hotel technology",
"status", "PUBLISHED", "blocks", List.of(Map.of("type", "RICH_TEXT", "html", "<p>Hi</p>"), form)));
}