Skip to content

Commit

Permalink
Nueva clase CommonMapper
Browse files Browse the repository at this point in the history
- Se agrega a las demás clases mapper.
  • Loading branch information
nmarulo committed Nov 8, 2024
1 parent 67e96b2 commit 0154117
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import dev.nmarulo.depensaapp.app.productshoppinglist.ProductHasShoppingList;
import dev.nmarulo.depensaapp.app.shoppinglist.ShoppingList;
import dev.nmarulo.depensaapp.app.unitytypes.UnitType;
import dev.nmarulo.depensaapp.commons.mapper.CommonMapper;
import org.springframework.data.domain.Page;

public final class ProductMapper {
public final class ProductMapper extends CommonMapper {

private ProductMapper() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import dev.nmarulo.depensaapp.app.productshoppinglist.ProductHasShoppingList;
import dev.nmarulo.depensaapp.app.shoppinglist.dtos.*;
import dev.nmarulo.depensaapp.commons.mapper.CommonMapper;
import org.springframework.data.domain.Page;

public final class ShoppingListMapper {
public final class ShoppingListMapper extends CommonMapper {

private ShoppingListMapper() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package dev.nmarulo.depensaapp.app.unitytypes;

import dev.nmarulo.depensaapp.app.unitytypes.dtos.FindAllUnitTypeRes;
import dev.nmarulo.depensaapp.commons.mapper.CommonMapper;
import org.springframework.data.domain.Page;

public final class UnitTypeMapper {
public final class UnitTypeMapper extends CommonMapper {

private UnitTypeMapper() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import dev.nmarulo.depensaapp.app.shoppinglist.ShoppingList;
import dev.nmarulo.depensaapp.app.users.dtos.FindByIdUserRes;
import dev.nmarulo.depensaapp.commons.mapper.CommonMapper;

public final class UserMapper {
public final class UserMapper extends CommonMapper {

private UserMapper() {
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.nmarulo.depensaapp.commons.mapper;

import dev.nmarulo.depensaapp.commons.dtos.PagingAndSortingRes;
import org.springframework.data.domain.Page;

import java.util.function.Function;
import java.util.function.Supplier;

public class CommonMapper {

protected static <E, R extends PagingAndSortingRes<O>, O> R pageTo(final Page<E> page,
final Supplier<R> supplier,
final Function<E, O> function) {
final var response = supplier.get();
final var content = page.stream()
.map(function)
.toList();

response.setContent(content);
response.setCurrentPage(page.getNumber());
response.setPageSize(page.getNumberOfElements());
response.setTotalPages(page.getTotalPages());
response.setTotal(page.getTotalElements());

return response;
}

}

0 comments on commit 0154117

Please sign in to comment.