-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from hariprasath-r/refactor-restfully
Refactor restfully
- Loading branch information
Showing
24 changed files
with
507 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,3 +24,4 @@ | |
/nbdist/ | ||
/.nb-gradle/ | ||
/bin/ | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package in.hp.java; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import springfox.documentation.builders.RequestHandlerSelectors; | ||
import springfox.documentation.service.ApiInfo; | ||
import springfox.documentation.service.Contact; | ||
import springfox.documentation.service.VendorExtension; | ||
import springfox.documentation.spi.DocumentationType; | ||
import springfox.documentation.spring.web.plugins.Docket; | ||
import springfox.documentation.swagger2.annotations.EnableSwagger2; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@Configuration | ||
@EnableSwagger2 | ||
public class SwaggerConfig { | ||
|
||
private static final Contact DEFAULT_CONTACT = new Contact( | ||
"Hariprasath", | ||
"https://www.github.com/hariprasath-r", | ||
""); | ||
|
||
private static final ApiInfo DEFAULT_API_INFO = new ApiInfo( | ||
"Course Data API", | ||
"Provides Creation and Maintaining Courses", | ||
"1.0", | ||
"urn:tos", | ||
DEFAULT_CONTACT, | ||
"Apache 2.0", | ||
"http://www.apache.org/licenses/LICENSE-2.0", | ||
new ArrayList<VendorExtension>()); | ||
|
||
private static final Set<String> DEFAULT_PRODUCES_CONSUMES = | ||
new HashSet<>(Arrays.asList("application/json", "application.xml")); | ||
|
||
/** | ||
* Configuring and building Docket Object | ||
* select() - allows to build the Docket with ApiSelectBuilder | ||
* apis() - allows to configure the basePackage from which the models will be read | ||
* paths() - allows to configure URI/resource path | ||
* build() - returns a Docket object | ||
* | ||
* @return | ||
*/ | ||
@Bean | ||
public Docket configureDocket() { | ||
return new Docket(DocumentationType.SWAGGER_2) | ||
.select() | ||
.apis(RequestHandlerSelectors.basePackage("in.hp.java")) | ||
// .paths(PathSelectors.ant("/*")) | ||
.build() // building Docker Object | ||
.apiInfo(DEFAULT_API_INFO) | ||
.produces(DEFAULT_PRODUCES_CONSUMES) | ||
.consumes(DEFAULT_PRODUCES_CONSUMES); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/main/java/in/hp/java/boot/InternationalizationDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package in.hp.java.boot; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.i18n.LocaleContextHolder; | ||
import org.springframework.context.support.ResourceBundleMessageSource; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController() | ||
public class InternationalizationDemo { | ||
|
||
/** | ||
* Autowiring message source to read the messages against passed input | ||
*/ | ||
@Autowired | ||
ResourceBundleMessageSource messageSource; | ||
|
||
@GetMapping("/greeting") | ||
public String greet() { | ||
return "Good Morning"; | ||
} | ||
|
||
/** | ||
* Injecting the locale from request from the header | ||
* Accept-Language - where locale is passed | ||
* required - false, since we already have default locale configured | ||
* | ||
* Instead of accepting from header everywhere, we can use LocaleContextHolder to retrieve the value | ||
* | ||
* @return | ||
*/ | ||
@GetMapping("/i18n") | ||
public String internationalGreeting() { | ||
return messageSource.getMessage("good.morning.message", null, LocaleContextHolder.getLocale()); | ||
} | ||
} |
56 changes: 0 additions & 56 deletions
56
src/main/java/in/hp/java/boot/controller/course/CourseController.java
This file was deleted.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
src/main/java/in/hp/java/boot/controller/topic/TopicController.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
src/main/java/in/hp/java/boot/controller/topic/TopicRepository.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.