Skip to content
Open

MVP #22

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ <h4>update</h4>
<h4>delete</h4>
<pre class="methodSignature">@Transactional
public&nbsp;void&nbsp;delete&#8203;(long&nbsp;id)
throws javax.persistence.EntityNotFoundException</pre>
throws javax.persistence.ResourceNotFoundException</pre>
<div class="block"><span class="descfrmTypeLabel">Description copied from interface:&nbsp;<code><a href="ZooService.html#delete(long)">ZooService</a></code></span></div>
<div class="block">Deletes the course record, it student course combinations, and its telephone items from the database based off of the provided primary key</div>
<dl>
Expand All @@ -385,7 +385,7 @@ <h4>delete</h4>
<dt><span class="paramLabel">Parameters:</span></dt>
<dd><code>id</code> - id The primary key (long) of the course you seek.</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>javax.persistence.EntityNotFoundException</code></dd>
<dd><code>javax.persistence.ResourceNotFoundException</code></dd>
</dl>
</li>
</ul>
Expand Down Expand Up @@ -438,7 +438,7 @@ <h4>saveZooAnimalCombo</h4>
<li class="blockList">
<h4>findZooByLikeName</h4>
<pre class="methodSignature">public&nbsp;java.util.ArrayList&lt;<a href="../models/Zoo.html" title="class in com.lambdaschool.schools.models">Zoo</a>&gt;&nbsp;findZooByLikeName&#8203;(java.lang.String&nbsp;name)
throws javax.persistence.EntityNotFoundException</pre>
throws javax.persistence.ResourceNotFoundException</pre>
<div class="block"><span class="descfrmTypeLabel">Description copied from interface:&nbsp;<code><a href="ZooService.html#findZooByLikeName(java.lang.String)">ZooService</a></code></span></div>
<div class="block">A list of all zoos whose name contains the given substring
A Stretch Goal</div>
Expand All @@ -450,7 +450,7 @@ <h4>findZooByLikeName</h4>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>List of zoos whose name contains the given substring</dd>
<dt><span class="throwsLabel">Throws:</span></dt>
<dd><code>javax.persistence.EntityNotFoundException</code></dd>
<dd><code>javax.persistence.ResourceNotFoundException</code></dd>
</dl>
</li>
</ul>
Expand Down
23 changes: 22 additions & 1 deletion schools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<description>Demo project for Spring Boot</description>

<properties>
<java.version>11</java.version>
<java.version>14</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -43,6 +43,27 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Swagger Dependencies Start -->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.9.2</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.9.2</version>
</dependency>
<!-- Swagger Dependencies End -->
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
package com.lambdaschool.schools;

import com.lambdaschool.schools.models.slip;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

/**
* Main class to start the application.
Expand All @@ -17,10 +24,15 @@ public class SchoolsApplication
*
* @param args Not used in this application.
*/
public static void main(String[] args)
{
public static void main(String[] args){

try{
System.out.println(System.getenv("PATH").toUpperCase());
} catch (Exception e){
System.out.println("No Such Environment Variable");
} finally{
SpringApplication.run(SchoolsApplication.class,
args);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public Server h2TcpServer() throws
SQLException
{
return Server.createTcpServer("-tcp",
"-tcpAllowOthers",
"-tcpPort",
h2TcpPort)
.start();
"-tcpAllowOthers",
"-tcpPort",
h2TcpPort)
.start();
}

/**
Expand All @@ -64,9 +64,9 @@ public Server h2WebServer() throws
SQLException
{
return Server.createWebServer("-web",
"-webAllowOthers",
"-webPort",
h2WebPort)
.start();
"-webAllowOthers",
"-webPort",
h2WebPort)
.start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.lambdaschool.schools.config;

import org.springframework.context.annotation.*;
import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration;
import springfox.documentation.builders.*;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
* Configures the default Swagger Documentation
*/
@Configuration
@EnableSwagger2
@Import(BeanValidatorPluginsConfiguration.class)
public class Swagger2Config
{
/**
* Configures what to document using Swagger
*
* @return A Docket which is the primary interface for Swagger configuration
*/
@Bean
public Docket api()
{
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors
.basePackage("com.lambdaschool.schools"))
.paths(PathSelectors.regex("/.*"))
.build()
.apiInfo(apiEndPointsInfo());
}

/**
* Configures some information related to the Application for Swagger
*
* @return ApiInfo a Swagger object containing identification information for this application
*/
private ApiInfo apiEndPointsInfo()
{
return new ApiInfoBuilder().title("School Example")
.description("User Model Example")
.contact(new Contact("John Mitchell",
"http://www.lambdaschool.com",
"john@lambdaschool.com"))
.license("MIT")
.licenseUrl("https://github.com/LambdaSchool/java-school/blob/master/LICENSE")
.version("1.0.0")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
package com.lambdaschool.schools.controllers;

import com.lambdaschool.schools.models.*;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.Collections;

@RestController
@RequestMapping("/otherapis") // optional
public class OtherApisController
{
/*
* Creates the object that is needed to do a client side Rest API call.
* We are the client getting data from a remote API.
* We can share this template among endpoints
*/
private RestTemplate restTemplate = new RestTemplate();

@GetMapping(value = "/isspositions")
public ResponseEntity<?> listIssPositions()
{
// we need to tell our RestTemplate what format to expect
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// a couple of common formats
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
// or we can accept all formats! Easiest but least secure
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
restTemplate.getMessageConverters().add(converter);

// create the url to access the API
String requestURL = "http://api.open-notify.org/iss-now.json";
// create the responseType expected. Notice the IssPositionReturnData is the data type we are expecting back from the API!
ParameterizedTypeReference<IssPositionReturnData> responseType = new ParameterizedTypeReference<>()
{
};

// create the response entity. do the get and get back information
ResponseEntity<IssPositionReturnData> responseEntity = restTemplate.exchange(requestURL,
HttpMethod.GET,
null,
responseType);
// we want to return the Iss_position data. From the data that gets returned in the body,
// get the Iss_position data only and return it.
// putting the data into its own object first, prevents the data from being reported to client inside of
// an embedded. So the response will look more like our clients are use to!
IssPosition ourIssPosition = responseEntity.getBody().getIss_position();
return new ResponseEntity<>(ourIssPosition,
HttpStatus.OK);
}

@GetMapping(value = "/shakespeare/{englishText}")
public ResponseEntity<?> getTranslation(
@PathVariable
String englishText)
{
// we need to tell our RestTemplate what format to expect
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// a couple of common formats
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
// or we can accept all formats! Easiest but least secure
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
restTemplate.getMessageConverters()
.add(converter);

// create the url to access the API including adding the path variable
String requestURL = "https://api.funtranslations.com/translate/shakespeare.json?text=" + englishText;
// create the responseType expected. Notice the Translation is the data type we are expecting back from the API!
ParameterizedTypeReference<Translation> responseType = new ParameterizedTypeReference<>()
{
};

// create the response entity. do the get and get back information
ResponseEntity<Translation> responseEntity = restTemplate.exchange(requestURL,
HttpMethod.GET,
null,
responseType);
// we want to return the contents of the translation data. From the data that gets returned in the body,
// get the contents data only and return it.
// putting the data into its own object first, prevents the data from being reported to client inside of
// an embedded. So the response will look more like our clients are use to!
TranslationContents ourTranslation = responseEntity.getBody()
.getContents();
return new ResponseEntity<>(ourTranslation,
HttpStatus.OK);
}

@GetMapping(value = "/advice")
public ResponseEntity<?> listSlipAdvice()
{
// we need to tell our RestTemplate what format to expect
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// a couple of common formats
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
// or we can accept all formats! Easiest but least secure
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
restTemplate.getMessageConverters().add(converter);

// create the url to access the API
String requestURL = "https://api.adviceslip.com/advice";
// create the responseType expected. Notice the IssPositionReturnData is the data type we are expecting back from the API!
ParameterizedTypeReference<SlipReturnData> responseType = new ParameterizedTypeReference<>()
{
};

// create the response entity. do the get and get back information
ResponseEntity<SlipReturnData> responseEntity = restTemplate.exchange(requestURL,
HttpMethod.GET,
null,
responseType);
// we want to return the Iss_position data. From the data that gets returned in the body,
// get the Iss_position data only and return it.
// putting the data into its own object first, prevents the data from being reported to client inside of
// an embedded. So the response will look more like our clients are use to!
slip ourSlipPosition = responseEntity.getBody().getSlip_position();
return new ResponseEntity<>(ourSlipPosition,
HttpStatus.OK);
}

@GetMapping(value = "/advice/{id}")
public ResponseEntity<?> getAdviceTranslation(
@PathVariable
int id)
{
// we need to tell our RestTemplate what format to expect
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
// a couple of common formats
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
// converter.setSupportedMediaTypes(Collections.singletonList(MediaType.APPLICATION_JSON));
// or we can accept all formats! Easiest but least secure
converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));
restTemplate.getMessageConverters()
.add(converter);

// create the url to access the API including adding the path variable
String requestURL = "https://api.adviceslip.com/advice?text=" + id;
// create the responseType expected. Notice the Translation is the data type we are expecting back from the API!
ParameterizedTypeReference<Translation> responseType = new ParameterizedTypeReference<>()
{
};

// create the response entity. do the get and get back information
ResponseEntity<Translation> responseEntity = restTemplate.exchange(requestURL,
HttpMethod.GET,
null,
responseType);
// we want to return the contents of the translation data. From the data that gets returned in the body,
// get the contents data only and return it.
// putting the data into its own object first, prevents the data from being reported to client inside of
// an embedded. So the response will look more like our clients are use to!
TranslationContents ourTranslation = responseEntity.getBody()
.getContents();
return new ResponseEntity<>(ourTranslation,
HttpStatus.OK);
}
}
Loading