Skip to content
Open
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
18 changes: 18 additions & 0 deletions schools/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<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>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
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.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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 @@ -19,6 +28,28 @@ public class SchoolsApplication
*/
public static void main(String[] args)
{

RestTemplate restTemplate = new RestTemplate();

MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();

converter.setSupportedMediaTypes(Collections.singletonList(MediaType.ALL));

restTemplate.getMessageConverters().add(converter);

String requestUrl = "https://api.adviceslip.com/advice";

ParameterizedTypeReference<slip> responseType = new ParameterizedTypeReference<>() {
};

ResponseEntity<slip> responseEntity = restTemplate.exchange(requestUrl, HttpMethod.GET,null,responseType);


slip ourSlip = responseEntity.getBody();
System.out.println(ourSlip);



SpringApplication.run(SchoolsApplication.class,
args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.lambdaschool.schools.config;

import org.springframework.context.annotation.Bean;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

public class Swagger2Config {

/*Configures what to document using Swagger
* @Return A docket whcih 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 Model Example")
.description("School Model Example")
.contact(new Contact("George Hatzigeorgio",
"http://www.lambdaschool.com",
"georgehatzigeorgio@gmail.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,34 @@
package com.lambdaschool.schools.exceptions;

import com.lambdaschool.schools.services.HelperFunctions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.LinkedHashMap;
import java.util.Map;

@Component
public class CustomErrorDetails extends DefaultErrorAttributes {

@Autowired
private HelperFunctions helperFunctions;


@Override
public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace){
Map<String,Object> errorAttributes = super.getErrorAttributes(webRequest,includeStackTrace);

Map<String, Object> errorDetails = new LinkedHashMap<>();
errorDetails.put("title",errorAttributes.get("error"));
errorDetails.put("status",errorAttributes.get("status"));
errorDetails.put("detail",errorAttributes.get("message"));
errorDetails.put("timestamp",errorAttributes.get("timestamp"));
errorDetails.put("developerMessage","path:" + errorAttributes.get("path"));

errorDetails.put("errors", helperFunctions.getValidationErrors(this.getError(webRequest)));

return errorDetails;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.lambdaschool.schools.exceptions;

public class ResourceNotFoundException extends RuntimeException{
public ResourceNotFoundException(String message){super("Error from a Lambda School Application"+ message);}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lambdaschool.schools.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import java.util.HashSet;
Expand All @@ -25,7 +26,11 @@ public class Course
/**
* Name (String) of this Course. Cannot be null and must be unique
*/
@Column(nullable = true,
@Length.List({
@Length(min = 2, message = "The field must be at least 2 characters"),
@Length(max = 30, message = "The field must be less than 30 characters")
})
@Column(nullable = false,
unique = true)
private String coursename;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.lambdaschool.schools.models;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ErrorDetail {

private String title;

private int status;

private String detail;

private Date timestamp;

private String developerMessage;

private List<ValidationError> errors = new ArrayList<>();

public ErrorDetail() {
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public int getStatus() {
return status;
}

public void setStatus(int status) {
this.status = status;
}

public String getDetail() {
return detail;
}

public void setDetail(String detail) {
this.detail = detail;
}

public Date getTimestamp() {
return timestamp;
}

public void setTimestamp(Date timestamp) {
this.timestamp = timestamp;
}

public String getDeveloperMessage() {
return developerMessage;
}

public void setDeveloperMessage(String developerMessage) {
this.developerMessage = developerMessage;
}

public List<ValidationError> getErrors() {
return errors;
}

public void setErrors(List<ValidationError> errors) {
this.errors = errors;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lambdaschool.schools.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import java.util.ArrayList;
Expand All @@ -24,6 +25,10 @@ public class Instructor
/**
* The Instructor's name (String)
*/
@Length.List({
@Length(min = 2, message = "The field must be at least 2 characters"),
@Length(max = 30, message = "The field must be less than 30 characters")
})
@Column(nullable = false)
private String name;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lambdaschool.schools.models;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.hibernate.validator.constraints.Length;

import javax.persistence.*;
import java.util.HashSet;
Expand All @@ -24,6 +25,10 @@ public class Student
/**
* The name student (String)
*/
@Length.List({
@Length(min = 2, message = "The field must be at least 2 characters"),
@Length(max = 30, message = "The field must be less than 30 characters")
})
@Column(nullable = false,
unique = true)
private String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.lambdaschool.schools.models;

public class ValidationError {
private String fieldname;

private String message;

public String getFieldname() {
return fieldname;
}

public ValidationError() {
}

public ValidationError(String fieldname, String message) {
this.fieldname = fieldname;
this.message = message;
}

public void setFieldname(String fieldname) {
this.fieldname = fieldname;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}

Loading