1
1
package com .omatheusmesmo .shoppmate .item .mapper ;
2
2
3
+ import com .omatheusmesmo .shoppmate .category .dto .CategoryResponseDTO ;
3
4
import com .omatheusmesmo .shoppmate .category .entity .Category ;
4
5
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 ;
6
8
import com .omatheusmesmo .shoppmate .item .entity .Item ;
9
+ import com .omatheusmesmo .shoppmate .unit .dto .UnitResponseDTO ;
7
10
import com .omatheusmesmo .shoppmate .unit .entity .Unit ;
8
11
import com .omatheusmesmo .shoppmate .unit .repository .UnitRepository ;
9
12
import org .springframework .beans .factory .annotation .Autowired ;
@@ -21,7 +24,7 @@ public class ItemMapper {
21
24
private UnitRepository unitRepository ;
22
25
23
26
24
- public Item toEntity (ItemDTO dto ) {
27
+ public Item toEntity (ItemDTORequest dto ) {
25
28
Category category = categoryRepository .findById (dto .idCategory ())
26
29
.orElseThrow (() -> new NoSuchElementException ("Category not found with id: " + dto .idCategory ()));
27
30
@@ -35,19 +38,18 @@ public Item toEntity(ItemDTO dto) {
35
38
return item ;
36
39
}
37
40
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
+ }
52
54
53
55
}
0 commit comments