diff --git a/CHANGELOG.md b/CHANGELOG.md index a878e02..1287dec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +* 5.1.2.RELEASE.20240211: + * **REMOVED** :-: : Removed `ApiResponse` + * 5.1.1.RELEASE.20231215: * **DOCS** : * **UPDATE** :+1: : Update `how to use it`. diff --git a/README.md b/README.md index ecde336..744283c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ @@ -9,7 +9,7 @@ Multilanguage: This library aims to provide standards and utilities that make work easier when creating microservices. -Docs updated for version: `X.X.X.RELEASE.2023XXXX` +Docs updated for version: `5.1.2.RELEASE.20240211` ## Table of Contents - [1 - Validations](#1) @@ -24,9 +24,6 @@ Docs updated for version: `X.X.X.RELEASE.2023XXXX` - [1.6.3 - Size Exact](#1.6.3) - [2 - Exceptions](#2) - [4 - Rest](#3) - - [4.1 - Api response](#3.1) - - [4.2 - Response Extractor (Next)](#3.2) - - [4.3 - Rest Template utils (Next)](#3.3) - [5 - Utils](#4) - [5.1 - Jackson](#4.1) - [5.2 - Enum mappeable](#4.2) @@ -86,17 +83,17 @@ ValidationException{ ValidationErrorMessage[ source = root[0].parentName, invalid_value = Pepito, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ], ValidationErrorMessage[ source = root[1].childName, invalid_value = Pepito Junior, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ], ValidationErrorMessage[ source = root[2].childName, invalid_value = Pepito Junior 2, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ] ] } @@ -131,7 +128,7 @@ ValidationException{ ValidationErrorMessage[ source = parentName, invalid_value = Pepito Simple, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ] ] } @@ -181,17 +178,17 @@ ValidationException{ ValidationErrorMessage[ source = parentName, invalid_value = Pepito, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ], ValidationErrorMessage[ source = childrens[0].childName, invalid_value = Pepito Junior, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ], ValidationErrorMessage[ source = childrens[1].childName, invalid_value = Pepito Junior 2, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ] ] } @@ -226,7 +223,7 @@ ValidationException{ ValidationErrorMessage[ source = parent_name, // => note here how the value change from `parentName` to `parent_name` invalid_value = Pepito Simple, - message = el tamaño debe estar entre 1 y 5 + message = el tama�o debe estar entre 1 y 5 ] ] } @@ -480,63 +477,6 @@ Para estandarizar el uso de las respuestas HTTP se crearon las excepciones(mas c Oficial docs for HTTP Responses [here](https://datatracker.ietf.org/doc/html/rfc7231). -### 3.1 Api Response -The idea of `ApiResponse` is to generalize API responses to a standard. -ALL API responses must follow this guideline. -The `ApiResponse` class has: -- `status`: Representing the HTTP code of the response. -- `message`: The response message to the request. -- `data`: The data or information of the response, if there is a response. -Ejemplos: -1 - A request to modify a record that is executed successfully must return: -```java -ApiResponse{ - status = 200, - message = "Success", - data = null -} -``` - -2 - A request to obtain a list must return: -```java -ApiResponse{ - status = 200, - message = "Success", - data = [ - "Data 1", - "Data 2", - "Data 3" - ] -} -``` - -3 - A request to obtain an object must return: -```java -ApiResponse{ - status = 200, - message = "Success", - data = SomeObject{ - field1 = "some data", - field2 = "some data 2" - } -} -``` - -4 - A request to create users with a name that already exists should return: -```java -ApiResponse{ - status = 409, - message = "Username already exists", -} -``` - -How to use it: -- For response 200 you can use: `ApiResponse.success()`, which by default says `status = 200`, `message = success` and `data = null`. -- For response 200 you can use: `ApiResponse.success(data)`, which by default says `status = 200` and `message = success`. -- For response 200 you can use: `ApiResponse.success(message, data)`, which by default says `status = 200`. -- For generic responses you can use: `ApiResponse.build(status, message, data)`. -- To extract a response from a `ResponseEntity` you can use: `ApiResponse.build(status, message, data)`, which by default says `status = response.getStatusCode().value()`, `message = response. getStatusCode().toString()` and `data = response.getBody()`. - ## 4 - Utils ### 4.1 - Jackson diff --git a/build.gradle b/build.gradle index 7fe8ab4..e7ff65c 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { group = 'dev.root101.commons' -version = '5.1.1.RELEASE.20231215' +version = '5.1.2.RELEASE.20240211' repositories { jcenter() diff --git a/src/main/java/dev/root101/commons/rest/ApiResponse.java b/src/main/java/dev/root101/commons/rest/ApiResponse.java deleted file mode 100644 index 1e4c25c..0000000 --- a/src/main/java/dev/root101/commons/rest/ApiResponse.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright 2022 Root101 (jhernandezb96@gmail.com, +53-5-426-8660). - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Or read it directly from LICENCE.txt file at the root of this project. - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package dev.root101.commons.rest; - -import org.springframework.http.ResponseEntity; - -/** - * - * @author Root101 (jhernandezb96@gmail.com, +53-5-426-8660) - * @author JesusHdez960717@Github - * @param - */ -public class ApiResponse { - - public static ApiResponse build(ResponseEntity response) { - return new ApiResponse<>( - String.valueOf(response.getStatusCode().value()), - response.getStatusCode().toString(), - response.getBody() - ); - } - - public static ApiResponse build(String status, String message, T data) { - return new ApiResponse<>(status, message, data); - } - - public static ApiResponse success() { - return ApiResponse.success(null); - } - - public static ApiResponse success(T data) { - return new ApiResponse<>("200", "Success", data); - } - - public static ApiResponse success(String message, T data) { - return new ApiResponse<>("200", message, data); - } - - private String status; - private String message; - private T data; - - public ApiResponse() { - } - - public ApiResponse(String status, String msg, T data) { - this.status = status; - this.message = msg; - this.data = data; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMsg() { - return message; - } - - public void setMsg(String msg) { - this.message = msg; - } - - public T getData() { - return data; - } - - public void setData(T data) { - this.data = data; - } - -}