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

This commit is contained in:
2026-05-15 16:52:55 +07:00
parent df38da6d5f
commit 57a39d0cb0
4 changed files with 17 additions and 1 deletions
@@ -44,6 +44,7 @@ public enum MessageCode {
FILE_IS_NOT_PROTECTED(0, "File is not protected"), FILE_IS_NOT_PROTECTED(0, "File is not protected"),
TARIFF_IS_ADD(0, "Tariff is added"), TARIFF_IS_ADD(0, "Tariff is added"),
TARIFF_IS_DELETED(0, "Tariff is deleted"), TARIFF_IS_DELETED(0, "Tariff is deleted"),
TARIFF_IS_NOT_DELETED(0, "Tariff is not deleted,use some users"),
TARIFF_IS_UPDATED(0, "Tariff is updated"), TARIFF_IS_UPDATED(0, "Tariff is updated"),
TARIFF_IS_NOT_FOUND(0, "Tariff is not found"), TARIFF_IS_NOT_FOUND(0, "Tariff is not found"),
VALIDATION_ERROR(2, "Validation error"), VALIDATION_ERROR(2, "Validation error"),
@@ -91,6 +91,12 @@ public class TariffHandler implements RequestHandler {
.tariffType(tariff.getType()) .tariffType(tariff.getType())
.build(); .build();
if (tariffService.existTariffInfoByTariffId(tariffRequest.getId())) {
return new BaseResponse(request.getMsgId(), MessageCode.TARIFF_IS_NOT_DELETED.getCode(),
MessageCode.TARIFF_IS_NOT_DELETED.getDescription(),
tariffResponse);
}
tariffService.deleteTariff(tariffRequest.getId()); tariffService.deleteTariff(tariffRequest.getId());
return new BaseResponse(request.getMsgId(), MessageCode.TARIFF_IS_DELETED.getCode(), return new BaseResponse(request.getMsgId(), MessageCode.TARIFF_IS_DELETED.getCode(),
@@ -15,6 +15,8 @@ public interface TariffInfoRepository extends JpaRepository<TariffInfo, String>
@Query("SELECT t FROM TariffInfo t WHERE t.autoRenewal = true AND t.endTariff <= :date") @Query("SELECT t FROM TariffInfo t WHERE t.autoRenewal = true AND t.endTariff <= :date")
List<TariffInfo> findForAutoRenewal(@Param("date") LocalDateTime date); List<TariffInfo> findForAutoRenewal(@Param("date") LocalDateTime date);
Boolean existsByTariffId(Long tariffId);
@Query(""" @Query("""
SELECT COUNT(u.Id) SELECT COUNT(u.Id)
FROM User u FROM User u
@@ -10,6 +10,7 @@ import ru.soune.nocopy.entity.tarif.TariffTimeTerm;
import ru.soune.nocopy.entity.tarif.TariffType; import ru.soune.nocopy.entity.tarif.TariffType;
import ru.soune.nocopy.entity.user.User; import ru.soune.nocopy.entity.user.User;
import ru.soune.nocopy.exception.TariffNotFoundException; import ru.soune.nocopy.exception.TariffNotFoundException;
import ru.soune.nocopy.repository.TariffInfoRepository;
import ru.soune.nocopy.repository.TariffRepository; import ru.soune.nocopy.repository.TariffRepository;
import java.util.List; import java.util.List;
@@ -21,6 +22,8 @@ public class TariffService {
private final TariffRepository tariffRepository; private final TariffRepository tariffRepository;
private final TariffInfoRepository tariffInfoRepository;
public void addTariff(String tariffName, double price, String type, int tokens, long diskSize, long maxUsers, public void addTariff(String tariffName, double price, String type, int tokens, long diskSize, long maxUsers,
int maxFilesCount, String tariffTerm, String description) { int maxFilesCount, String tariffTerm, String description) {
Tariff tariff = new Tariff(); Tariff tariff = new Tariff();
@@ -46,6 +49,10 @@ public class TariffService {
.collect(Collectors.toList()); .collect(Collectors.toList());
} }
public Boolean existTariffInfoByTariffId(Long id) {
return tariffInfoRepository.existsByTariffId(id);
}
public List<TariffDTO> getTariffByAccountTypeAndTariffTerm(User user, TariffTimeTerm tariffTerm) { public List<TariffDTO> getTariffByAccountTypeAndTariffTerm(User user, TariffTimeTerm tariffTerm) {
String typeAccount = user.canManageCompanySettings() ? "b2b": "b2c"; String typeAccount = user.canManageCompanySettings() ? "b2b": "b2c";
@@ -120,7 +127,7 @@ public class TariffService {
if (tariffRequest.getName() != null) { if (tariffRequest.getName() != null) {
tariff.setName(tariffRequest.getName()); tariff.setName(tariffRequest.getName());
} }
if (tariffRequest.getPrice() != null) { // null = не обновляем if (tariffRequest.getPrice() != null) {
tariff.setPrice(tariffRequest.getPrice()); tariff.setPrice(tariffRequest.getPrice());
} }
if (tariffRequest.getTokens() != null) { if (tariffRequest.getTokens() != null) {