Skip to content

Commit

Permalink
feat: implement filterWithSingleResult in JpaCrudService
Browse files Browse the repository at this point in the history
Closes #78
  • Loading branch information
mlopezFC committed Jun 25, 2024
1 parent 6c23b71 commit c7d1786
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package com.flowingcode.backendcore.service;

import com.flowingcode.backendcore.model.ErrorDescription;
import com.flowingcode.backendcore.model.QuerySpec;
import com.flowingcode.backendcore.service.validation.CreationValidator;
import com.flowingcode.backendcore.service.validation.DeletionValidator;
import com.flowingcode.backendcore.service.validation.UpdateValidator;
import com.flowingcode.backendcore.validation.CreationValidationException;
import com.flowingcode.backendcore.validation.DeletionValidationException;
import com.flowingcode.backendcore.validation.UpdateValidationException;
import com.flowingcode.backendcore.validation.ValidationException;
import com.flowingcode.backendcore.validation.ValidationSupport;
import com.flowingcode.backendcore.validation.Validator;
import java.lang.reflect.Method;
import java.lang.reflect.UndeclaredThrowableException;
import java.util.Collections;
Expand All @@ -15,19 +26,6 @@
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.util.Streamable;

import com.flowingcode.backendcore.model.ErrorDescription;
import com.flowingcode.backendcore.model.QuerySpec;
import com.flowingcode.backendcore.service.CrudService;
import com.flowingcode.backendcore.service.validation.CreationValidator;
import com.flowingcode.backendcore.service.validation.DeletionValidator;
import com.flowingcode.backendcore.service.validation.UpdateValidator;
import com.flowingcode.backendcore.validation.CreationValidationException;
import com.flowingcode.backendcore.validation.DeletionValidationException;
import com.flowingcode.backendcore.validation.UpdateValidationException;
import com.flowingcode.backendcore.validation.ValidationException;
import com.flowingcode.backendcore.validation.ValidationSupport;
import com.flowingcode.backendcore.validation.Validator;

public abstract class JpaCrudService<T, K> implements CrudService<T, K> {

protected abstract CrudRepository<T, K> getCrudRepository();
Expand Down Expand Up @@ -108,6 +106,11 @@ public List<T> filter(QuerySpec filter) {
return getExecutor().findAll(buildSpecification(filter), buildPageable(filter)).toList();
}
}

@Override
public Optional<T> filterWithSingleResult(QuerySpec filter) {
return getExecutor().findOne(buildSpecification(filter));
}

@Override
public long count(QuerySpec filter) {
Expand Down

0 comments on commit c7d1786

Please sign in to comment.