Skip to content

Commit a6a8caa

Browse files
committed
feat: add mappers for brand, product and user
1 parent b6b19b8 commit a6a8caa

File tree

3 files changed

+52
-0
lines changed

3 files changed

+52
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package br.com.catalog.utils;
2+
3+
import br.com.catalog.models.Brand;
4+
import br.com.catalog.services.impls.dtos.BrandDTO;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.util.function.Function;
8+
9+
@Component
10+
public class BrandToResponse implements Function<Brand, BrandDTO> {
11+
@Override
12+
public BrandDTO apply(Brand brand) {
13+
return new BrandDTO(brand.getName());
14+
}
15+
}
16+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package br.com.catalog.utils;
2+
3+
import br.com.catalog.models.Product;
4+
import br.com.catalog.services.impls.dtos.ProductDTO;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.util.function.Function;
8+
9+
@Component
10+
public class ProductToResponse implements Function<Product, ProductDTO> {
11+
@Override
12+
public ProductDTO apply(Product product) {
13+
return ProductDTO.builder()
14+
.name(product.getName())
15+
.brand(product.getBrand().getName())
16+
.description(product.getDescription())
17+
.price(product.getPrice())
18+
.stockQuanitity(product.getStockQuantity())
19+
.build();
20+
}
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package br.com.catalog.utils;
2+
3+
import br.com.catalog.models.User;
4+
import br.com.catalog.services.impls.dtos.UserResponseDTO;
5+
import org.springframework.stereotype.Component;
6+
7+
import java.util.function.Function;
8+
9+
@Component
10+
public class UserToResponse implements Function<User, UserResponseDTO> {
11+
@Override
12+
public UserResponseDTO apply(User user) {
13+
return new UserResponseDTO(user.getUsername(), user.getRole().toString());
14+
}
15+
}

0 commit comments

Comments
 (0)