diff --git a/app/server/.gitlab-ci.yml b/app/server/.gitlab-ci.yml index f3c69097d7..351d4cce9c 100644 --- a/app/server/.gitlab-ci.yml +++ b/app/server/.gitlab-ci.yml @@ -11,8 +11,6 @@ services: cache: paths: - ./.m2/repository - # keep cache across branch - key: "$CI_BUILD_REF_NAME" variables: DOCKER_DRIVER: overlay diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/BaseController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/BaseController.java index f61763efed..f2a94cc7ae 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/BaseController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/BaseController.java @@ -1,7 +1,7 @@ package com.appsmith.server.controllers; import com.appsmith.server.domains.BaseDomain; -import com.appsmith.server.dtos.ResponseDto; +import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.services.CrudService; import lombok.RequiredArgsConstructor; @@ -26,31 +26,31 @@ public abstract class BaseController> create(@Valid @RequestBody T resource) throws AppsmithException { + public Mono> create(@Valid @RequestBody T resource) throws AppsmithException { log.debug("Going to create resource {}", resource.getClass().getName()); return service.create(resource) - .map(created -> new ResponseDto<>(HttpStatus.CREATED.value(), created, null)); + .map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null)); } @GetMapping("") - public Flux> getAll() { + public Mono> getAll() { log.debug("Going to get all resources"); - return service.get() - .map(resources -> new ResponseDto<>(HttpStatus.OK.value(), resources, null)); + return service.get().collectList() + .map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null)); } @GetMapping("/{id}") - public Mono> getById(@PathVariable ID id) { + public Mono> getById(@PathVariable ID id) { log.debug("Going to get resource for id: {}", id); return service.getById(id) - .map(resources -> new ResponseDto<>(HttpStatus.OK.value(), resources, null)); + .map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null)); } @PutMapping("/{id}") - public Mono> update(@PathVariable ID id, @RequestBody T resource) { + public Mono> update(@PathVariable ID id, @RequestBody T resource) { log.debug("Going to update resource with id: {}", id); return service.update(id, resource) - .map(updatedResource -> new ResponseDto<>(HttpStatus.OK.value(), updatedResource, null)); + .map(updatedResource -> new ResponseDTO<>(HttpStatus.OK.value(), updatedResource, null)); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java index 23163c6429..b1a244ec16 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/LayoutController.java @@ -2,7 +2,7 @@ package com.appsmith.server.controllers; import com.appsmith.server.constants.Url; import com.appsmith.server.domains.Layout; -import com.appsmith.server.dtos.ResponseDto; +import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.services.LayoutService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -29,21 +29,21 @@ public class LayoutController { } @PostMapping("/pages/{pageId}") - public Mono> createLayout(@PathVariable String pageId, @Valid @RequestBody Layout layout) { + public Mono> createLayout(@PathVariable String pageId, @Valid @RequestBody Layout layout) { return service.createLayout(pageId, layout) - .map(created -> new ResponseDto<>(HttpStatus.CREATED.value(), created, null)); + .map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null)); } @GetMapping("/{layoutId}/pages/{pageId}") - public Mono> getLayout(@PathVariable String pageId, @PathVariable String layoutId) { + public Mono> getLayout(@PathVariable String pageId, @PathVariable String layoutId) { return service.getLayout(pageId, layoutId) - .map(created -> new ResponseDto<>(HttpStatus.CREATED.value(), created, null)); + .map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null)); } @PutMapping("/{layoutId}/pages/{pageId}") - public Mono> updateLayout(@PathVariable String pageId, @PathVariable String layoutId, @RequestBody Layout layout) { + public Mono> updateLayout(@PathVariable String pageId, @PathVariable String layoutId, @RequestBody Layout layout) { return service.updateLayout(pageId, layoutId, layout) - .map(created -> new ResponseDto<>(HttpStatus.CREATED.value(), created, null)); + .map(created -> new ResponseDTO<>(HttpStatus.CREATED.value(), created, null)); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java index 3f55c6bef6..caffb5bfff 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PluginController.java @@ -4,7 +4,7 @@ import com.appsmith.server.constants.Url; import com.appsmith.server.domains.Organization; import com.appsmith.server.domains.Plugin; import com.appsmith.server.dtos.PluginOrgDTO; -import com.appsmith.server.dtos.ResponseDto; +import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.services.PluginService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -29,16 +29,16 @@ public class PluginController extends BaseController> install(@Valid @RequestBody PluginOrgDTO plugin) { + public Mono> install(@Valid @RequestBody PluginOrgDTO plugin) { return service.installPlugin(plugin) - .map(organization -> new ResponseDto<>(HttpStatus.CREATED.value(), organization, null)); + .map(organization -> new ResponseDTO<>(HttpStatus.CREATED.value(), organization, null)); } @PostMapping("/uninstall") @ResponseStatus(HttpStatus.CREATED) - public Mono> uninstall(@Valid @RequestBody PluginOrgDTO plugin) { + public Mono> uninstall(@Valid @RequestBody PluginOrgDTO plugin) { return service.uninstallPlugin(plugin) - .map(organization -> new ResponseDto<>(HttpStatus.CREATED.value(), organization, null)); + .map(organization -> new ResponseDTO<>(HttpStatus.CREATED.value(), organization, null)); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/WidgetController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/WidgetController.java index db08919535..c96c596a5d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/WidgetController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/WidgetController.java @@ -2,7 +2,7 @@ package com.appsmith.server.controllers; import com.appsmith.server.constants.Url; import com.appsmith.server.domains.Widget; -import com.appsmith.server.dtos.ResponseDto; +import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.services.WidgetService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; @@ -22,8 +22,8 @@ public class WidgetController extends BaseController> getByName(@PathVariable String name) { + public Mono> getByName(@PathVariable String name) { return service.getByName(name) - .map(widget -> new ResponseDto<>(HttpStatus.OK.value(), widget, null)); + .map(widget -> new ResponseDTO<>(HttpStatus.OK.value(), widget, null)); } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseDTO.java new file mode 100644 index 0000000000..ecd832fc5e --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseDTO.java @@ -0,0 +1,39 @@ +package com.appsmith.server.dtos; + +import com.appsmith.server.exceptions.ErrorDTO; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.io.Serializable; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ResponseDTO implements Serializable { + + private static final long serialVersionUID = 8965011907233699993L; + + private ResponseMetaDTO responseMeta; + + private T data; + + public ResponseDTO(int status, T data, String message) { + this.responseMeta = new ResponseMetaDTO(status, message); + this.data = data; + } + + public ResponseDTO(int status, T data, String message, boolean success) { + this.responseMeta = new ResponseMetaDTO(status, message, success); + this.data = data; + } + + public ResponseDTO(int status, ErrorDTO errorDTO) { + this.responseMeta = new ResponseMetaDTO(status, errorDTO); + } + +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseDto.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseDto.java deleted file mode 100644 index a931983b60..0000000000 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseDto.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.appsmith.server.dtos; - -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import java.io.Serializable; - -@Getter -@Setter -@ToString -@NoArgsConstructor -@AllArgsConstructor -public class ResponseDto implements Serializable { - - private static final long serialVersionUID = 8965011907233699993L; - - private int status; - - private T data; - - private String message; - - private boolean success = true; - - public ResponseDto(int status, T data, String message) { - this.status = status; - this.data = data; - this.message = message; - } - -} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseMetaDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseMetaDTO.java new file mode 100644 index 0000000000..fdb83a76f3 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/ResponseMetaDTO.java @@ -0,0 +1,41 @@ +package com.appsmith.server.dtos; + +import com.appsmith.server.exceptions.ErrorDTO; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +public class ResponseMetaDTO { + + private int status; + + private String message; + + private boolean success = true; + + private ErrorDTO error; + + public ResponseMetaDTO(int status, String message, boolean success) { + this.status = status; + this.message = message; + this.success = success; + } + + public ResponseMetaDTO(int status, String message) { + this.status = status; + this.message = message; + } + + public ResponseMetaDTO(int status, ErrorDTO errorDTO) { + this.status = status; + this.error = errorDTO; + this.success = false; + } +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/ErrorDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/ErrorDTO.java index 3399703740..b1fbb7a7b3 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/ErrorDTO.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/ErrorDTO.java @@ -13,7 +13,7 @@ import java.io.Serializable; @AllArgsConstructor public class ErrorDTO implements Serializable { - private int errorCode; + private int code; - private String errorMessage; + private String message; } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java index b154a39c5b..ebf6f48eb1 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/exceptions/GlobalExceptionHandler.java @@ -1,6 +1,6 @@ package com.appsmith.server.exceptions; -import com.appsmith.server.dtos.ResponseDto; +import com.appsmith.server.dtos.ResponseDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ControllerAdvice; @@ -28,10 +28,10 @@ public class GlobalExceptionHandler { */ @ExceptionHandler @ResponseBody - public Mono> catchAppsmithException(AppsmithException e, ServerWebExchange exchange) { + public Mono> catchAppsmithException(AppsmithException e, ServerWebExchange exchange) { exchange.getResponse().setStatusCode(HttpStatus.resolve(e.getHttpStatus())); log.error("", e); - return Mono.just(new ResponseDto<>(e.getHttpStatus(), new ErrorDTO(e.getAppErrorCode(), e.getMessage()), null, false)); + return Mono.just(new ResponseDTO<>(e.getHttpStatus(), new ErrorDTO(e.getAppErrorCode(), e.getMessage()))); } /** @@ -44,11 +44,11 @@ public class GlobalExceptionHandler { */ @ExceptionHandler @ResponseBody - public Mono> catchException(Exception e, ServerWebExchange exchange) { + public Mono> catchException(Exception e, ServerWebExchange exchange) { exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR); log.error("", e); - return Mono.just(new ResponseDto<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), new ErrorDTO(AppsmithError.INTERNAL_SERVER_ERROR.getHttpErrorCode(), - AppsmithError.INTERNAL_SERVER_ERROR.getMessage()), null, false)); + return Mono.just(new ResponseDTO<>(HttpStatus.INTERNAL_SERVER_ERROR.value(), new ErrorDTO(AppsmithError.INTERNAL_SERVER_ERROR.getHttpErrorCode(), + AppsmithError.INTERNAL_SERVER_ERROR.getMessage()))); } }