Skip to content

Commit e2f579c

Browse files
committed
feat: update ItemMapper to use ItemDTORequest and enhance response DTOs for item, category, and unit
1 parent 13fb67e commit e2f579c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package com.omatheusmesmo.shoppmate.item.mapper;
22

3+
import com.omatheusmesmo.shoppmate.category.dto.CategoryResponseDTO;
34
import com.omatheusmesmo.shoppmate.category.entity.Category;
45
import com.omatheusmesmo.shoppmate.category.repository.CategoryRepository;
5-
import com.omatheusmesmo.shoppmate.item.dto.ItemDTO;
6+
import com.omatheusmesmo.shoppmate.item.dto.ItemDTORequest;
7+
import com.omatheusmesmo.shoppmate.item.dto.ItemResponseDTO;
68
import com.omatheusmesmo.shoppmate.item.entity.Item;
9+
import com.omatheusmesmo.shoppmate.unit.dto.UnitResponseDTO;
710
import com.omatheusmesmo.shoppmate.unit.entity.Unit;
811
import com.omatheusmesmo.shoppmate.unit.repository.UnitRepository;
912
import org.springframework.beans.factory.annotation.Autowired;
@@ -21,7 +24,7 @@ public class ItemMapper {
2124
private UnitRepository unitRepository;
2225

2326

24-
public Item toEntity(ItemDTO dto) {
27+
public Item toEntity(ItemDTORequest dto) {
2528
Category category = categoryRepository.findById(dto.idCategory())
2629
.orElseThrow(() -> new NoSuchElementException("Category not found with id: " + dto.idCategory()));
2730

@@ -35,19 +38,18 @@ public Item toEntity(ItemDTO dto) {
3538
return item;
3639
}
3740

38-
//
39-
// public ItemResponseDTO toResponseDTO(Item entity) {
40-
//
41-
// CategoryDTO categoryDto = new CategoryDTO(entity.getCategory().getId(), entity.getCategory().getName());
42-
// UnitDTO unitDto = new UnitDTO(entity.getUnit().getId(), entity.getUnit().getName(), entity.getUnit().getSymbol());
43-
//
44-
// return new ItemResponseDTO(
45-
// entity.getId(),
46-
// entity.getName(),
47-
// categoryDto,
48-
// unitDto
49-
//
50-
// );
51-
// }
41+
42+
public ItemResponseDTO toResponseDTO(Item entity) {
43+
44+
CategoryResponseDTO categoryDto = new CategoryResponseDTO(entity.getCategory().getId(), entity.getCategory().getName());
45+
UnitResponseDTO unitDto = new UnitResponseDTO(entity.getUnit().getId(), entity.getUnit().getSymbol());
46+
47+
return new ItemResponseDTO(
48+
entity.getId(),
49+
entity.getName(),
50+
categoryDto,
51+
unitDto
52+
);
53+
}
5254

5355
}

0 commit comments

Comments
 (0)