<commit_before>package au.gov.dto.dibp.appointments.availabletimes;

import au.gov.dto.dibp.appointments.client.Client;
import au.gov.dto.dibp.appointments.qflowintegration.ApiCallsSenderService;
import au.gov.dto.dibp.appointments.util.ResponseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
class AvailableTimesService {

    private static final String REQUEST_TEMPLATE_PATH = "GetDynamicSuggestedSlots2.mustache";
    private static final String START_TIME = "//GetDynamicSuggestedSlots2Response/GetDynamicSuggestedSlots2Result/SuggestedSlots/DynamicCalendarSuggestedSlotItem/StartTime";

    private final ApiCallsSenderService senderService;
    private final String serviceAddress;

    @Autowired
    public AvailableTimesService(ApiCallsSenderService senderService, @Value("${SERVICE.ADDRESS.CALENDAR}") String serviceAddress) {
        this.senderService = senderService;
        this.serviceAddress = serviceAddress;
    }

    public List<String> getAvailableTimes(Client client, String calendarId) {
        Map<String, String> data = new HashMap<>();
        data.put("calendarId", calendarId);
        data.put("appointmentTypeId", client.getAppointmentTypeId());
        data.put("currentUserId", "3"); // FIXME(Marz)

        ResponseWrapper response = senderService.sendRequest(REQUEST_TEMPLATE_PATH, data, serviceAddress);
        return parseAvailableTimesResponse(response);
    }

    private List<String> parseAvailableTimesResponse(ResponseWrapper response) {
        NodeList nodes = response.getNodeListAttribute(START_TIME);
        List<String> availableTimes = new ArrayList<>();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            availableTimes.add(convertMinutesToHour(node.getTextContent()));
        }
        return availableTimes;
    }

    private String convertMinutesToHour(String minutesString){
        int timeInMinutes = Integer.parseInt(minutesString);
        int minutes = timeInMinutes % 60;
        int hours = (timeInMinutes-minutes) / 60;
        return String.format("%1$d:%2$02d", hours, minutes);
    }

}<commit_msg>Format available times as HH:mm<commit_after>package au.gov.dto.dibp.appointments.availabletimes;

import au.gov.dto.dibp.appointments.client.Client;
import au.gov.dto.dibp.appointments.qflowintegration.ApiCallsSenderService;
import au.gov.dto.dibp.appointments.util.ResponseWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
class AvailableTimesService {

    private static final String REQUEST_TEMPLATE_PATH = "GetDynamicSuggestedSlots2.mustache";
    private static final String START_TIME = "//GetDynamicSuggestedSlots2Response/GetDynamicSuggestedSlots2Result/SuggestedSlots/DynamicCalendarSuggestedSlotItem/StartTime";

    private final ApiCallsSenderService senderService;
    private final String serviceAddress;

    @Autowired
    public AvailableTimesService(ApiCallsSenderService senderService, @Value("${SERVICE.ADDRESS.CALENDAR}") String serviceAddress) {
        this.senderService = senderService;
        this.serviceAddress = serviceAddress;
    }

    public List<String> getAvailableTimes(Client client, String calendarId) {
        Map<String, String> data = new HashMap<>();
        data.put("calendarId", calendarId);
        data.put("appointmentTypeId", client.getAppointmentTypeId());
        data.put("currentUserId", "3"); // FIXME(Marz)

        ResponseWrapper response = senderService.sendRequest(REQUEST_TEMPLATE_PATH, data, serviceAddress);
        return parseAvailableTimesResponse(response);
    }

    private List<String> parseAvailableTimesResponse(ResponseWrapper response) {
        NodeList nodes = response.getNodeListAttribute(START_TIME);
        List<String> availableTimes = new ArrayList<>();
        for (int i = 0; i < nodes.getLength(); i++) {
            Node node = nodes.item(i);
            availableTimes.add(convertMinutesToHour(node.getTextContent()));
        }
        return availableTimes;
    }

    private String convertMinutesToHour(String minutesString){
        int timeInMinutes = Integer.parseInt(minutesString);
        int minutes = timeInMinutes % 60;
        int hours = (timeInMinutes-minutes) / 60;
        return String.format("%1$02d:%2$02d", hours, minutes);
    }

}
{'fraction_non_alphanumeric': 0.09987644151565074, 'fraction_numerical': 0.006589785831960461, 'mean_word_length': 4.308196721311475, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2565692', 'n_tokens_mistral': 1382, 'n_tokens_neox': 1356, 'n_words': 260}