/
Apathy21
/
company
Обзор
Документация
Войти
/
Apathy21
/
company
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
MainService/src/main/java/org/example/service/BranchOfficeService.java
41 строка
1 KB
alexeev509
Skeletop company app realization
13 сен 2024, 19:21
13 сен 2024, 19:21
2a02e11
Код
Авторство
О чём код?
package org.example.service; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.inject.Named; import jakarta.transaction.Transactional; import org.example.Entity.Address; import org.example.Entity.BranchOffice; import org.example.dao.AddressDaoImpl; import org.example.dao.api.BranchOfficeDao; import java.util.List; import java.util.Optional; @Named("branchOfficeService") @ApplicationScoped public class BranchOfficeService { @Inject private BranchOfficeDao branchDao; @Inject private AddressDaoImpl daoAddress; public List<BranchOffice> getBranchOfficesByCompanyId(long id) { return branchDao.findBranchOfficesByCompanyId(id); } @Transactional public void save(BranchOffice createdBranchOffice) { // #logic-explanation: we must check: have we such Address in db or not: Optional<Address> addressByLocation = daoAddress.getAddressByLocation(createdBranchOffice.getAddress()); // #logic-explanation: if we have this address -> we must use actual and don't create new; addressByLocation.ifPresent(createdBranchOffice::setAddress); branchDao.save(createdBranchOffice); } @Transactional public void delete(BranchOffice branchOffice) { branchDao.delete(branchOffice); } }