1 | package edu.ucsb.cs156.dining.services; | |
2 | ||
3 | import edu.ucsb.cs156.dining.entities.UCSBAPIDiningCommons; | |
4 | import java.util.List; | |
5 | import lombok.extern.slf4j.Slf4j; | |
6 | import org.springframework.beans.factory.annotation.Value; | |
7 | import org.springframework.boot.web.client.RestTemplateBuilder; | |
8 | import org.springframework.http.HttpEntity; | |
9 | import org.springframework.http.HttpHeaders; | |
10 | import org.springframework.http.HttpMethod; | |
11 | import org.springframework.http.ResponseEntity; | |
12 | import org.springframework.stereotype.Service; | |
13 | import org.springframework.web.client.RestTemplate; | |
14 | ||
15 | /** Service class to interact with UCSB Dining Commons API */ | |
16 | @Service | |
17 | @Slf4j | |
18 | public class UCSBAPIDiningCommonsService { | |
19 | ||
20 | @Value("${app.ucsb.api.consumer_key}") | |
21 | private String apiKey; | |
22 | ||
23 | private final RestTemplate restTemplate; | |
24 | ||
25 | public UCSBAPIDiningCommonsService(RestTemplateBuilder restTemplateBuilder) { | |
26 | this.restTemplate = restTemplateBuilder.build(); | |
27 | } | |
28 | ||
29 | private static final String DINING_COMMONS_ENDPOINT = | |
30 | "https://api.ucsb.edu/dining/commons/v1/"; | |
31 | ||
32 | public List<UCSBAPIDiningCommons> getAllDiningCommons() throws Exception { | |
33 | HttpHeaders headers = new HttpHeaders(); | |
34 |
1
1. getAllDiningCommons : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("ucsb-api-key", this.apiKey); |
35 |
1
1. getAllDiningCommons : removed call to org/springframework/http/HttpHeaders::set → KILLED |
headers.set("accept", "application/json"); |
36 | ||
37 | HttpEntity<String> entity = new HttpEntity<>("body", headers); | |
38 | ||
39 | log.info("Fetching all dining commons from API"); | |
40 | ||
41 | ResponseEntity<UCSBAPIDiningCommons[]> response = restTemplate.exchange( | |
42 | DINING_COMMONS_ENDPOINT, HttpMethod.GET, entity, UCSBAPIDiningCommons[].class); | |
43 | ||
44 | UCSBAPIDiningCommons[] diningCommonsArray = response.getBody(); | |
45 |
1
1. getAllDiningCommons : negated conditional → KILLED |
if (diningCommonsArray == null) { |
46 | throw new Exception("Failed to fetch dining commons data from API"); | |
47 | } | |
48 | ||
49 |
1
1. getAllDiningCommons : replaced return value with Collections.emptyList for edu/ucsb/cs156/dining/services/UCSBAPIDiningCommonsService::getAllDiningCommons → KILLED |
return List.of(diningCommonsArray); |
50 | } | |
51 | } | |
Mutations | ||
34 |
1.1 |
|
35 |
1.1 |
|
45 |
1.1 |
|
49 |
1.1 |