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:
1 parent
98a77fa17d
commit
ab9d3f4942
6 files changed
+49
-3
No files matched your search
+11
-1
@@ -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) {
|
||||
|
||||
+3
-1
@@ -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);
|
||||
}
|
||||
|
||||
+9
@@ -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);
|
||||
|
||||
+1
-1
@@ -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)));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.solvway.services.counter.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -24,5 +26,7 @@ public class CmsBlock {
|
||||
private String buttonLabel;
|
||||
private String buttonUrl;
|
||||
private List<CmsFaqItem> items;
|
||||
/** A Snowflake value beyond JavaScript number precision: written as a string, read from either. */
|
||||
@JsonSerialize(using = ToStringSerializer.class)
|
||||
private Long eventUuid;
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package com.solvway.services.counter.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/** Event uuids are Snowflake values beyond JavaScript's number precision, so a block sends its eventUuid as a string. */
|
||||
class CmsBlockJsonTest {
|
||||
private final ObjectMapper json = new ObjectMapper();
|
||||
|
||||
@Test
|
||||
void eventUuidTravelsAsAStringAndReadsBackFromEither() throws Exception {
|
||||
CmsBlock b = new CmsBlock();
|
||||
b.setType("FORM");
|
||||
b.setEventUuid(3312726793093644288L);
|
||||
assertThat(json.writeValueAsString(b)).contains("\"eventUuid\":\"3312726793093644288\"");
|
||||
assertThat(json.readValue("{\"type\":\"FORM\",\"eventUuid\":\"3312726793093644288\"}", CmsBlock.class).getEventUuid()).isEqualTo(3312726793093644288L);
|
||||
assertThat(json.readValue("{\"type\":\"FORM\",\"eventUuid\":3312726793093644288}", CmsBlock.class).getEventUuid()).isEqualTo(3312726793093644288L);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user