feat(pages): admin publish and discard endpoints
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
cd85faa60e
commit
8203839b09
5 files changed
+71
-1
No files matched your search
@@ -7,7 +7,7 @@ Design: `design.md` and `docs/superpowers/specs/2026-12-03-page-builder-design.m
|
|||||||
- [x] 1.1 SQL: `sql/01-page-draft.sql`, `sql/99-rollback.sql`; mirror 01 into `local/seed/`; apply locally.
|
- [x] 1.1 SQL: `sql/01-page-draft.sql`, `sql/99-rollback.sql`; mirror 01 into `local/seed/`; apply locally.
|
||||||
- [x] 1.2 services-counter: `draft` on the entity and DTO, `hasDraft` on list rows; save rules for published pages; publish (re-validate, slug check) and discard endpoints; `findPublished` unchanged.
|
- [x] 1.2 services-counter: `draft` on the entity and DTO, `hasDraft` on list rows; save rules for published pages; publish (re-validate, slug check) and discard endpoints; `findPublished` unchanged.
|
||||||
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
- Verify: `mvn -T 1C -B -pl solvway-services-counter -am verify`
|
||||||
- [ ] 1.3 mobile-api: `POST /api/admin/pages/{id}/publish` and `/discard`, scoped, refusals relayed like save.
|
- [x] 1.3 mobile-api: `POST /api/admin/pages/{id}/publish` and `/discard`, scoped, refusals relayed like save.
|
||||||
- Verify: `mvn -T 1C -B -pl solvway-mobile-api -am verify`
|
- Verify: `mvn -T 1C -B -pl solvway-mobile-api -am verify`
|
||||||
|
|
||||||
## 2. Portal
|
## 2. Portal
|
||||||
|
|||||||
+2
@@ -79,6 +79,8 @@ public class RestApiCounterServiceConstants {
|
|||||||
public static final String API_REST_COUNTER_CMS_PAGE_FIND_BY_ID = "/counter/cmsPage/findById/{id}";
|
public static final String API_REST_COUNTER_CMS_PAGE_FIND_BY_ID = "/counter/cmsPage/findById/{id}";
|
||||||
public static final String API_REST_COUNTER_CMS_PAGE_SEARCH = "/counter/cmsPage/search";
|
public static final String API_REST_COUNTER_CMS_PAGE_SEARCH = "/counter/cmsPage/search";
|
||||||
public static final String API_REST_COUNTER_CMS_PAGE_DELETE = "/counter/cmsPage/delete";
|
public static final String API_REST_COUNTER_CMS_PAGE_DELETE = "/counter/cmsPage/delete";
|
||||||
|
public static final String API_REST_COUNTER_CMS_PAGE_PUBLISH = "/counter/cmsPage/publish";
|
||||||
|
public static final String API_REST_COUNTER_CMS_PAGE_DISCARD = "/counter/cmsPage/discard";
|
||||||
public static final String API_REST_COUNTER_CMS_PAGE_FIND_PUBLISHED = "/counter/cmsPage/findPublished/{companyId}/{slug}";
|
public static final String API_REST_COUNTER_CMS_PAGE_FIND_PUBLISHED = "/counter/cmsPage/findPublished/{companyId}/{slug}";
|
||||||
public static final String API_REST_COUNTER_PAGE_IMAGE_UPLOAD = "/counter/pageImage/upload";
|
public static final String API_REST_COUNTER_PAGE_IMAGE_UPLOAD = "/counter/pageImage/upload";
|
||||||
public static final String API_REST_COUNTER_PAGE_IMAGE = "/counter/pageImage/{id}";
|
public static final String API_REST_COUNTER_PAGE_IMAGE = "/counter/pageImage/{id}";
|
||||||
|
|||||||
+14
@@ -58,6 +58,20 @@ public class AdminPageController {
|
|||||||
return ResponseEntity.ok(pages.update(id, request));
|
return ResponseEntity.ok(pages.update(id, request));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@AppAuth
|
||||||
|
@AdminModule("BO_PAGES")
|
||||||
|
@PostMapping("/pages/{id}/publish")
|
||||||
|
public ResponseEntity<Map<String, Object>> publish(@PathVariable long id) {
|
||||||
|
return ResponseEntity.ok(pages.publish(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@AppAuth
|
||||||
|
@AdminModule("BO_PAGES")
|
||||||
|
@PostMapping("/pages/{id}/discard")
|
||||||
|
public ResponseEntity<Map<String, Object>> discard(@PathVariable long id) {
|
||||||
|
return ResponseEntity.ok(pages.discard(id));
|
||||||
|
}
|
||||||
|
|
||||||
@AppAuth
|
@AppAuth
|
||||||
@AdminModule("BO_PAGES")
|
@AdminModule("BO_PAGES")
|
||||||
@DeleteMapping("/pages/{id}")
|
@DeleteMapping("/pages/{id}")
|
||||||
|
|||||||
@@ -75,6 +75,21 @@ public class AdminPageService {
|
|||||||
rest.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_CMS_PAGE_DELETE), Void.class, id);
|
rest.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_CMS_PAGE_DELETE), Void.class, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Makes a published page's draft live; the counter checks the draft again. */
|
||||||
|
public Map<String, Object> publish(long id) {
|
||||||
|
User caller = caller();
|
||||||
|
load(caller, id);
|
||||||
|
Map<String, Object> body = new LinkedHashMap<>();
|
||||||
|
body.put("id", id);
|
||||||
|
body.put("user", caller.getUsername());
|
||||||
|
return relay(() -> rest.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_CMS_PAGE_PUBLISH), MAP, body).getBody());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> discard(long id) {
|
||||||
|
load(caller(), id);
|
||||||
|
return relay(() -> rest.postForEntity(url(RestApiCounterServiceConstants.API_REST_COUNTER_CMS_PAGE_DISCARD), MAP, id).getBody());
|
||||||
|
}
|
||||||
|
|
||||||
/** base64 bytes; the counter checks type and size. */
|
/** base64 bytes; the counter checks type and size. */
|
||||||
public Map<String, Object> uploadImage(Long companyId, String data) {
|
public Map<String, Object> uploadImage(Long companyId, String data) {
|
||||||
User caller = caller();
|
User caller = caller();
|
||||||
|
|||||||
+39
@@ -41,6 +41,8 @@ class AdminPageServiceTest {
|
|||||||
private static final String SEARCH = "/counter/cmsPage/search";
|
private static final String SEARCH = "/counter/cmsPage/search";
|
||||||
private static final String DELETE = "/counter/cmsPage/delete";
|
private static final String DELETE = "/counter/cmsPage/delete";
|
||||||
private static final String UPLOAD = "/counter/pageImage/upload";
|
private static final String UPLOAD = "/counter/pageImage/upload";
|
||||||
|
private static final String PUBLISH = "/counter/cmsPage/publish";
|
||||||
|
private static final String DISCARD = "/counter/cmsPage/discard";
|
||||||
|
|
||||||
private RestTemplateCustomUtil rest;
|
private RestTemplateCustomUtil rest;
|
||||||
private AdminAuthenticationService auth;
|
private AdminAuthenticationService auth;
|
||||||
@@ -173,4 +175,41 @@ class AdminPageServiceTest {
|
|||||||
assertThatThrownBy(() -> service.create(request(null))).isInstanceOf(CodedResponseStatusException.class);
|
assertThatThrownBy(() -> service.create(request(null))).isInstanceOf(CodedResponseStatusException.class);
|
||||||
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
verify(rest, never()).postForEntity(eq(SAVE), any(ParameterizedTypeReference.class), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void publishAndDiscardAreScopedAndSentForTheStoredPage() {
|
||||||
|
caller(2L, false);
|
||||||
|
when(rest.postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of("id", 5)));
|
||||||
|
when(rest.postForEntity(eq(DISCARD), any(ParameterizedTypeReference.class), any())).thenReturn(ResponseEntity.ok(Map.of("id", 5)));
|
||||||
|
assertThat(service.publish(5L)).containsEntry("id", 5);
|
||||||
|
assertThat(service.discard(5L)).containsEntry("id", 5);
|
||||||
|
ArgumentCaptor<Object> body = ArgumentCaptor.forClass(Object.class);
|
||||||
|
verify(rest).postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), body.capture());
|
||||||
|
assertThat((Map<String, Object>) body.getValue()).containsEntry("id", 5L).containsEntry("user", "boss");
|
||||||
|
verify(rest).postForEntity(eq(DISCARD), any(ParameterizedTypeReference.class), eq(5L));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void staffCannotPublishOrDiscardAnotherCompanysPage() {
|
||||||
|
caller(3L, false);
|
||||||
|
for (Runnable r : List.<Runnable>of(() -> service.publish(5L), () -> service.discard(5L))) {
|
||||||
|
assertThatThrownBy(r::run).isInstanceOfSatisfying(CodedResponseStatusException.class,
|
||||||
|
e -> assertThat(e.getCode()).isEqualTo("PAGE_NOT_FOUND"));
|
||||||
|
}
|
||||||
|
verify(rest, never()).postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), any());
|
||||||
|
verify(rest, never()).postForEntity(eq(DISCARD), any(ParameterizedTypeReference.class), any());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void aPublishRefusalBecomesCodeAndField() {
|
||||||
|
caller(2L, false);
|
||||||
|
byte[] problem = "{\"status\":409,\"detail\":\"slug|PagesSlugTaken\"}".getBytes(StandardCharsets.UTF_8);
|
||||||
|
when(rest.postForEntity(eq(PUBLISH), any(ParameterizedTypeReference.class), any())).thenThrow(
|
||||||
|
HttpClientErrorException.create(HttpStatus.CONFLICT, "x", HttpHeaders.EMPTY, problem, StandardCharsets.UTF_8));
|
||||||
|
assertThatThrownBy(() -> service.publish(5L)).isInstanceOfSatisfying(CodedResponseStatusException.class, e -> {
|
||||||
|
assertThat(e.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
|
||||||
|
assertThat(e.getCode()).isEqualTo("PagesSlugTaken");
|
||||||
|
assertThat(e.getBody().getProperties()).containsEntry("details", Map.of("field", "slug"));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user