dev add tarriff description
Test Workflow / test (push) Has been cancelled

This commit is contained in:
2026-05-15 15:29:07 +07:00
parent a4928395b9
commit c0818146bc
2 changed files with 16 additions and 21 deletions
@@ -107,7 +107,7 @@ public class TariffHandler implements RequestHandler {
Map.of("id", tariffRequest.getId())); Map.of("id", tariffRequest.getId()));
} }
TariffDTO tariffDTO = tariffService.updateTariff(tariffRequest.getId(), tariff); TariffDTO tariffDTO = tariffService.updateTariff(tariffRequest.getId(), tariff, tariffRequest);
TariffResponse tariffResponse = TariffResponse.builder() TariffResponse tariffResponse = TariffResponse.builder()
.tariffName(tariffDTO.getName()) .tariffName(tariffDTO.getName())
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import ru.soune.nocopy.dto.tarriff.TariffDTO; import ru.soune.nocopy.dto.tarriff.TariffDTO;
import ru.soune.nocopy.dto.tarriff.TariffRequest;
import ru.soune.nocopy.entity.tarif.Tariff; import ru.soune.nocopy.entity.tarif.Tariff;
import ru.soune.nocopy.entity.tarif.TariffTimeTerm; import ru.soune.nocopy.entity.tarif.TariffTimeTerm;
import ru.soune.nocopy.entity.tarif.TariffType; import ru.soune.nocopy.entity.tarif.TariffType;
@@ -81,18 +82,10 @@ public class TariffService {
} }
@Transactional @Transactional
public TariffDTO createTariff(TariffDTO tariffDTO) { public TariffDTO updateTariff(Long id, TariffDTO tariffDTO, TariffRequest tariffRequest) {
Tariff tariff = new Tariff();
updateTariffFromDTO(tariff, tariffDTO);
return convertToDTO(tariffRepository.save(tariff));
}
@Transactional
public TariffDTO updateTariff(Long id, TariffDTO tariffDTO) {
Tariff tariff = tariffRepository.findById(id) Tariff tariff = tariffRepository.findById(id)
.orElseThrow(() -> new TariffNotFoundException("Tariff not found")); .orElseThrow(() -> new TariffNotFoundException("Tariff not found"));
updateTariffFromDTO(tariff, tariffDTO); updateTariffFromDTO(tariff, tariffDTO, tariffRequest);
return convertToDTO(tariffRepository.save(tariff)); return convertToDTO(tariffRepository.save(tariff));
} }
@@ -119,15 +112,17 @@ public class TariffService {
); );
} }
private void updateTariffFromDTO(Tariff tariff, TariffDTO dto) { private void updateTariffFromDTO(Tariff tariff, TariffDTO dto, TariffRequest tariffRequest) {
tariff.setType(dto.getType()); tariff.setType(tariffRequest.getType() == null ? dto.getType(): tariffRequest.getType());
tariff.setName(dto.getName()); tariff.setName(tariffRequest.getName() == null ? dto.getName(): tariffRequest.getName());
tariff.setPrice(dto.getPrice()); tariff.setPrice(tariffRequest.getPrice() == 0 ? dto.getPrice(): tariffRequest.getPrice());
tariff.setTokens(dto.getTokens()); tariff.setTokens(tariffRequest.getTokens() == 0 ? dto.getTokens(): tariffRequest.getTokens());
tariff.setMaxFilesCount(dto.getMaxFilesCount()); tariff.setMaxFilesCount(tariffRequest.getMaxFilesCount() == 0 ? dto.getMaxFilesCount():
tariff.setDiskSize(dto.getDiskSize()); tariffRequest.getMaxFilesCount());
tariff.setMaxUsers(dto.getMaxUsers()); tariff.setDiskSize(tariffRequest.getDiskSize() == 0 ? dto.getDiskSize(): tariffRequest.getDiskSize());
tariff.setDescription(dto.getDescription()); tariff.setMaxUsers(tariffRequest.getMaxUsers() == 0 ? dto.getMaxUsers(): tariffRequest.getMaxUsers());
tariff.setTariffTerm(TariffTimeTerm.valueOf(dto.getTariffTerm().toUpperCase())); tariff.setDescription(tariffRequest.getDescription() == null ? dto.getDescription(): tariffRequest.getDescription());
tariff.setTariffTerm(tariffRequest.getTariffTerm() == null ? TariffTimeTerm.valueOf(dto.getTariffTerm().toUpperCase()):
TariffTimeTerm.valueOf(tariffRequest.getTariffTerm()));
} }
} }