conradbekondo / inventory-api

0 stars 0 forks source link

Error while fetching Products from API #12

Closed conradbekondo closed 2 months ago

conradbekondo commented 2 months ago

I get this error while trying to fetch data from the GET /api/inventory/products endpoint after updating to the latest docker image.

org.springframework.aop.AopInvocationException: Null return value from advice does not match primitive return type for: public abstract int ca.quickdo.springintro.repository.MovementsRepository.calculateTotalQuantityByProduct(java.lang.Integer)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:255) ~[spring-aop-5.3.31.jar!/:5.3.31]
        at jdk.proxy2/jdk.proxy2.$Proxy116.calculateTotalQuantityByProduct(Unknown Source) ~[na:na]
        at ca.quickdo.springintro.controller.InventoryController.lambda$getProducts$0(InventoryController.java:66) ~[classes!/:na]
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197) ~[na:na]
        at java.base/java.util.ArrayList$Itr.forEachRemaining(ArrayList.java:1003) ~[na:na]
        at java.base/java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1845) ~[na:na]
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[na:na]
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[na:na]
IlorsonDel commented 2 months ago

I went through and I understood that, the error message suggests that there is an issue with the return type of the calculateTotalQuantityByProduct method in the MovementsRepository. The method is defined to return an int primitive type, but the advice (interceptor) used in the AOP invocation is returning a null value, which does not match the primitive return type.

So I modified the calculateTotalQuantityByProduct method to return an integer

conradbekondo commented 2 months ago

@IlorsonDel you can just use Optional<Integer> as return type

IlorsonDel commented 2 months ago

Thanks sir, I did so, and pushed back

conradbekondo commented 2 months ago

@IlorsonDel did you build the application on your local machine before pushing?

https://github.com/conradbekondo/inventory-api/actions/runs/8910454921/job/24469764276#step:5:27

IlorsonDel commented 2 months ago

I build it and solve the remaining errors. Am just from pushing it back, you can look at it !