2525public class AddressServiceImpl implements AddressService {
2626
2727 @ Autowired
28- private AddressRepository repository ;
28+ private AddressRepository addressRepository ;
2929 @ Autowired
3030 DependentRepository dependentRepository ;
3131 @ Autowired
@@ -34,44 +34,45 @@ public class AddressServiceImpl implements AddressService {
3434 static final String RESPONSEENDERECONAOENCONTRADO = "Endereço não encontrado" ;
3535 @ Override
3636 @ Transactional
37- public void saveAddress (AddressDTO addressDTO ) {
38- Address address = new Address ();
39- address = mapTo (addressDTO , address );
40- repository .save (address );
37+ public AddressDTO saveAddress (AddressDTO addressDTO ) {
38+ Address addressEntity = new Address ();
39+ addressEntity = mapTo (addressDTO , addressEntity );
40+ return new AddressDTO ( addressRepository .save (addressEntity ) );
4141 }
4242
43+
4344 @ Override
4445 @ Transactional (readOnly = true )
4546 public Page <AddressDTO > search (String text , Pageable pageable ) {
4647 Page <Address > page ;
4748 if (Objects .equals (text , "" )) {
48- page = repository .findAll (pageable );
49+ page = addressRepository .findAll (pageable );
4950 } else {
50- page = repository .findByStreetIgnoreCaseContainingOrDistrictIgnoreCaseContainingOrCityIgnoreCaseContainingOrStateIgnoreCaseContaining (text , text , text , text , pageable );
51+ page = addressRepository .findByStreetIgnoreCaseContainingOrDistrictIgnoreCaseContainingOrCityIgnoreCaseContainingOrStateIgnoreCaseContaining (text , text , text , text , pageable );
5152 }
5253 return page .map (AddressDTO ::new );
5354 }
5455
5556 @ Override
5657 @ Transactional
5758 public List <DependentDTO > findDependentByAddressId (Long id ) {
58- Address address = repository .getReferenceById (id );
59+ Address address = addressRepository .getReferenceById (id );
5960 List <Dependent > addressDependent = dependentRepository .findByAddress_Id (address .getId ());
6061 return addressDependent .stream ().map (DependentDTO ::new ).toList ();
6162 }
6263
6364 @ Override
6465 @ Transactional
6566 public List <ApplianceDTO > findApplianceByAddressId (Long id ) {
66- Address address = repository .getReferenceById (id );
67+ Address address = addressRepository .getReferenceById (id );
6768 List <Appliance > addressAppliance =applianceRepository .findByAddress_Id (address .getId ());
6869 return addressAppliance .stream ().map (ApplianceDTO ::new ).toList ();
6970 }
7071
7172 @ Override
7273 @ Transactional (readOnly = true )
7374 public AddressDTO findById (Long id ) {
74- Address address = repository .findById (id ).orElseThrow (
75+ Address address = addressRepository .findById (id ).orElseThrow (
7576 () -> new ResourceNotFoundException (RESPONSEENDERECONAOENCONTRADO ));
7677
7778 return new AddressDTO (address );
@@ -80,23 +81,23 @@ public AddressDTO findById(Long id) {
8081 @ Override
8182 @ Transactional (propagation = Propagation .SUPPORTS )
8283 public void delete (Long id ) {
83- if (!repository .existsById (id )) {
84+ if (!addressRepository .existsById (id )) {
8485 throw new ResourceNotFoundException (RESPONSEENDERECONAOENCONTRADO );
8586 }
8687
87- repository .deleteById (id );
88+ addressRepository .deleteById (id );
8889 }
8990
9091 @ Override
9192 @ Transactional
9293 public void update (Long id , AddressDTO addressDTO ) {
93- if (!repository .existsById (id )) {
94+ if (!addressRepository .existsById (id )) {
9495 throw new ResourceNotFoundException (RESPONSEENDERECONAOENCONTRADO );
9596 }
9697
97- Address address = repository .getReferenceById (id );
98+ Address address = addressRepository .getReferenceById (id );
9899 address = mapTo (addressDTO , address );
99- repository .save (address );
100+ addressRepository .save (address );
100101 }
101102
102103 public Address mapTo (AddressDTO dto , Address entity ) {
0 commit comments