DEGTEVUWU/java-project-72

View on GitHub
app/src/main/java/hexlet/code/utils/UrlService.java

Summary

Maintainability
A
0 mins
Test Coverage
F
40%
package hexlet.code.utils;

import hexlet.code.model.Url;
import hexlet.code.repository.CheckRepository;

import java.sql.Timestamp;
import java.util.Optional;

public class UrlService {
    public static final Optional<Integer> getStatusCode(Url url)  {
        if (CheckRepository.findExisting(url.getId())) {
            var list = CheckRepository.find(Math.toIntExact(url.getId()));
            return Optional.of(list.get(list.size() - 1).getStatusCode());
        }
        return Optional.empty();
    }
    public static final Optional<Timestamp> getCheckCreatedAt(Url url) {
        if (CheckRepository.findExisting(url.getId())) {
            var list = CheckRepository.find(Math.toIntExact(url.getId()));
            if (!list.isEmpty()) {
                return Optional.of(list.get(list.size() - 1).getCreatedAt());
            }
        }
        return Optional.empty();
    }
}