chore: Don't use Layout class for parsing request payloads (#33760)

Goal is to remove `Layout` class being used to deserialise request
payloads. There's two routs in `LayoutControllerCE` that are doing this.

1. The `POST /api/v1/layouts/pages/{pageId}` seems unused, so removing
that.
2. The `PUT /api/v1/layouts/{layoutId}/pages/{pageId}` only gets a
single field in the JSON body, called `dsl`. So we introduce a `record`
to accept just that.

All in an effort towards remove `@JsonProperty` from `Layout`, so it can
work correctly with Postgres.

**/test all**

<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/9254557613>
> Commit: a8ebac28e571d3c89ec8a5fcb6ac9cdc1e8f308f
> Cypress dashboard url: <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9254557613&attempt=1"
target="_blank">Click here!</a>

<!-- end of auto-generated comment: Cypress test results  -->
This commit is contained in:
Shrikant Sharat Kandula 2024-05-27 20:50:35 +05:30 committed by GitHub
parent 43bd03214f
commit c4e5d5e6c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 26 deletions

View File

@ -6,6 +6,7 @@ import com.appsmith.server.constants.Url;
import com.appsmith.server.domains.Layout;
import com.appsmith.server.dtos.EntityType;
import com.appsmith.server.dtos.LayoutDTO;
import com.appsmith.server.dtos.LayoutUpdateDTO;
import com.appsmith.server.dtos.RefactorEntityNameDTO;
import com.appsmith.server.dtos.ResponseDTO;
import com.appsmith.server.dtos.UpdateMultiplePageLayoutDTO;
@ -19,7 +20,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
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.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
@ -45,16 +45,6 @@ public class LayoutControllerCE {
this.refactoringService = refactoringService;
}
@JsonView(Views.Public.class)
@PostMapping("/pages/{defaultPageId}")
public Mono<ResponseDTO<Layout>> createLayout(
@PathVariable String defaultPageId,
@Valid @RequestBody Layout layout,
@RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) {
return service.createLayout(defaultPageId, layout, branchName)
.map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null));
}
@JsonView(Views.Public.class)
@GetMapping("/{layoutId}/pages/{defaultPageId}")
public Mono<ResponseDTO<Layout>> getLayout(
@ -83,11 +73,11 @@ public class LayoutControllerCE {
@PathVariable String pageId,
@RequestParam String applicationId,
@PathVariable String layoutId,
@RequestBody Layout layout,
@RequestBody LayoutUpdateDTO dto,
@RequestHeader(name = FieldName.BRANCH_NAME, required = false) String branchName) {
log.debug("update layout received for page {}", pageId);
return updateLayoutService
.updateLayout(pageId, applicationId, layoutId, layout, branchName)
.updateLayout(pageId, applicationId, layoutId, dto.toLayout(), branchName)
.map(created -> new ResponseDTO<>(HttpStatus.OK.value(), created, null));
}

View File

@ -0,0 +1,12 @@
package com.appsmith.server.dtos;
import com.appsmith.server.domains.Layout;
import net.minidev.json.JSONObject;
public record LayoutUpdateDTO(JSONObject dsl) {
public Layout toLayout() {
Layout layout = new Layout();
layout.setDsl(dsl);
return layout;
}
}

View File

@ -7,8 +7,6 @@ public interface LayoutServiceCE {
Mono<Layout> createLayout(String pageId, Layout layout);
Mono<Layout> createLayout(String defaultPageId, Layout layout, String branchName);
Mono<Layout> getLayout(String pageId, String layoutId, Boolean viewMode);
Mono<Layout> getLayout(String defaultPageId, String layoutId, Boolean viewMode, String branchName);

View File

@ -60,17 +60,6 @@ public class LayoutServiceCEImpl implements LayoutServiceCE {
.then(Mono.just(layout));
}
@Override
public Mono<Layout> createLayout(String defaultPageId, Layout layout, String branchName) {
if (StringUtils.isEmpty(branchName)) {
return createLayout(defaultPageId, layout);
}
return newPageService
.findByBranchNameAndDefaultPageId(branchName, defaultPageId, pagePermission.getEditPermission())
.flatMap(branchedPage -> createLayout(branchedPage.getId(), layout))
.map(responseUtils::updateLayoutWithDefaultResources);
}
@Override
public Mono<Layout> getLayout(String pageId, String layoutId, Boolean viewMode) {
return newPageService