Skip to content

Commit

Permalink
✨ [FEAT] 간병인 총 시간 조회 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
20210815 committed Dec 7, 2024
1 parent aeda77b commit 3ecfc46
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.carely.backend.dto.certificate.volunteerDTO;
import com.carely.backend.exception.*;
import com.carely.backend.repository.UserRepository;
import com.carely.backend.repository.VolunteerRepository;
import jakarta.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -47,13 +48,15 @@ public class CertificateService {
private final UserRepository userRepository;
protected final RawTransactionManager txManager;
protected final StaticGasProvider gasProvider;
private final VolunteerRepository volunteerRepository;

private final GanacheProperties ganacheProperties;
private String ganacheUrl = "http://3.34.24.211:7545";

@Autowired
public CertificateService(UserRepository userRepository, GanacheProperties ganacheProperties) {
public CertificateService(UserRepository userRepository, VolunteerRepository volunteerRepository, GanacheProperties ganacheProperties) {
this.userRepository = userRepository;
this.volunteerRepository = volunteerRepository;
this.ganacheProperties = ganacheProperties;
String privateKey = ganacheProperties.getPrivateKey().trim(); // 공백 제거
String contractKey = ganacheProperties.getContractKey().trim(); // 공백 제거
Expand Down Expand Up @@ -336,6 +339,18 @@ public CertificateDTO getCertificateById(String certificateId) throws Exception
public int calculateTotalVolunteerHours(String userId) {
User user = userRepository.findById(Long.valueOf(userId))
.orElseThrow(() -> new UsernameNotFoundException("사용자를 찾을 수 없습니다."));

if (user.getUserType().equals(UserType.CAREGIVER)) {
int result = 0;
List<Volunteer> list = volunteerRepository.findByCaregiver(user);
for(Volunteer volunteer : list) {
if (volunteer.getIsApproved()) {
result += volunteer.getDurationHours();
}
}
return result;
}

// Solidity 함수 호출을 위한 Function 객체 생성
Function function = new Function(
"calculateTotalVolunteerHours",
Expand Down

0 comments on commit 3ecfc46

Please sign in to comment.