Skip to content

Commit

Permalink
Merge branch 'release/4.3.0.SNAPSHOT.20220829'
Browse files Browse the repository at this point in the history
  • Loading branch information
JesusHdez960717 committed Aug 29, 2022
2 parents caac921 + 080a4af commit e912d0e
Show file tree
Hide file tree
Showing 26 changed files with 770 additions and 209 deletions.
17 changes: 16 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
* 4.1.1.SNAPSHOT.20220000:
* 4.3.0.SNAPSHOT.20220829:
* **VALIDATION** :
* **BUG FIX** :raised_bug: : Filter primitive values for not validate.
* **GENERAL** :
* **IMPROVEMENT** :raised: : Created Api UC & Api Controllee, an UC and a Controller wich return ApiResponse by default.
* **IMPROVEMENT** :raised: : Find by return null if id not found.
* **IMPROVEMENT** :raised: : Created builder factory in ApiResponse for message.
* **IMPROVEMENT** :raised: : Created ResponseExtractor.
* **IMPROVEMENT** :raised: : Created Validation for Enum values.
* **IMPROVEMENT** :raised: : Upgrade gradle dependencies.

* 4.2.2.RELEASE.20220613:
* **VALIDATION** :
* **IMPROVEMENT** :raised_hands: : Add recursive validation.

* 4.1.1.SNAPSHOT.20220531:
* **GENERAL** :
* **IMPROVEMENT** :raised: : Change `count()` to type `long`.

Expand Down
20 changes: 11 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
plugins {
id 'java'
id 'java'
}

group = 'dev.root101.clean'

version = '4.2.2.RELEASE.20220613'
version = '4.3.0.SNAPSHOT.20220829'

repositories {
jcenter()
Expand All @@ -18,15 +18,17 @@ dependencies{
//javax.validation.NoProviderFoundException: Unable to create a Configuration, because no Bean Validation provider could be found. Add a provider like Hibernate Validator (RI) to your classpath.
implementation 'org.hibernate.validator:hibernate-validator:6.2.3.Final'

//integration with spring
implementation 'org.springframework:spring-web:5.3.20'
implementation 'org.springframework:spring-webmvc:5.3.20'
implementation 'org.springframework:spring-context:5.3.20'
//repo
implementation 'org.springframework.data:spring-data-jpa:2.7.0'
//spring
implementation 'org.springframework.boot:spring-boot-starter-web:2.7.3'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.3'

//Jackson
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.3'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.13.3'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.3'

//lombok
implementation 'org.projectlombok:lombok:1.18.24'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2022 Root101 ([email protected], +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.clean.core.app.usecase;

import dev.root101.clean.core.app.domain.DomainObject;
import dev.root101.clean.core.framework.ApiResponse;
import java.util.List;

/**
*
* @author Root101 ([email protected], +53-5-426-8660)
* @author JesusHdezWaterloo@Github
* @param <Domain>
* @param <ID>
*/
public interface ApiCRUDUseCase<Domain extends DomainObject<ID>, ID> extends AbstractUseCase {

public ApiResponse<Domain> create(Domain newObject) throws RuntimeException;

public ApiResponse<Domain> edit(Domain objectToEdit) throws RuntimeException;

public ApiResponse destroy(Domain objectToDestroy) throws RuntimeException;

public ApiResponse destroyById(ID keyId) throws RuntimeException;

public ApiResponse<Domain> findBy(ID keyId) throws RuntimeException;

public ApiResponse<List<Domain>> findAll() throws RuntimeException;

/**
* By default return the size of the findAll() list.
*
* @return findAll().size()
* @throws RuntimeException
*/
public default ApiResponse<Long> count() throws RuntimeException {
return ApiResponse.buildSucces(
(long) findAll().getData().size()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package dev.root101.clean.core.app.usecase;

import dev.root101.clean.core.app.domain.DomainObject;
import dev.root101.clean.core.framework.ApiResponse;
import dev.root101.clean.core.repo.CRUDRepository;
import java.util.List;

public class ApiDefaultCRUDUseCase<Domain extends DomainObject<ID>, ID, CRUDRepo extends CRUDRepository<Domain, ID>> implements ApiCRUDUseCase<Domain, ID> {

private final DefaultCRUDUseCase<Domain, ID, CRUDRepo> crudUC;

public ApiDefaultCRUDUseCase(CRUDRepo crudRepo) {
this.crudUC = new DefaultCRUDUseCase(crudRepo);
}

@Override
public ApiResponse<Domain> create(Domain newObject) throws RuntimeException {
return ApiResponse.buildSucces(
crudUC.create(newObject)
);
}

@Override
public ApiResponse<Domain> edit(Domain objectToEdit) throws RuntimeException {
return ApiResponse.buildSucces(
crudUC.edit(objectToEdit)
);
}

@Override
public ApiResponse destroy(Domain objectToDestroy) throws RuntimeException {
crudUC.destroy(objectToDestroy);
return ApiResponse.buildSuccesVoid();
}

@Override
public ApiResponse destroyById(ID keyId) throws RuntimeException {
crudUC.destroyById(keyId);
return ApiResponse.buildSuccesVoid();
}

@Override
public ApiResponse<Domain> findBy(ID keyId) throws RuntimeException {
return ApiResponse.buildSucces(
crudUC.findBy(keyId)
);
}

@Override
public ApiResponse<List<Domain>> findAll() throws RuntimeException {
return ApiResponse.buildSucces(
crudUC.findAll()
);
}

@Override
public ApiResponse<Long> count() throws RuntimeException {
return ApiResponse.buildSucces(
crudUC.count()
);
}

}
25 changes: 21 additions & 4 deletions src/main/java/dev/root101/clean/core/exceptions/ApiException.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,37 @@
*/
public class ApiException extends RuntimeException {

private final HttpStatus status;
private final int rawStatusCode;
private final String message;

public ApiException(HttpStatus status) {
super(status.getReasonPhrase());
this.status = status;
this.rawStatusCode = status.value();
this.message = status.getReasonPhrase();
}

public ApiException(HttpStatus status, String message) {
super(message);
this.status = status;
this.rawStatusCode = status.value();
this.message = message;
}

public ApiException(int rawStatusCode, String message) {
super(message);
this.rawStatusCode = rawStatusCode;
this.message = message;
}

public HttpStatus status() {
return status;
return HttpStatus.resolve(rawStatusCode);
}

public int getRawStatusCode() {
return rawStatusCode;
}

public String getReasonPhrase() {
return message;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public static <T> ApiResponse<T> buildSuccesVoid() {
public static <T> ApiResponse<T> buildSucces(T data) {
return new ApiResponse<>("200", "Success", data);
}

public static <T> ApiResponse<T> buildSucces(String msg, T data) {
return new ApiResponse<>("200", msg, data);
}

private String status;
private String msg;
private T data;
Expand Down
Loading

0 comments on commit e912d0e

Please sign in to comment.