@@ -0,0 +1,96 @@
|
||||
package ru.soune.nocopy.service.complaint;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.soune.nocopy.entity.complaint.LawCase;
|
||||
import ru.soune.nocopy.entity.complaint.LawCasePriority;
|
||||
import ru.soune.nocopy.entity.complaint.LawCaseType;
|
||||
import ru.soune.nocopy.repository.LawCaseRepository;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class LawCaseService {
|
||||
|
||||
private final LawCaseRepository lawCaseRepository;
|
||||
|
||||
public LawCase addLawCase(BigDecimal amount, String description, String name,
|
||||
LawCasePriority priority) {
|
||||
LawCase lawCase = new LawCase();
|
||||
|
||||
BigDecimal damage = amount == null ? BigDecimal.ZERO : amount;
|
||||
|
||||
lawCase.setAmount(damage);
|
||||
lawCase.setName(name);
|
||||
lawCase.setDescription(description);
|
||||
lawCase.setPriority(priority);
|
||||
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public LawCase getById(Long id) {
|
||||
return lawCaseRepository.findById(id).orElse(null);
|
||||
}
|
||||
|
||||
public LawCase changeStatus(Long id, LawCaseType type) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
lawCase.setType(type);
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public LawCase changePriority(Long id, LawCasePriority priority) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
lawCase.setPriority(priority);
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public LawCase changeDamage(Long id, BigDecimal damage) {
|
||||
LawCase lawCase = lawCaseRepository.findById(id).orElse(null);
|
||||
if (lawCase == null) {
|
||||
return null;
|
||||
}
|
||||
lawCase.setAmount(damage);
|
||||
return lawCaseRepository.save(lawCase);
|
||||
}
|
||||
|
||||
public List<LawCase> getAllUserLawCases(Long userId, int pageSize, int pageNumber, String propertySort,
|
||||
String ascDesc) {
|
||||
Sort.Direction direction = ascDesc.equalsIgnoreCase("desc") ? Sort.Direction.DESC:
|
||||
Sort.Direction.ASC;
|
||||
Sort sort = Sort.by(direction, propertySort);
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
||||
|
||||
return lawCaseRepository.getUserLawCases(userId, pageable);
|
||||
}
|
||||
|
||||
public Page<LawCase> getAllUserLawCases(Long userId, int pageSize, int pageNumber,
|
||||
LawCaseType lawCaseType, String lawyer,
|
||||
LawCasePriority lawCasePriority,
|
||||
String propertySort, String ascDesc) {
|
||||
Sort.Direction direction = ascDesc.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC;
|
||||
Sort sort = Sort.by(direction, propertySort);
|
||||
Pageable pageable = PageRequest.of(pageNumber, pageSize, sort);
|
||||
|
||||
return lawCaseRepository.getUserLawCases(userId, lawCaseType, lawyer, lawCasePriority, pageable);
|
||||
}
|
||||
|
||||
public void deleteById(Long id) {
|
||||
lawCaseRepository.deleteById(id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user