Merge branch 'feature/response-meta' into 'master'
Modifying the ResponseDTO to contain the ResponseMeta object. Also moving... See merge request theappsmith/internal-tools-server!22
This commit is contained in:
commit
64440cf3e7
|
|
@ -11,8 +11,6 @@ services:
|
|||
cache:
|
||||
paths:
|
||||
- ./.m2/repository
|
||||
# keep cache across branch
|
||||
key: "$CI_BUILD_REF_NAME"
|
||||
|
||||
variables:
|
||||
DOCKER_DRIVER: overlay
|
||||
|
|
|
|||
|
|
@ -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<S extends CrudService, T extends BaseDomain
|
|||
|
||||
@PostMapping
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public Mono<ResponseDto<T>> create(@Valid @RequestBody T resource) throws AppsmithException {
|
||||
public Mono<ResponseDTO<T>> 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<ResponseDto<T>> getAll() {
|
||||
public Mono<ResponseDTO<T>> 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<ResponseDto<T>> getById(@PathVariable ID id) {
|
||||
public Mono<ResponseDTO<T>> 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<ResponseDto<T>> update(@PathVariable ID id, @RequestBody T resource) {
|
||||
public Mono<ResponseDTO<T>> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ResponseDto<Layout>> createLayout(@PathVariable String pageId, @Valid @RequestBody Layout layout) {
|
||||
public Mono<ResponseDTO<Layout>> 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<ResponseDto<Layout>> getLayout(@PathVariable String pageId, @PathVariable String layoutId) {
|
||||
public Mono<ResponseDTO<Layout>> 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<ResponseDto<Layout>> updateLayout(@PathVariable String pageId, @PathVariable String layoutId, @RequestBody Layout layout) {
|
||||
public Mono<ResponseDTO<Layout>> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<PluginService, Plugin, Stri
|
|||
|
||||
@PostMapping("/install")
|
||||
@ResponseStatus(HttpStatus.CREATED)
|
||||
public Mono<ResponseDto<Organization>> install(@Valid @RequestBody PluginOrgDTO plugin) {
|
||||
public Mono<ResponseDTO<Organization>> 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<ResponseDto<Organization>> uninstall(@Valid @RequestBody PluginOrgDTO plugin) {
|
||||
public Mono<ResponseDTO<Organization>> 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<WidgetService, Widget, Stri
|
|||
}
|
||||
|
||||
@GetMapping("/name/{name}")
|
||||
public Mono<ResponseDto<Widget>> getByName(@PathVariable String name) {
|
||||
public Mono<ResponseDTO<Widget>> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<T> 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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<T> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ResponseDto<ErrorDTO>> catchAppsmithException(AppsmithException e, ServerWebExchange exchange) {
|
||||
public Mono<ResponseDTO<ErrorDTO>> 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<ResponseDto<ErrorDTO>> catchException(Exception e, ServerWebExchange exchange) {
|
||||
public Mono<ResponseDTO<ErrorDTO>> 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())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user