-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/4.3.0.SNAPSHOT.20220829'
- Loading branch information
Showing
26 changed files
with
770 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/main/java/dev/root101/clean/core/app/usecase/ApiCRUDUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/main/java/dev/root101/clean/core/app/usecase/ApiDefaultCRUDUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.